12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- import { Component } from "@angular/core";
- import {
- IonicPage,
- NavController,
- NavParams,
- InfiniteScroll
- } from "ionic-angular";
- import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
- import { HttpClient } from "@angular/common/http";
- 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 http: HttpClient
- ) {
- 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.http
- .get("https://ipfs.infura.io:5001/api/v0/cat", {
- params: { arg: lastTweetHash }
- })
- .toPromise();
- // const tweet = JSON.parse(res);
- console.log(res);
- }
- }
|