Browse Source

publish with gun to other peers

Carsten Porth 5 years ago
parent
commit
1747a02af4
1 changed files with 22 additions and 30 deletions
  1. 22 30
      app/src/providers/p2p-database-gun/p2p-database-gun.ts

+ 22 - 30
app/src/providers/p2p-database-gun/p2p-database-gun.ts

@@ -2,31 +2,45 @@ import { Injectable } from "@angular/core";
 import Gun from "gun/gun";
 import "gun/lib/then";
 
-/*
-  Generated class for the P2pDatabaseGunProvider provider.
-
-  See https://angular.io/guide/dependency-injection for more info on providers
-  and Angular DI.
-*/
 @Injectable()
 export class P2pDatabaseGunProvider {
   private gun;
-  osnPrefix: string = "hybridOSN-beta001";
+  osnPrefix: string = "hybridOSN-beta003";
 
   constructor() {
-    this.gun = Gun();
+    this.gun = Gun(["https://hybrid-osn.herokuapp.com/gun"]);
   }
 
   public storeLastTweetHashForUser(userId, hash, timestamp): void {
     const tweet = this.gun
       .get(timestamp)
       .put({ hash: hash, created_at: timestamp });
+
     this.gun
       .get(this.osnPrefix + "-" + userId)
       .get("tweets")
       .set(tweet);
   }
 
+  /**
+   * 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 + "/hashtags").set(hashtags);
+  }
+
   public async getLastTweetFromUser(userId) {
     return new Promise(resolve =>
       this.gun
@@ -62,26 +76,4 @@ 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);
-  }
 }