Browse Source

Bug fix: async private tweet loading

Carsten Porth 5 years ago
parent
commit
4d0866ff47
1 changed files with 15 additions and 12 deletions
  1. 15 12
      app/src/providers/feed/feed.ts

+ 15 - 12
app/src/providers/feed/feed.ts

@@ -72,24 +72,27 @@ export class FeedProvider {
     // Fetch user's friends
     const friends = await this.getCachedFriends(this.userId);
 
-    let privateTweetHashs = [];
-    friends.forEach(async friend => {
-      privateTweetHashs = privateTweetHashs.concat(
-        await this.gun.fetchPrivateTweetHashsForUserInInterval(
-          friend.id_str,
+    // Extract friends user ids and add own user id
+    const friendsAndUserIds = friends
+      .map(friend => friend.id_str)
+      .concat([this.userId]);
+
+    // Fetch ipfs hashs for period
+    const promises = [];
+    friendsAndUserIds.forEach(async accountId => {
+      promises.push(
+        this.gun.fetchPrivateTweetHashsForUserInInterval(
+          accountId,
           intervalStart,
           intervalEnd
         )
       );
     });
 
-    // Add users private tweets
-    privateTweetHashs = privateTweetHashs.concat(
-      await this.gun.fetchPrivateTweetHashsForUserInInterval(
-        this.userId,
-        intervalStart,
-        intervalEnd
-      )
+    const resolvedPromises = await Promise.all(promises);
+    const privateTweetHashs = resolvedPromises.reduce(
+      (el, privateTweets) => privateTweets.concat(el),
+      []
     );
 
     if (privateTweetHashs.length) {