|
@@ -18,14 +18,9 @@ export class TweetBodyComponent {
|
|
|
|
|
|
get status(): string {
|
|
|
if (this.data["retweeted_status"]) {
|
|
|
- const range = this.data["retweeted_status"]["display_text_range"];
|
|
|
- return this.data["retweeted_status"]["full_text"].substr(
|
|
|
- range[0],
|
|
|
- range[1]
|
|
|
- );
|
|
|
+ return this.data["retweeted_status"]["full_text"];
|
|
|
} else {
|
|
|
- const range = this.data["display_text_range"];
|
|
|
- return this.data["full_text"].substr(range[0], range[1]);
|
|
|
+ return this.data["full_text"];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -44,6 +39,13 @@ export class TweetBodyComponent {
|
|
|
return this.data["extended_entities"];
|
|
|
}
|
|
|
}
|
|
|
+ get range() {
|
|
|
+ if (this.data["retweeted_status"]) {
|
|
|
+ return this.data["retweeted_status"]["display_text_range"];
|
|
|
+ } else {
|
|
|
+ return this.data["display_text_range"];
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
get hasPhoto() {
|
|
|
return (
|
|
@@ -61,4 +63,149 @@ export class TweetBodyComponent {
|
|
|
this.extended_entities["media"][0]["type"] === "animated_gif"
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ get tweetArray() {
|
|
|
+ let tweetArray = [];
|
|
|
+ tweetArray = tweetArray.concat(this.getUserMentionsForTweetArray());
|
|
|
+ tweetArray = tweetArray.concat(this.getHashtagsForTweetArray());
|
|
|
+ tweetArray = tweetArray.concat(this.getUrlsForTweetArray());
|
|
|
+ tweetArray = tweetArray.concat(
|
|
|
+ this.getTextPartsForTweetArray(
|
|
|
+ tweetArray.sort((a, b) => a["start"] - b["start"])
|
|
|
+ )
|
|
|
+ );
|
|
|
+ tweetArray = this.cutToTextRange(tweetArray);
|
|
|
+ return tweetArray.sort((a, b) => a["start"] - b["start"]);
|
|
|
+ }
|
|
|
+
|
|
|
+ private getUserMentionsForTweetArray() {
|
|
|
+ return this.entities["user_mentions"].map(mention => ({
|
|
|
+ start: mention["indices"][0],
|
|
|
+ stop: mention["indices"][1],
|
|
|
+ type: "user_mention",
|
|
|
+ text: "@" + mention["screen_name"],
|
|
|
+ userId: mention["id_str"]
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ private getHashtagsForTweetArray() {
|
|
|
+ return this.entities["hashtags"].map(hashtag => ({
|
|
|
+ start: hashtag["indices"][0],
|
|
|
+ stop: hashtag["indices"][1],
|
|
|
+ type: "hashtag",
|
|
|
+ text: "#" + hashtag["text"]
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ private getUrlsForTweetArray() {
|
|
|
+ return this.entities["urls"].map(url => ({
|
|
|
+ start: url["indices"][0],
|
|
|
+ stop: url["indices"][1],
|
|
|
+ type: "url",
|
|
|
+ text: url["display_url"],
|
|
|
+ url: url["url"]
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ private getTextPartsForTweetArray(specialParts) {
|
|
|
+ if (!specialParts.length) {
|
|
|
+ // text only
|
|
|
+ return [
|
|
|
+ {
|
|
|
+ start: 0,
|
|
|
+ stop: this.status.length,
|
|
|
+ type: "text",
|
|
|
+ text: this.status
|
|
|
+ }
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ let res = [];
|
|
|
+ let start = 0;
|
|
|
+ for (let i = 0; i < specialParts.length; i++) {
|
|
|
+ if (start != specialParts[i].start) {
|
|
|
+ res.push({
|
|
|
+ start: start,
|
|
|
+ stop: specialParts[i]["start"],
|
|
|
+ type: "text",
|
|
|
+ text: this.status.substring(start, specialParts[i]["start"])
|
|
|
+ });
|
|
|
+ }
|
|
|
+ start = specialParts[i]["stop"];
|
|
|
+ }
|
|
|
+ const stopOfLastSpecialPart =
|
|
|
+ specialParts[specialParts.length - 1]["stop"];
|
|
|
+ const textUntilEnd = this.status.substring(
|
|
|
+ stopOfLastSpecialPart,
|
|
|
+ this.status.length
|
|
|
+ );
|
|
|
+ if (textUntilEnd.length) {
|
|
|
+ res.push({
|
|
|
+ start: stopOfLastSpecialPart,
|
|
|
+ stop: this.status.length,
|
|
|
+ type: "text",
|
|
|
+ text: textUntilEnd
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private cutToTextRange(tweetArray) {
|
|
|
+ const res = [];
|
|
|
+ for (let i = 0; i < tweetArray.length; i++) {
|
|
|
+ if (
|
|
|
+ tweetArray[i]["start"] >= this.range[0] &&
|
|
|
+ tweetArray[i]["stop"] <= this.range[1]
|
|
|
+ ) {
|
|
|
+ // Inside the range
|
|
|
+ res.push(tweetArray[i]);
|
|
|
+ } else if (
|
|
|
+ tweetArray[i]["start"] < this.range[0] &&
|
|
|
+ tweetArray[i]["stop"] <= this.range[1]
|
|
|
+ ) {
|
|
|
+ // Beginning needs to be cut
|
|
|
+ res.push({
|
|
|
+ start: this.range[0],
|
|
|
+ stop: tweetArray[i]["stop"],
|
|
|
+ type: tweetArray[i]["type"],
|
|
|
+ text: tweetArray[i]["text"].substring(
|
|
|
+ this.range[0],
|
|
|
+ tweetArray[i]["stop"]
|
|
|
+ )
|
|
|
+ });
|
|
|
+ } else if (
|
|
|
+ tweetArray[i]["start"] >= this.range[0] &&
|
|
|
+ tweetArray[i]["stop"] > this.range[1]
|
|
|
+ ) {
|
|
|
+ // End needs to be cut
|
|
|
+ if (this.range[1] - tweetArray[i]["start"] > 0) {
|
|
|
+ res.push({
|
|
|
+ start: tweetArray[i]["start"],
|
|
|
+ stop: this.range[1],
|
|
|
+ type: tweetArray[i]["type"],
|
|
|
+ text: tweetArray[i]["text"].substring(
|
|
|
+ 0,
|
|
|
+ this.range[1] - tweetArray[i]["start"]
|
|
|
+ )
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else if (
|
|
|
+ tweetArray[i]["start"] < this.range[0] &&
|
|
|
+ tweetArray[i]["stop"] > this.range[1]
|
|
|
+ ) {
|
|
|
+ // Start and end needs to be cut
|
|
|
+ res.push({
|
|
|
+ start: this.range[0],
|
|
|
+ stop: this.range[1],
|
|
|
+ type: tweetArray[i]["type"],
|
|
|
+ text: tweetArray[i]["text"].substring(
|
|
|
+ this.range[1] - tweetArray[i]["stop"],
|
|
|
+ tweetArray[i]["stop"] - this.range[1]
|
|
|
+ )
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|