|
@@ -4,6 +4,9 @@ import { NavController } from "ionic-angular";
|
|
|
import { WriteTweetPage } from "../../pages/write-tweet/write-tweet";
|
|
|
import { P2pDatabaseGunProvider } from "../../providers/p2p-database-gun/p2p-database-gun";
|
|
|
import { Vibration } from "@ionic-native/vibration";
|
|
|
+import { Storage } from "@ionic/storage";
|
|
|
+import { MockProvider } from "../../providers/mock-provider/mock-provider";
|
|
|
+
|
|
|
|
|
|
@Component({
|
|
|
selector: "tweet-actions",
|
|
@@ -16,17 +19,21 @@ export class TweetActionsComponent {
|
|
|
|
|
|
constructor(
|
|
|
private twitter: TwitterApiProvider,
|
|
|
+ private storage: Storage,
|
|
|
private ref: ChangeDetectorRef,
|
|
|
private navCtrl: NavController,
|
|
|
private gun: P2pDatabaseGunProvider,
|
|
|
- private vibration: Vibration
|
|
|
+ private vibration: Vibration,
|
|
|
+ private mockProv: MockProvider
|
|
|
) {}
|
|
|
|
|
|
ngOnInit() {
|
|
|
+ console.log('ngOnInit calling getPrivateLikes ');
|
|
|
this.getPrivateLikes(this.id);
|
|
|
}
|
|
|
|
|
|
get favoriteCount() {
|
|
|
+ console.log('favoriteCount');
|
|
|
if (this.data["retweeted_status"]) {
|
|
|
return this.data["retweeted_status"]["favorite_count"];
|
|
|
} else {
|
|
@@ -35,6 +42,7 @@ export class TweetActionsComponent {
|
|
|
}
|
|
|
|
|
|
get id() {
|
|
|
+ console.log('id');
|
|
|
if (this.data["retweeted_status"]) {
|
|
|
return this.data["retweeted_status"]["id_str"];
|
|
|
} else {
|
|
@@ -43,6 +51,7 @@ export class TweetActionsComponent {
|
|
|
}
|
|
|
|
|
|
private async getPrivateLikes(id: string) {
|
|
|
+ console.log('getPrivateLikes');
|
|
|
const likeEntry = await this.gun.getLikes(this.id);
|
|
|
if (likeEntry.likes > 0) {
|
|
|
this.privateFavoriteCount = likeEntry.likes;
|
|
@@ -51,6 +60,7 @@ export class TweetActionsComponent {
|
|
|
}
|
|
|
|
|
|
addPrivateLike(id: string) {
|
|
|
+ console.log('addPrivateLike',id);
|
|
|
this.vibration.vibrate([100, 50, 100]);
|
|
|
this.gun.addLike(id).then(() => {
|
|
|
this.privateFavoriteCount++;
|
|
@@ -59,6 +69,7 @@ export class TweetActionsComponent {
|
|
|
}
|
|
|
|
|
|
toggleLike(id: string) {
|
|
|
+ console.log('toggleLike');
|
|
|
this.vibration.vibrate([100, 50, 100]);
|
|
|
if (this.data["favorited"]) {
|
|
|
this.removeLike(id);
|
|
@@ -68,26 +79,44 @@ export class TweetActionsComponent {
|
|
|
}
|
|
|
|
|
|
private like(id: string): void {
|
|
|
- this.twitter.likeTweet(id).then(() => {
|
|
|
+ console.log('like : ', id);
|
|
|
+ if(this.storage.get("mockup")){
|
|
|
+ console.log('like tweet in mock');
|
|
|
+ this.mockProv.likeTweet(id);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ 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(() => {
|
|
|
+ console.log('removeLike:');
|
|
|
+ if(this.storage.get("mockup")){
|
|
|
+ console.log('unlike tweet in mock');
|
|
|
+ this.mockProv.unlikeTweet(id);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ this.twitter.unlikeTweet(id).then(() => {
|
|
|
this.data["favorited"] = false;
|
|
|
this.data["favorite_count"]--;
|
|
|
this.ref.detectChanges();
|
|
|
- });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
retweetStatus(id: string): void {
|
|
|
+ console.log('retweetStatus');
|
|
|
this.navCtrl.push(WriteTweetPage, { tweetId: id });
|
|
|
}
|
|
|
|
|
|
replyToStatus(id: string): void {
|
|
|
+ console.log('replyToStatus');
|
|
|
this.navCtrl.push(WriteTweetPage, { replyToStatus: id });
|
|
|
}
|
|
|
}
|