1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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 Gun from "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 = [];
- gun;
- tweets: any[];
- constructor(
- public navCtrl: NavController,
- public navParams: NavParams,
- private twitter: TwitterApiProvider,
- private ipfs: P2pStorageIpfsProvider
- ) {
- this.gun = Gun();
- }
- 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(this.userId);
- }
- 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) {
- let lastTweetHash;
- this.gun
- .get("username")
- .get("lastTweet")
- .once(lastTweet => (lastTweetHash = lastTweet));
- const res = await this.ipfs.fetchTweet(lastTweetHash);
- console.log(res);
- }
- }
|