Firebase
firestore
以存储聊天信息。
有些特定的消息我只希望其中一个用户收到。
目前我有两种视图类型:
-
-
发送消息的视图类型
假设有以下对话:
用户1到用户2:
CLICKS ON A BUTTON AND AN AUTOMATIC MESSAGE IS SENT <----want it to show only to user2.
我如何确保只有user2会得到它?
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view;
if (viewType == AppConstants.CHAT_SENT_KEY) {
view = LayoutInflater.from( parent.getContext() ).inflate(
R.layout.item_chat_sent,
parent,
false );
return new ChatViewHolder( view );
} else if (viewType == AppConstants.CHAT_RECEIVED_KEY) {
view = LayoutInflater.from( parent.getContext() ).inflate(
R.layout.item_chat_received,
parent,
false );
return new ChatViewHolder( view );
} else {
view = LayoutInflater.from( parent.getContext() ).inflate( R.layout.item_loading, parent, false );
return new LoadingViewHolder( view );
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
if (viewHolder instanceof ChatViewHolder) {
((ChatViewHolder) viewHolder).bind( (chats.get( position )) );
} else if (viewHolder instanceof LoadingViewHolder) {
showLoadingView( (LoadingViewHolder) viewHolder, position );
}
}
@Override
public int getItemViewType(int position) {
if (chats.get( position ).getSenderId().contentEquals( userId )) {
if (position == 0 && chats.size() > 49 && snapSize > 49) {
return AppConstants.CHAT_LOADING_KEY;
} else {
return AppConstants.CHAT_SENT_KEY;
}
} else {
if (position == 0 && chats.size() > 49 && snapSize > 49) {
return AppConstants.CHAT_LOADING_KEY;
} else {
return AppConstants.CHAT_RECEIVED_KEY;
}
}
}
有什么联系吗
viewTypes