我有一个聊天应用程序,这是使用firebase。它工作得很好。但有些用户会发送类似的俚语或诸如此类的东西。我使用的是Firebase Recyclerview。我的连接是直接连接到数据库的。因此,在添加数据之前,我无法验证消息是好是坏。
我想要做的是,我想将数据发送到其他位置。然后使用云函数验证后,我想将其添加到原始聊天室数据库中。
在这一步之前,我没有任何问题。但是当用户发送消息时。我不想让用户等待数据更新。云函数需要2-3秒的时间。我想在本地添加具有发送状态的数据,然后在聊天室数据库中更新数据时对其进行更新。
那么最好的方法是什么呢..
我的代码没有任何问题。它只是一个基本的firebase适配器..
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("rooms").child("Off-Topic").child("chat")
.limitToLast(500);
firebaseOptions = new FirebaseRecyclerOptions.Builder<ChatData>()
.setQuery(query, ChatData.class)
.build();
chatAdapter = new FirebaseRecyclerAdapter<ChatData, ChatHolder>(firebaseOptions) {
@Override
protected void onBindViewHolder(ChatHolder holder, int position, ChatData model) {
}
@Override
public ChatHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.sender_text_message, parent, false);
return new ChatHolder(v);
}
};发布于 2017-12-25 19:31:34
解决这个问题的最简单方法是在ChatData类中添加一个布尔变量。这个变量(让我们称它为isGood)在发送消息时将为false,当它被您的云函数更新时将变为true。
所以你的适配器的onBindViewHolder应该是:
@Override
protected void onBindViewHolder(ChatHolder holder, int position, ChatData model) {
if(model.isGood())
holder.textView.setText(model.getMessage()); //edit this line as needed
else
holder.textView.setText("sending..."); //replace textView with the name of your actual TextView
}https://stackoverflow.com/questions/47859450
复制相似问题