static void likeTweet(String currentUserId, Tweet tweet) { DocumentReference tweetDocProfile = tweetsRef.doc(tweet.authorId).collection('userTweets').doc(tweet.id); tweetDocProfile.get().then((doc) { int likes = doc.data()['likes']; //error the operator isn't defined for the type 'object, tweetDocProfile.update({'likes': likes + 1}); });
DocumentReference tweetDocFeed =
feedRefs.doc(currentUserId).collection('userFeed').doc(tweet.id);
tweetDocFeed.get().then((doc) {
if (doc.exists) {
int likes = doc.data()['likes'];
tweetDocFeed.update({'likes': likes + 1});
}
});
likesRef.doc(tweet.id).collection('tweetLikes').doc(currentUserId).set({});
addActivity(currentUserId, tweet, false, null);
}
static void unlikeTweet(String currentUserId, Tweet tweet) { DocumentReference tweetDocProfile = tweetsRef.doc(tweet.authorId).collection('userTweets').doc(tweet.id); tweetDocProfile.get().then((doc) { int likes = doc.data()['likes']; tweetDocProfile.update({'likes': likes - 1}); });
DocumentReference tweetDocFeed =
feedRefs.doc(currentUserId).collection('userFeed').doc(tweet.id);
tweetDocFeed.get().then((doc) {
if (doc.exists) {
int likes = doc.data()['likes'];
tweetDocFeed.update({'likes': likes - 1});
}
});
likesRef
.doc(tweet.id)
.collection('tweetLikes')
.doc(currentUserId)
.get()
.then((doc) => doc.reference.delete());
}