瀏覽代碼

Reply to tweets

Carsten Porth 5 年之前
父節點
當前提交
bc372f5be7

+ 3 - 1
app/src/components/tweet-actions/tweet-actions.html

@@ -1,5 +1,7 @@
-<!-- Generated template for the TweetActionsComponent component -->
 <div class="actions-container">
+  <div class="reply" *ngIf="!data.private_tweet" (click)="replyToStatus(data.id_str)">
+    <ion-icon name="undo"></ion-icon>
+  </div>
   <div class="retweets" *ngIf="!data.user.protected" (click)="retweetStatus(id)">
     <ion-icon name="ios-git-compare-outline"></ion-icon>
     <span>{{ data.retweet_count | friendlyNumber }}</span>

+ 4 - 0
app/src/components/tweet-actions/tweet-actions.ts

@@ -62,4 +62,8 @@ export class TweetActionsComponent {
   retweetStatus(id: string): void {
     this.navCtrl.push(WriteTweetPage, { tweetId: id });
   }
+
+  replyToStatus(id: string): void {
+    this.navCtrl.push(WriteTweetPage, { replyToStatus: id });
+  }
 }

+ 4 - 0
app/src/pages/write-tweet/write-tweet.html

@@ -9,6 +9,10 @@
   <ion-label *ngIf="retweet" color="primary">Retweet</ion-label>
   <quoted-status *ngIf="retweet" [data]="retweet.data"></quoted-status>
 
+  <!-- Show tweet to reply to -->
+  <ion-label *ngIf="replyTweet" color="primary">Reply to</ion-label>
+  <quoted-status *ngIf="replyTweet" [data]="replyTweet.data"></quoted-status>
+
   <!-- Form to write a tweet -->
   <form [formGroup]="tweet" (ngSubmit)="submitTweet()">
     <ion-item class="padding-0">

+ 12 - 1
app/src/pages/write-tweet/write-tweet.ts

@@ -19,7 +19,9 @@ import { P2pDatabaseGunProvider } from "../../providers/p2p-database-gun/p2p-dat
 export class WriteTweetPage {
   tweet: FormGroup;
   retweetId: string;
+  replyToStatusId: string;
   retweet;
+  replyTweet;
 
   constructor(
     public navCtrl: NavController,
@@ -32,6 +34,8 @@ export class WriteTweetPage {
     private gun: P2pDatabaseGunProvider
   ) {
     this.retweetId = this.navParams.get("tweetId");
+    this.replyToStatusId = this.navParams.get("replyToStatus");
+
     this.tweet = this.formBuilder.group({
       text: ["", Validators.maxLength(140)],
       p2p: [false]
@@ -42,6 +46,9 @@ export class WriteTweetPage {
     if (this.retweetId) {
       this.retweet = await this.twitter.fetchTweet(this.retweetId);
     }
+    if (this.replyToStatusId) {
+      this.replyTweet = await this.twitter.fetchTweet(this.replyToStatusId);
+    }
   }
 
   get tweetCharProgress() {
@@ -64,7 +71,11 @@ export class WriteTweetPage {
         tweet.created_at
       );
     } else {
-      await this.twitter.tweet(this.tweet.value["text"], this.retweet);
+      await this.twitter.tweet(
+        this.tweet.value["text"],
+        this.retweet,
+        this.replyToStatusId
+      );
     }
 
     loading.dismiss();

+ 5 - 2
app/src/providers/twitter-api/twitter-api.ts

@@ -73,7 +73,7 @@ export class TwitterApiProvider {
     return await this.client.post("blocks/destroy", { user_id: userId });
   }
 
-  public async tweet(status, retweet?) {
+  public async tweet(status, retweet?, replyToStatusId?) {
     if (status.length === 0 && retweet) {
       // Simple retweet
       return await this.client.post("statuses/retweet", {
@@ -81,7 +81,10 @@ export class TwitterApiProvider {
       });
     } else if (!retweet) {
       // Simple tweet
-      return await this.client.post("statuses/update", { status: status });
+      return await this.client.post("statuses/update", {
+        status: status,
+        in_reply_to_status_id: replyToStatusId
+      });
     } else if (status.length > 0 && retweet) {
       // Quoted tweet
       const url =