Browse Source

refactoring

Carsten Porth 5 years ago
parent
commit
ce820f0af2

+ 3 - 4
app/src/providers/crypto/crypto.ts

@@ -199,10 +199,9 @@ export class CryptoProvider {
           utf8BytesOfPlainText
         );
       })
-      .then((encData: ArrayBuffer) => {
-        // prepend the iv to the bytes, so that decryption-process can use it, see markdown file for "AES (symm.) encryption" and "AES Initialization vector (iv)"
-        return this.mergeBytes(iv, this.bufferToBytes(encData));
-      })
+      .then((encData: ArrayBuffer) =>
+        this.mergeBytes(iv, this.bufferToBytes(encData))
+      )
       .then(this.bytesToBase64);
   }
 

+ 8 - 11
app/src/providers/feed/feed.ts

@@ -43,7 +43,7 @@ export class FeedProvider {
       intervalEnd
     );
 
-    if (privateTweetHashs.length) {
+    if (privateTweetHashs.length > 0) {
       const privateTweets = await this.fetchPrivateTweets(privateTweetHashs);
 
       // Combine and sort tweets
@@ -76,24 +76,21 @@ export class FeedProvider {
       .concat([this.userId]);
 
     // Fetch ipfs hashs for period
-    const promises = [];
-    friendsAndUserIds.forEach(async accountId => {
-      promises.push(
-        this.gun.fetchPrivateTweetHashsForUserInInterval(
-          accountId,
-          intervalStart,
-          intervalEnd
-        )
+    const promises: Promise<object[]>[] = friendsAndUserIds.map(accountId => {
+      return this.gun.fetchPrivateTweetHashsForUserInInterval(
+        accountId,
+        intervalStart,
+        intervalEnd
       );
     });
 
     const resolvedPromises = await Promise.all(promises);
     const privateTweetHashs = resolvedPromises.reduce(
-      (el, privateTweets) => privateTweets.concat(el),
+      (privateTweets, el) => privateTweets.concat(el),
       []
     );
 
-    if (privateTweetHashs.length) {
+    if (privateTweetHashs.length > 0) {
       const privateTweets = await this.fetchPrivateTweets(privateTweetHashs);
 
       // Combine and sort tweets

+ 7 - 9
app/src/providers/p2p-database-gun/p2p-database-gun.ts

@@ -5,7 +5,7 @@ import "gun/lib/then";
 @Injectable()
 export class P2pDatabaseGunProvider {
   private gun;
-  osnPrefix: string = "hybridOSN-beta010";
+  osnPrefix: string = "hybridOSN-beta011";
 
   constructor() {
     this.gun = Gun(["https://hybrid-osn.herokuapp.com/gun"]);
@@ -24,10 +24,9 @@ export class P2pDatabaseGunProvider {
 
     const randomId = Math.floor(Math.random() * 10000000000);
 
-    const hashtags = await this.gun
+    const hashtags = this.gun
       .get(randomId)
-      .put({ hashtags: hashtagsSeparated })
-      .then();
+      .put({ hashtags: hashtagsSeparated });
 
     this.gun
       .get(this.osnPrefix)
@@ -67,11 +66,10 @@ export class P2pDatabaseGunProvider {
       );
 
       return entries
-        .filter(
-          entry =>
-            new Date(entry["created_at"]) < intervalStart &&
-            new Date(entry["created_at"]) >= intervalEnd
-        )
+        .filter(entry => {
+          const createdAtDate = new Date(entry["created_at"]);
+          return createdAtDate < intervalStart && createdAtDate >= intervalEnd;
+        })
         .map(entry => {
           entry.userId = userId;
           return entry;