tweet-header.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { Component, Input } from "@angular/core";
  2. import { ActionSheetController, App } from "ionic-angular";
  3. import { ProfilePage } from "../../pages/profile/profile";
  4. import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
  5. @Component({
  6. selector: "tweet-header",
  7. templateUrl: "tweet-header.html"
  8. })
  9. export class TweetHeaderComponent {
  10. @Input()
  11. user: any[];
  12. @Input()
  13. tweetCreatedAt: string;
  14. constructor(
  15. private appCtrl: App,
  16. public actionSheetCtrl: ActionSheetController,
  17. private twitter: TwitterApiProvider
  18. ) {}
  19. showProfile(userId) {
  20. this.appCtrl.getRootNav().push(ProfilePage, { userId });
  21. }
  22. showActions(userId) {
  23. this.twitter.fetchUser(userId).then(user => {
  24. this.actionSheetCtrl
  25. .create({
  26. title: "@" + this.user["screen_name"],
  27. buttons: this.getButtonsForActionSheet(user)
  28. })
  29. .present();
  30. });
  31. }
  32. private getButtonsForActionSheet(user) {
  33. const buttons = [];
  34. if (user.following) {
  35. // Unfollow
  36. buttons.push({
  37. text: "Unfollow",
  38. role: "destructive",
  39. handler: () => {
  40. this.twitter.destroyFriendship(user.id_str);
  41. }
  42. });
  43. } else {
  44. // Follow
  45. buttons.push({
  46. text: "Follow",
  47. role: "destructive",
  48. handler: () => {
  49. this.twitter.createFriendship(user.id_str);
  50. }
  51. });
  52. }
  53. if (user.muting) {
  54. // unmute
  55. buttons.push({
  56. text: "Unmute",
  57. role: "destructive",
  58. handler: () => {
  59. this.twitter.unmuteUser(user.id_str);
  60. }
  61. });
  62. } else {
  63. // mute
  64. buttons.push({
  65. text: "Mute",
  66. role: "destructive",
  67. handler: () => {
  68. this.twitter.muteUser(user.id_str);
  69. }
  70. });
  71. }
  72. if (user.blocking) {
  73. // Unblock
  74. buttons.push({
  75. text: "Unblock",
  76. role: "destructive",
  77. handler: () => {
  78. this.twitter.unblockUser(user.id_str);
  79. }
  80. });
  81. } else {
  82. // Block
  83. buttons.push({
  84. text: "Block",
  85. role: "destructive",
  86. handler: () => {
  87. this.twitter.blockUser(user.id_str);
  88. }
  89. });
  90. }
  91. // Cancel button
  92. buttons.push({
  93. text: "Cancel",
  94. role: "cancel"
  95. });
  96. return buttons;
  97. }
  98. }