profile.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { Component } from "@angular/core";
  2. import {
  3. IonicPage,
  4. NavController,
  5. NavParams,
  6. InfiniteScroll
  7. } from "ionic-angular";
  8. import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
  9. import { P2pStorageIpfsProvider } from "../../providers/p2p-storage-ipfs/p2p-storage-ipfs";
  10. import { P2pDatabaseGunProvider } from "../../providers/p2p-database-gun/p2p-database-gun";
  11. /**
  12. * Generated class for the ProfilePage page.
  13. *
  14. * See https://ionicframework.com/docs/components/#navigation for more info on
  15. * Ionic pages and navigation.
  16. */
  17. @IonicPage()
  18. @Component({
  19. selector: "page-profile",
  20. templateUrl: "profile.html"
  21. })
  22. export class ProfilePage {
  23. userId: string;
  24. user: any = [];
  25. tweets: any[];
  26. constructor(
  27. public navCtrl: NavController,
  28. public navParams: NavParams,
  29. private twitter: TwitterApiProvider,
  30. private ipfs: P2pStorageIpfsProvider,
  31. private gun: P2pDatabaseGunProvider
  32. ) {}
  33. ionViewDidLoad() {
  34. this.userId = this.navParams.get("userId");
  35. this.twitter.fetchUser(this.userId).then(res => (this.user = res));
  36. this.twitter
  37. .fetchUserTimeline(this.userId)
  38. .then(res => (this.tweets = res));
  39. this.checkP2pTweets("username");
  40. }
  41. doRefresh(refresher) {
  42. this.twitter.fetchUserTimeline(this.userId).then(res => {
  43. this.tweets = res;
  44. refresher.complete();
  45. });
  46. }
  47. loadMore(infiniteScroll: InfiniteScroll) {
  48. this.twitter
  49. .fetchUserTimelineSince(
  50. this.userId,
  51. this.tweets[this.tweets.length - 1].id
  52. )
  53. .then(res => {
  54. this.tweets = this.tweets.concat(res);
  55. infiniteScroll.complete();
  56. });
  57. }
  58. private async checkP2pTweets(userId) {
  59. const lastTweetHash = await this.gun.getLastTweetFromUser(userId);
  60. const res = await this.ipfs.fetchTweet(lastTweetHash);
  61. }
  62. }