Explorar el Código

Store hashtags public

Carsten Porth hace 5 años
padre
commit
087029fdb9

+ 3 - 0
app/src/pages/write-tweet/write-tweet.ts

@@ -66,11 +66,14 @@ export class WriteTweetPage {
     if (this.tweet.value.p2p) {
       const tweet = await this.buildPrivateTweet();
       const res = await this.ipfs.storeTweet(tweet);
+
       this.gun.storeLastTweetHashForUser(
         tweet.user_id,
         res["Hash"],
         tweet.created_at
       );
+
+      this.gun.publishHashtags(tweet.entities.hashtags);
     } else {
       await this.twitter.tweet(
         this.tweet.value["text"],

+ 25 - 3
app/src/providers/p2p-database-gun/p2p-database-gun.ts

@@ -11,7 +11,7 @@ import "gun/lib/then";
 @Injectable()
 export class P2pDatabaseGunProvider {
   private gun;
-  osnPrefix: string = "hybridOSN-";
+  osnPrefix: string = "hybridOSN-beta001";
 
   constructor() {
     this.gun = Gun();
@@ -22,7 +22,7 @@ export class P2pDatabaseGunProvider {
       .get(timestamp)
       .put({ hash: hash, created_at: timestamp });
     this.gun
-      .get(this.osnPrefix + userId)
+      .get(this.osnPrefix + "-" + userId)
       .get("tweets")
       .set(tweet);
   }
@@ -42,7 +42,7 @@ export class P2pDatabaseGunProvider {
     intervalEnd
   ): Promise<string[]> {
     const gunIds = await this.gun
-      .get(this.osnPrefix + userId)
+      .get(this.osnPrefix + "-" + userId)
       .get("tweets")
       .then();
 
@@ -64,4 +64,26 @@ export class P2pDatabaseGunProvider {
       return [];
     }
   }
+
+  /**
+   * Hashtags are stored without reference to the users to provide these information on an extra dashboard to twitter
+   * @param hashtagEntity extracted hashtags
+   */
+  public publishHashtags(hashtagEntity): void {
+    const timestamp = Date.now();
+    const hashtagsCommaSeparated = hashtagEntity
+      .map(el => el.hashtag)
+      .sort()
+      .join("|");
+
+    const hashtags = this.gun.get(timestamp).put({
+      hashtags: hashtagsCommaSeparated,
+      created_at: timestamp
+    });
+
+    this.gun
+      .get(this.osnPrefix)
+      .get("hashtags")
+      .set(hashtags);
+  }
 }