import { Component } from "@angular/core"; import { IonicPage, NavController, NavParams, InfiniteScroll } from "ionic-angular"; import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api"; import { P2pStorageIpfsProvider } from "../../providers/p2p-storage-ipfs/p2p-storage-ipfs"; import { P2pDatabaseGunProvider } from "../../providers/p2p-database-gun/p2p-database-gun"; /** * Generated class for the ProfilePage page. * * See https://ionicframework.com/docs/components/#navigation for more info on * Ionic pages and navigation. */ @IonicPage() @Component({ selector: "page-profile", templateUrl: "profile.html" }) export class ProfilePage { userId: string; user: any = []; tweets: any[]; constructor( public navCtrl: NavController, public navParams: NavParams, private twitter: TwitterApiProvider, private ipfs: P2pStorageIpfsProvider, private gun: P2pDatabaseGunProvider ) {} ionViewDidLoad() { this.userId = this.navParams.get("userId"); this.twitter.fetchUser(this.userId).then(res => (this.user = res)); this.twitter .fetchUserTimeline(this.userId) .then(res => (this.tweets = res)); this.checkP2pTweets("username"); } doRefresh(refresher) { this.twitter.fetchUserTimeline(this.userId).then(res => { this.tweets = res; refresher.complete(); }); } loadMore(infiniteScroll: InfiniteScroll) { this.twitter .fetchUserTimelineSince( this.userId, this.tweets[this.tweets.length - 1].id ) .then(res => { this.tweets = this.tweets.concat(res); infiniteScroll.complete(); }); } private async checkP2pTweets(userId) { const lastTweetHash = await this.gun.getLastTweetFromUser(userId); const res = await this.ipfs.fetchTweet(lastTweetHash); } }