public void OnSuccess(Java.Lang.Object result) { DocumentSnapshot snapshot = (DocumentSnapshot)result; if (!snapshot.Exists()) { return; } DocumentReference likeReference = AppDataHelper.GetFirestore().Collection("posts").Document(postID); if (like) { likeReference.Update("likes." + AppDataHelper.GetFirebaseAuth().CurrentUser.Uid, true); } else { //check for null if (snapshot.Get("likes") == null) { return; } var data = snapshot.Get("likes") != null?snapshot.Get("likes") : null; if (data != null) { var dictionaryFromHashMap = new Android.Runtime.JavaDictionary <string, string>(data.Handle, JniHandleOwnership.DoNotRegister); //retrieve our own id string uid = AppDataHelper.GetFirebaseAuth().CurrentUser.Uid; //check if our user ID is contained inside the dictionary if (dictionaryFromHashMap.Contains(uid)) { //remove our user ID to unlike the post dictionaryFromHashMap.Remove(uid); //update the hashmap withour our userid included likeReference.Update("likes", dictionaryFromHashMap); } } } }
public void OnSuccess(Java.Lang.Object result) { DocumentSnapshot snapshot = (DocumentSnapshot)result; if (!snapshot.Exists()) { return; } DocumentReference likesReference = AppDataHelper.GetFirestore().Collection("posts").Document(postID); if (Like) { likesReference.Update("likes." + AppDataHelper.GetFirebaseAuth().CurrentUser.Uid, true); } else { if (snapshot.Get("likes") == null) { return; } var data = snapshot.Get("likes") != null?snapshot.Get("likes") : null; if (data != null) { var dictionaryFromHashMap = new Android.Runtime.JavaDictionary <string, string>(data.Handle, JniHandleOwnership.DoNotRegister); string uid = AppDataHelper.GetFirebaseAuth().CurrentUser.Uid; if (dictionaryFromHashMap.Contains(uid)) { dictionaryFromHashMap.Remove(uid); likesReference.Update("likes", dictionaryFromHashMap); } } } }