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