Browse Source

retweet functionality for mock

rohit.gowda 4 years ago
parent
commit
cbb330c510

+ 3 - 11
app/src/pages/write-tweet/write-tweet.html

@@ -3,43 +3,35 @@
     <ion-title>Tweet something</ion-title>
   </ion-navbar>
 </ion-header>
-
 <ion-content padding>
   <!-- Show tweet to retweet or quote (if passed to the page) -->
   <ion-label *ngIf="retweet" color="primary">Retweet</ion-label>
-  <quoted-status *ngIf="retweet" [data]="retweet.data"></quoted-status>
-
+  <!-- <quoted-status *ngIf="retweet" [data]="retweet.data"></quoted-status> -->
+  <quoted-status *ngIf="retweet" [data]="retweet"></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">
       <ion-label color="primary" stacked>Your tweet</ion-label>
       <ion-textarea type="text" formControlName="text" maxlength="140" [attr.rows]="4"></ion-textarea>
     </ion-item>
-
     <div class="actions">
       <span class="progress">
         <svg width="20" height="20" class="progress-circle">
           <circle class="background-stroke" cx="10" cy="10" r="8"></circle>
           <circle class="progress-stroke" cx="10" cy="10" r="8" transform="rotate(-90, 10, 10)" [style.strokeDashoffset]="tweetCharProgress"></circle>
         </svg>
-
         <span class="progress-stats">{{ (tweet.value.text).length }}/140</span>
       </span>
-
       <span class="network-switch">
         <ion-icon name="logo-twitter"></ion-icon>
         <ion-toggle checked="false" formControlName="p2p" color="dark"></ion-toggle>
         <ion-icon name="glasses"></ion-icon>
       </span>
-
       <ion-icon name="warning" *ngIf="showTrigger" class="warning" (click)="showTriggerInfo()"></ion-icon>
-
       <button ion-button type="submit" class="submit-tweet">tweet!</button>
     </div>
   </form>
-
-</ion-content>
+</ion-content>

+ 13 - 13
app/src/pages/write-tweet/write-tweet.ts

@@ -48,7 +48,7 @@ export class WriteTweetPage {
   ) {
     this.retweetId = this.navParams.get("tweetId");
     this.replyToStatusId = this.navParams.get("replyToStatus");
-    console.log('retweeting now? ',this.retweetId , this.replyToStatusId );
+    console.log('retweeting now? retweetId:', this.retweetId, 'replyToStatusId: ', this.replyToStatusId);
 
     this.tweet = this.formBuilder.group({
       text: [""],
@@ -87,21 +87,21 @@ export class WriteTweetPage {
   }
 
   async ionViewDidLoad() {
-    console.log('ceck if  the tweet is retweet or a reply',this.retweetId , this.replyToStatusId );
     if (this.retweetId) {
-      if( this.storage.get("mockup"))
-        console.log("retweeting in mockup");
-      else{
+      if (this.storage.get("mockup")) {
+        this.retweet = this.mockProv.fetchTweet(this.retweetId);
+        console.log("retweeted tweet", this.retweet);
+      } else {
         this.retweet = await this.twitter.fetchTweet(this.retweetId);
-        console.log('this.retweet is:',this.retweet );
+        console.log('this.retweet is:', this.retweet);
       }
     }
     if (this.replyToStatusId) {
-      if( this.storage.get("mockup"))
+      if (this.storage.get("mockup"))
         console.log("replying in mockup");
       else
-      this.replyTweet = await this.twitter.fetchTweet(this.replyToStatusId);
-    console.log('this.replyTweet is:',this.replyTweet );
+        this.replyTweet = await this.twitter.fetchTweet(this.replyToStatusId);
+      console.log('this.replyTweet is:', this.replyTweet);
     }
   }
 
@@ -141,10 +141,10 @@ export class WriteTweetPage {
     if (await this.storage.get("mockup")) {
       console.log('value of the tweet is:', this.tweet.value);
       console.log('publishing tweet for mock', this.tweet.value["text"]);
-      await this.mockProv.writeTweet(this.tweet.value["text"], 
-                                      this.tweet.value.p2p,
-                                       this.retweet,
-                                      this.replyToStatusId );
+      await this.mockProv.writeTweet(this.tweet.value["text"],
+        this.tweet.value.p2p,
+        this.retweet,
+        this.replyToStatusId);
       // loading.dismiss();
     } else {
       console.log('in else ');

+ 27 - 19
app/src/providers/mock-provider/mock-provider.ts

@@ -59,19 +59,24 @@ export class MockProvider {
   }
 
   public async replyTweet() {}
-  
 
-  public writeTweet(twt: string , isPrivate: boolean, retwt, replyid) {
-    console.log('inside writetweet',retwt,replyid);
+
+  public writeTweet(twt: string, isPrivate: boolean, retwt, replyid) {
+    console.log('inside writetweet', retwt, replyid);
     // console.log('inside writetweet obj is:',this.mockTweets[0].full_text);
     let newTweet = Object.assign({}, this.mockTweets[0]);
-    newTweet.full_text = twt; 
-    newTweet.id = Math.floor(100000 + Math.random() * 900000); 
-    newTweet.id_str =  newTweet.id ;
     newTweet.full_text = twt;
-      newTweet.retweet = retwt;
-      newTweet.replyToStatusId = replyid;
-    if(isPrivate){
+    newTweet.id = Math.floor(100000 + Math.random() * 900000);
+    newTweet.id_str = newTweet.id;
+    newTweet.full_text = twt;
+    if(retwt){
+      newTweet.is_quote_status = true;
+      newTweet.quoted_status = retwt;
+      newTweet.quoted_status_id = retwt.id;
+      newTweet.quoted_status_id_str = retwt.id_str;
+    }
+    newTweet.replyToStatusId = replyid;
+    if (isPrivate) {
       newTweet.private_tweet = true;
     }
     console.log('new tweet ', newTweet);
@@ -112,31 +117,34 @@ export class MockProvider {
       });
   }
 
-  public likeTweet(id){
-    console.log('fetch tweet id:',id , this.mockTweets);
-    const result = this.mockTweets.find(x=>x.id_str == id);
-     // this.mockTweets.forEach(el=>{
+  public likeTweet(id) {
+    console.log('fetch tweet id:', id, this.mockTweets);
+    const result = this.mockTweets.find(x => x.id_str == id);
+    // this.mockTweets.forEach(el=>{
     //   console.log("mocktweet el is:",el);
     // })
     result.favorited = true;
     result.favorite_count++;
-    console.log('tweet found and modified:',result);
+    console.log('tweet found and modified:', result);
     return result;
   }
 
-  public unlikeTweet(id){
-    console.log('fetch tweet id:',id , this.mockTweets);
-    const result = this.mockTweets.find(x=>x.id_str == id);
-     // this.mockTweets.forEach(el=>{
+  public unlikeTweet(id) {
+    console.log('fetch tweet id:', id, this.mockTweets);
+    const result = this.mockTweets.find(x => x.id_str == id);
+    // this.mockTweets.forEach(el=>{
     //   console.log("mocktweet el is:",el);
     // })
     result.favorited = false;
     result.favorite_count--;
-    console.log('tweet found and modified:',result);
+    console.log('tweet found and modified:', result);
     return result;
   }
 
 
+  public fetchTweet(tweetID) {
+    return this.mockTweets.find(x => x.id_str == tweetID);
+  }
 
   private async fetchPrivateTweets(privateTweetsData: object[]) {