|
@@ -3,17 +3,21 @@ 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";
|
|
|
-
|
|
|
+import { Storage } from "@ionic/storage";
|
|
|
@Injectable()
|
|
|
export class FeedProvider {
|
|
|
friends;
|
|
|
+ userId: string;
|
|
|
|
|
|
constructor(
|
|
|
private twitter: TwitterApiProvider,
|
|
|
private gun: P2pDatabaseGunProvider,
|
|
|
private ipfs: P2pStorageIpfsProvider,
|
|
|
- private cryptoUtils: CryptoProvider
|
|
|
- ) {}
|
|
|
+ private cryptoUtils: CryptoProvider,
|
|
|
+ private storage: Storage
|
|
|
+ ) {
|
|
|
+ this.storage.get("userId").then(userId => (this.userId = userId));
|
|
|
+ }
|
|
|
|
|
|
public async loadUserTimeline(
|
|
|
userId,
|
|
@@ -53,11 +57,7 @@ export class FeedProvider {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public async loadHomeTimeline(
|
|
|
- userId,
|
|
|
- oldestPublicTweet?,
|
|
|
- oldestPrivateTweet?
|
|
|
- ) {
|
|
|
+ public async loadHomeTimeline(oldestPublicTweet?, oldestPrivateTweet?) {
|
|
|
// Fetch tweets from Twitter
|
|
|
const maxId = oldestPublicTweet ? oldestPublicTweet["id_str"] : undefined;
|
|
|
let tweets = await this.twitter.fetchHomeFeed(maxId);
|
|
@@ -70,7 +70,7 @@ export class FeedProvider {
|
|
|
const intervalEnd: Date = this.getOldestTweetTimestamp(tweets);
|
|
|
|
|
|
// Fetch user's friends
|
|
|
- const friends = await this.getCachedFriends(userId);
|
|
|
+ const friends = await this.getCachedFriends(this.userId);
|
|
|
|
|
|
let privateTweetHashs = [];
|
|
|
friends.forEach(async friend => {
|
|
@@ -86,7 +86,7 @@ export class FeedProvider {
|
|
|
// Add users private tweets
|
|
|
privateTweetHashs = privateTweetHashs.concat(
|
|
|
await this.gun.fetchPrivateTweetHashsForUserInInterval(
|
|
|
- userId,
|
|
|
+ this.userId,
|
|
|
intervalStart,
|
|
|
intervalEnd
|
|
|
)
|
|
@@ -95,7 +95,7 @@ export class FeedProvider {
|
|
|
if (privateTweetHashs.length) {
|
|
|
const privateTweets = await this.fetchPrivateTweets(
|
|
|
privateTweetHashs,
|
|
|
- userId
|
|
|
+ this.userId
|
|
|
);
|
|
|
|
|
|
// Combine and sort tweets
|