|
@@ -2,6 +2,7 @@ import { Injectable } from "@angular/core";
|
|
|
import { TwitterApiProvider } from "../twitter-api/twitter-api";
|
|
|
import { P2pDatabaseGunProvider } from "../p2p-database-gun/p2p-database-gun";
|
|
|
import { P2pStorageIpfsProvider } from "../p2p-storage-ipfs/p2p-storage-ipfs";
|
|
|
+import { CryptoProvider } from "../crypto/crypto";
|
|
|
|
|
|
@Injectable()
|
|
|
export class FeedProvider {
|
|
@@ -10,7 +11,8 @@ export class FeedProvider {
|
|
|
constructor(
|
|
|
private twitter: TwitterApiProvider,
|
|
|
private gun: P2pDatabaseGunProvider,
|
|
|
- private ipfs: P2pStorageIpfsProvider
|
|
|
+ private ipfs: P2pStorageIpfsProvider,
|
|
|
+ private cryptoUtils: CryptoProvider
|
|
|
) {}
|
|
|
|
|
|
public async loadUserTimeline(
|
|
@@ -37,7 +39,10 @@ export class FeedProvider {
|
|
|
);
|
|
|
|
|
|
if (privateTweetHashs.length) {
|
|
|
- const privateTweets = await this.fetchPrivateTweets(privateTweetHashs);
|
|
|
+ const privateTweets = await this.fetchPrivateTweets(
|
|
|
+ privateTweetHashs,
|
|
|
+ userId
|
|
|
+ );
|
|
|
|
|
|
// Combine and sort tweets
|
|
|
return tweets
|
|
@@ -88,7 +93,10 @@ export class FeedProvider {
|
|
|
);
|
|
|
|
|
|
if (privateTweetHashs.length) {
|
|
|
- const privateTweets = await this.fetchPrivateTweets(privateTweetHashs);
|
|
|
+ const privateTweets = await this.fetchPrivateTweets(
|
|
|
+ privateTweetHashs,
|
|
|
+ userId
|
|
|
+ );
|
|
|
|
|
|
// Combine and sort tweets
|
|
|
return tweets
|
|
@@ -99,9 +107,19 @@ export class FeedProvider {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async fetchPrivateTweets(privateTweetHashs) {
|
|
|
+ private async fetchPrivateTweets(privateTweetHashs, userId: string) {
|
|
|
// Load private tweets from P2P storage
|
|
|
- const privateTweets = await this.ipfs.fetchTweets(privateTweetHashs);
|
|
|
+ const privateEncryptedTweets = await this.ipfs.fetchTweets(
|
|
|
+ privateTweetHashs
|
|
|
+ );
|
|
|
+
|
|
|
+ // Fetch public key
|
|
|
+ const publicKey = await this.cryptoUtils.fetchPublicKeyForUser(userId);
|
|
|
+
|
|
|
+ // Decrypt tweets
|
|
|
+ const privateTweets = privateEncryptedTweets.map(encryptedTweet =>
|
|
|
+ JSON.parse(this.cryptoUtils.decrypt(encryptedTweet, publicKey))
|
|
|
+ );
|
|
|
|
|
|
// Add user object to private tweets
|
|
|
return await Promise.all(
|