|
@@ -2,13 +2,9 @@ import { Component, Input, ChangeDetectorRef } from "@angular/core";
|
|
import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
|
|
import { TwitterApiProvider } from "../../providers/twitter-api/twitter-api";
|
|
import { NavController } from "ionic-angular";
|
|
import { NavController } from "ionic-angular";
|
|
import { WriteTweetPage } from "../../pages/write-tweet/write-tweet";
|
|
import { WriteTweetPage } from "../../pages/write-tweet/write-tweet";
|
|
|
|
+import { P2pDatabaseGunProvider } from "../../providers/p2p-database-gun/p2p-database-gun";
|
|
|
|
+import { Vibration } from "@ionic-native/vibration";
|
|
|
|
|
|
-
|
|
|
|
- * Generated class for the TweetActionsComponent component.
|
|
|
|
- *
|
|
|
|
- * See https:
|
|
|
|
- * Components.
|
|
|
|
- */
|
|
|
|
@Component({
|
|
@Component({
|
|
selector: "tweet-actions",
|
|
selector: "tweet-actions",
|
|
templateUrl: "tweet-actions.html"
|
|
templateUrl: "tweet-actions.html"
|
|
@@ -16,13 +12,20 @@ import { WriteTweetPage } from "../../pages/write-tweet/write-tweet";
|
|
export class TweetActionsComponent {
|
|
export class TweetActionsComponent {
|
|
@Input()
|
|
@Input()
|
|
data: any[];
|
|
data: any[];
|
|
|
|
+ privateFavoriteCount: number = 0;
|
|
|
|
|
|
constructor(
|
|
constructor(
|
|
private twitter: TwitterApiProvider,
|
|
private twitter: TwitterApiProvider,
|
|
private ref: ChangeDetectorRef,
|
|
private ref: ChangeDetectorRef,
|
|
- private navCtrl: NavController
|
|
+ private navCtrl: NavController,
|
|
|
|
+ private gun: P2pDatabaseGunProvider,
|
|
|
|
+ private vibration: Vibration
|
|
) {}
|
|
) {}
|
|
|
|
|
|
|
|
+ ngOnInit() {
|
|
|
|
+ this.getPrivateLikes(this.id);
|
|
|
|
+ }
|
|
|
|
+
|
|
get favoriteCount() {
|
|
get favoriteCount() {
|
|
if (this.data["retweeted_status"]) {
|
|
if (this.data["retweeted_status"]) {
|
|
return this.data["retweeted_status"]["favorite_count"];
|
|
return this.data["retweeted_status"]["favorite_count"];
|
|
@@ -39,26 +42,46 @@ export class TweetActionsComponent {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- like(id: string): void {
|
|
+ private async getPrivateLikes(id: string) {
|
|
- if (!this.data["private_tweet"]) {
|
|
+ const likeEntry = await this.gun.getLikes(this.id);
|
|
- this.twitter.likeTweet(id).then(() => {
|
|
+ this.privateFavoriteCount = likeEntry.likes;
|
|
- this.data["favorited"] = true;
|
|
+ this.ref.detectChanges();
|
|
- this.data["favorite_count"]++;
|
|
+ }
|
|
- this.ref.detectChanges();
|
|
+
|
|
- });
|
|
+ addPrivateLike(id: string) {
|
|
- }
|
|
+ this.vibration.vibrate([100, 50, 100]);
|
|
|
|
+ console.log(id);
|
|
|
|
+ this.gun.addLike(id).then(() => {
|
|
|
|
+ this.privateFavoriteCount++;
|
|
|
|
+ this.ref.detectChanges();
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
- removeLike(id: string): void {
|
|
+ toggleLike(id: string) {
|
|
- if (!this.data["private_tweet"]) {
|
|
+ this.vibration.vibrate([100, 50, 100]);
|
|
- this.twitter.unlikeTweet(id).then(() => {
|
|
+ if (this.data["favorited"]) {
|
|
- this.data["favorited"] = false;
|
|
+ this.removeLike(id);
|
|
- this.data["favorite_count"]--;
|
|
+ } else {
|
|
- this.ref.detectChanges();
|
|
+ this.like(id);
|
|
- });
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private like(id: string): void {
|
|
|
|
+ this.twitter.likeTweet(id).then(() => {
|
|
|
|
+ this.data["favorited"] = true;
|
|
|
|
+ this.data["favorite_count"]++;
|
|
|
|
+ this.ref.detectChanges();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private removeLike(id: string): void {
|
|
|
|
+ this.twitter.unlikeTweet(id).then(() => {
|
|
|
|
+ this.data["favorited"] = false;
|
|
|
|
+ this.data["favorite_count"]--;
|
|
|
|
+ this.ref.detectChanges();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
retweetStatus(id: string): void {
|
|
retweetStatus(id: string): void {
|
|
this.navCtrl.push(WriteTweetPage, { tweetId: id });
|
|
this.navCtrl.push(WriteTweetPage, { tweetId: id });
|
|
}
|
|
}
|