Browse Source

Retweet and reply to public tweets in private mode

Carsten Porth 5 năm trước cách đây
mục cha
commit
f80f71ef03

+ 9 - 0
app/src/components/quoted-status/quoted-status.scss

@@ -32,3 +32,12 @@ quoted-status {
     }
   }
 }
+
+.private quoted-status {
+  .header {
+    color: #efefef;
+  }
+  .body p {
+    color: #efefef;
+  }
+}

+ 3 - 2
app/src/components/tweet-body/tweet-body.html

@@ -1,14 +1,15 @@
-<!-- Generated template for the TweetBodyComponent component -->
 <div>
   <div class="tweet-array">
     <span class="tweet-array-part" *ngFor="let part of tweetArray">
       <span *ngIf="part.type =='text'" class="text" [innerHtml]="part.text"></span>
-      <a *ngIf="part.type == 'url'" href="{{ part.url }}">{{ part.text }}</a>
+      <a *ngIf="part.type == 'url'" href="{{ part.url }}">{{part.text}}</a>
       <mention *ngIf="part.type == 'user_mention'" [username]="part.text" [userId]="part.userId"></mention>
       <hashtag *ngIf="part.type == 'hashtag'" [hashtag]="part.text"></hashtag>
     </span>
   </div>
+
   <img *ngIf="hasPhoto" src="{{ entities.media[0]['media_url_https'] }}" alt="Photo" class="photo">
   <video *ngIf="isGif" src="{{ extended_entities.media[0]['video_info']['variants'][0]['url'] }}" autoplay loop></video>
   <quoted-status *ngIf="data.quoted_status" [data]="data.quoted_status"></quoted-status>
+  <div *ngIf="!data.quoted_status && data.quoted_status_id" class="removed-tweet">Tweet has been removed...</div>
 </div>

+ 8 - 0
app/src/components/tweet-body/tweet-body.scss

@@ -11,4 +11,12 @@ tweet-body {
   video {
     width: 100%;
   }
+  .removed-tweet {
+    border: 1px solid #cc1f1a;
+    padding: 5px;
+    margin: 5px 0;
+    color: #cc1f1a;
+    border-radius: 3px;
+    font-style: italic;
+  }
 }

+ 3 - 0
app/src/components/tweet/tweet.scss

@@ -16,5 +16,8 @@ tweet {
   .private {
     background: #333;
     color: #efefef;
+    .retweet-info {
+      color: #bebebe;
+    }
   }
 }

+ 2 - 0
app/src/pages/write-tweet/write-tweet.ts

@@ -125,6 +125,8 @@ export class WriteTweetPage {
       user_id: await this.storage.get("userId"),
       created_at: Date.now(),
       private_tweet: true,
+      in_reply_to_status_id: this.replyToStatusId,
+      quoted_status_id: this.retweetId,
       display_text_range: [0, status.length],
       entities: entities
     };

+ 29 - 2
app/src/providers/feed/feed.ts

@@ -135,6 +135,14 @@ export class FeedProvider {
       privateTweets.push(JSON.parse(decryptedTweet));
     }
 
+    // Add retweeted/quoted status
+    privateTweets.map(async tweet => await this.addQuotedStatusToTweet(tweet));
+
+    // Add original status (reply to)
+    privateTweets.map(
+      async tweet => await this.addOriginalStatusToTweet(tweet)
+    );
+
     // Add user object to private tweets
     return await Promise.all(
       privateTweets.map(async tweet => await this.addUserToTweet(tweet))
@@ -156,8 +164,27 @@ export class FeedProvider {
     return "";
   }
 
-  private async addUserToTweet(tweet) {
-    tweet.user = await this.twitter.fetchUser(tweet.user_id);
+  private async addUserToTweet(tweet: object): Promise<object> {
+    tweet["user"] = await this.twitter.fetchUser(tweet["user_id"]);
+    return tweet;
+  }
+
+  private async addQuotedStatusToTweet(tweet: object): Promise<object> {
+    if (!tweet["quoted_status_id"]) return tweet;
+    const quoted_status = await this.twitter.fetchTweet(
+      tweet["quoted_status_id"]
+    );
+    tweet["quoted_status"] = quoted_status["data"];
+    return tweet;
+  }
+
+  private async addOriginalStatusToTweet(tweet: object): Promise<object> {
+    if (!tweet["in_reply_to_status_id"]) return tweet;
+    const originalTweet = await this.twitter.fetchTweet(
+      tweet["in_reply_to_status_id"]
+    );
+    tweet["in_reply_to_screen_name"] =
+      originalTweet["data"]["user"]["screen_name"];
     return tweet;
   }