3 Commits 093841dc89 ... 1ba25f5fd2

Author SHA1 Message Date
  rohit.gowda 1ba25f5fd2 Load user private tweets when loading home timeline 4 years ago
  rohit.gowda 77e102c02b Add alert message for invalid actions 4 years ago
  rohit.gowda f3d699ca50 Fix filtering of private tweets 4 years ago
3 changed files with 28 additions and 14 deletions
  1. 3 3
      app/src/pages/home/home.ts
  2. 4 1
      app/src/pages/settings/settings.ts
  3. 21 10
      app/src/providers/feed/feed.ts

+ 3 - 3
app/src/pages/home/home.ts

@@ -113,16 +113,16 @@ export class HomePage {
     this.privateTweet = !this.privateTweet;
     const loading = this.loadingCtrl.create();
     loading.present();
-    this.tweets = this.privateTweets;
-
+   
     if(this.privateTweet){
       this.color = 'black';
+      this.tweets = this.privateTweets;
       loading.dismiss();
     }
 
     else{
       this.color = 'white';
-      this.tweets =this.cachedTweets;
+      this.tweets = this.cachedTweets;
       loading.dismiss();
     }
     

+ 4 - 1
app/src/pages/settings/settings.ts

@@ -97,11 +97,14 @@ export class SettingsPage {
       this.publishPrivateKey();
     }
     else{
-      this.createAlert("No Keys","No keys to save!");
+      this.createAlert("No Keys","Please generate the keypair before saving!");
     }
   }
 
   async publishPublicKey() {
+     if (!this.publicKey || !this.privateKey) {
+       this.createAlert("No Keypair to Publish","Please generate the keypair before trying to publish!");
+     }
     await this.openpgp.publishPubKey(this.publicKey);
     this.showToast("Publc key published");
 

+ 21 - 10
app/src/providers/feed/feed.ts

@@ -45,17 +45,9 @@ export class FeedProvider {
       new Date();
     const intervalEnd: Date = this.getOldestTweetTimestamp(tweets);
 
-    // Fetch private tweet hashs from P2P DB for corresponding interval
-    const privateTweetHashs: object[] = await this.gun.fetchPrivateTweetHashsForUserInInterval(
-      userId,
-      intervalStart,
-      intervalEnd
-    );
-
-    if (privateTweetHashs.length > 0) {
-      const privateTweets = await this.fetchPrivateTweets(privateTweetHashs);
-
+    const privateTweets = await this.fetchUserPrivateTweets(userId,intervalStart,intervalEnd);
       // Combine and sort tweets
+    if(privateTweets){
       return tweets
         .concat(privateTweets)
         .sort((a, b) => this.sortByDateAsc(a, b));
@@ -90,6 +82,7 @@ export class FeedProvider {
     const friendsAndUserIds = friends
       .map(friend => friend.id_str)
       .concat([this.userId]);
+      console.log("friendsAndUserIds are:"+friendsAndUserIds);
 
     // Fetch ipfs hashs for period
     const promises: Promise < object[] > [] = friendsAndUserIds.map(accountId => {
@@ -112,6 +105,10 @@ export class FeedProvider {
     if (privateTweetHashs.length > 0) {
       const privateTweets = await this.fetchPrivateTweets(privateTweetHashs);
       // Combine and sort tweets
+      const userPrivateTweets = await this.fetchUserPrivateTweets(this.userId,intervalStart,intervalEnd);
+      if(!userPrivateTweets){
+        privateTweets.concat(userPrivateTweets);
+      }
 
       return tweets
         .concat(privateTweets)
@@ -122,6 +119,20 @@ export class FeedProvider {
     }
   }
 
+  private async fetchUserPrivateTweets(userId,intervalStart,intervalEnd){
+    // Fetch private tweet hashs from P2P DB for corresponding interval
+    const privateTweetHashs: object[] = await this.gun.fetchPrivateTweetHashsForUserInInterval(
+      userId,
+      intervalStart,
+      intervalEnd
+    );
+
+    if (privateTweetHashs.length > 0) {
+     return this.fetchPrivateTweets(privateTweetHashs);
+   }
+   return null;
+  }
+
   private async fetchFollowersPublicKeys(followers) {
     //Fetch email address of all friends from gunDB
     const emailPromises: Promise < string > [] = followers.map(accountId => {