tweet-actions.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { Component, Input, ChangeDetectorRef } from "@angular/core";
  2. import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
  3. import { NavController } from "ionic-angular";
  4. import { WriteTweetPage } from "../../pages/write-tweet/write-tweet";
  5. /**
  6. * Generated class for the TweetActionsComponent component.
  7. *
  8. * See https://angular.io/api/core/Component for more info on Angular
  9. * Components.
  10. */
  11. @Component({
  12. selector: "tweet-actions",
  13. templateUrl: "tweet-actions.html"
  14. })
  15. export class TweetActionsComponent {
  16. @Input()
  17. data: any[];
  18. constructor(
  19. private twitter: TwitterApiProvider,
  20. private ref: ChangeDetectorRef,
  21. private navCtrl: NavController
  22. ) {}
  23. get favoriteCount() {
  24. if (this.data["retweeted_status"]) {
  25. return this.data["retweeted_status"]["favorite_count"];
  26. } else {
  27. return this.data["favorite_count"];
  28. }
  29. }
  30. get id() {
  31. if (this.data["retweeted_status"]) {
  32. return this.data["retweeted_status"]["id_str"];
  33. } else {
  34. return this.data["id_str"];
  35. }
  36. }
  37. like(id: string): void {
  38. if (!this.data["private_tweet"]) {
  39. this.twitter.likeTweet(id).then(() => {
  40. this.data["favorited"] = true;
  41. this.data["favorite_count"]++;
  42. this.ref.detectChanges();
  43. });
  44. }
  45. }
  46. removeLike(id: string): void {
  47. if (!this.data["private_tweet"]) {
  48. this.twitter.unlikeTweet(id).then(() => {
  49. this.data["favorited"] = false;
  50. this.data["favorite_count"]--;
  51. this.ref.detectChanges();
  52. });
  53. }
  54. }
  55. retweetStatus(id: string): void {
  56. this.navCtrl.push(WriteTweetPage, { tweetId: id });
  57. }
  58. replyToStatus(id: string): void {
  59. this.navCtrl.push(WriteTweetPage, { replyToStatus: id });
  60. }
  61. }