我正在开发一个社交网络应用程序,用户可以在其中关注其他用户,并喜欢他们的帖子,评论...每当有人关注某人时,它就会在其他用户帐户的通知片段中显示,以通知他他有新的关注者。问题是当用户点击取消关注时,我无法删除通知。这是我尝试过的:
if ( holder.btn_follow.getText().toString().equals("follow"))
{
addNotifications(user.getId());
}
else{
FirebaseDatabase.getInstance().getReference("Notifications").child(user.getId()).removeValue();
}
这是我添加通知的方式:
private void addNotifications(String userid)
{
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Notifications").child(userid);
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("userid", firebaseUser.getUid());
hashMap.put("text"," started following you");
hashMap.put("postid","");
hashMap.put("ispost",false);
reference.push().setValue(hashMap);
}
我的代码的问题在于,只要用户取消关注某人,该用户的所有通知都将被删除,包括他的喜欢和评论。我要删除的是“开始关注您”。这是它在Firebase数据库中的外观。
使用Firebase查询指的是Firebase文档,它将是这样的
Query queryRef = mReference.child("Notifications").child(userId).orderByChild("text").equalTo("start following you");
queryRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snapshot, String previousChild) {
// snapshot.getRef().setValue(null);
snapshot.getRef().remove();
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句