gpt4 book ai didi

java - 删除多个父节点上的特定子节点

转载 作者:行者123 更新时间:2023-12-02 10:00:44 26 4
gpt4 key购买 nike

我正在做一个应用程序,当用户删除他/她的帐户时,他在数据库中的所有数据记录也将被删除(例如,在 friend 中,等于他的 uid 的节点也将被自动删除,从而取消好友关系)其他用户。

this is the database structure

最佳答案

我正在从我的 friend 列表中删除一位 friend :-

private void removeFromFriend(final String type, String id) {

Map hashMap = new HashMap();
hashMap.put(firebaseUser.getUid() + "/" + id, null);
hashMap.put(id + "/" + firebaseUser.getUid(), null);

mDatabaseReference.child(userFriendListTableName).updateChildren(hashMap, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(@Nullable DatabaseError databaseError, @NonNull DatabaseReference databaseReference) {

if (databaseError == null) {
profileDialog.dismiss();
friendAdapter.notifyDataSetChanged();
if (type.equalsIgnoreCase("block")) {
Toast.makeText(getActivity(), "Blocked Successfully", Toast.LENGTH_SHORT).show();
} else if (type.equals("report")) {
Toast.makeText(getActivity(), "Report as spam successfully and removed from friends", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(), "User removed from friends", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getActivity(), "" + databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}

}
});
}

如果您想更新一个引用中的 2 个或多个表,请执行此操作:-

friendsMap.put(userFriendListTableName + "/" + currentUserId + "/" + userId + "/friend_id", userId);
friendsMap.put(userFriendListTableName + "/" + currentUserId + "/" + userId + "/acceptDate", String.valueOf(System.currentTimeMillis()));
friendsMap.put(userFriendListTableName + "/" + userId + "/" + currentUserId + "/friend_id", currentUserId);
friendsMap.put(userFriendListTableName + "/" + userId + "/" + currentUserId + "/acceptDate", String.valueOf(System.currentTimeMillis()));

friendsMap.put(friendRequestTableName + "/" + currentUserId + "/" + userId, null);
friendsMap.put(friendRequestTableName + "/" + userId + "/" + currentUserId, null);

mRootRef.updateChildren(friendsMap, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(@Nullable DatabaseError databaseError, @NonNull DatabaseReference databaseReference) {
if (databaseError != null) {
Toast.makeText(context, "" + databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Toast.makeText(context, "" + databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});

在此,我将从好友请求列表中删除这两个用户,并将这两个用户添加到好友列表中

关于java - 删除多个父节点上的特定子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55661820/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com