融云设置已读,未读消息标识

融云设置已读,未读消息标识

需求:会话列表,以及会话界面发出去的消息前面加上已读,未读的标识

官方给的解决方案

1、您可以通过 rc_config.xml 里的开关,开启消息的阅读回执功能。默认 false 为关闭状态,设置成 true 为开启
2、请在 init 之后调用下面方法来设置支持消息回执的会话类型。目前只支持 PRIVATE、GROUP 和 DISCUSSION 三种类型
官方还有一个说的更详细的文档,忘了在哪里,找不到了

官方的没法解决我的需求,就算它能显示也不是我想要的。

处理会话界面

1、自定义类继承自 MessageListAdpater, 然后重写其中的 holder.sentStatus

2、布局是 rc_item_message.xml

3、自定义类集成自 ConversationFragment,然后重写onResolveAdpater 中得到自定义adpter并返回
参考代码

public class MyMessageListAdapter extends MessageListAdapter {
public MyMessageListAdapter(Context context) {
    super(context);
}

@Override
protected void bindView(View v, int position, UIMessage data) {
    super.bindView(v, position, data);
    if(data != null){
        final MessageListAdapter.ViewHolder holder = (MessageListAdapter.ViewHolder) v.getTag();
        if(holder != null){
            if (data.getMessageDirection().equals(Message.MessageDirection.RECEIVE)) {
                holder.sentStatus.setVisibility(View.GONE);
            } else {
                LogUtils.i("msgStatus", data.getSentStatus().getValue() + "");
                if (data.getSentStatus() == Message.SentStatus.SENT) {
                    holder.sentStatus.setCompoundDrawablesWithIntrinsicBounds(v.getContext().getResources().getDrawable(R.mipmap.ic_msg_sent),null,null,null);
                    holder.sentStatus.setText(R.string.im_msg_sent);
                    holder.sentStatus.setVisibility(View.VISIBLE);
                } else if (data.getSentStatus() == Message.SentStatus.READ) {
                    holder.sentStatus.setText(R.string.im_msg_read);
                    holder.sentStatus.setCompoundDrawablesWithIntrinsicBounds(v.getContext().getResources().getDrawable(R.mipmap.ic_msg_read),null,null,null);
                    holder.sentStatus.setVisibility(View.VISIBLE);

                }
            }
        }

    }


}}

敲黑板:rc_config.xml 里的开关,开启消息的阅读回执功能。默认 false 为关闭状态,设置成 true 为开启 ,如果能正常显示最好,不能正常显示,需要在会话界面自己发送阅读回执。

处理会话列表界面

集成 PrivateConversationProvider 然后重新 bindView 方法, 然后在此方法中 根据 Message.SentStatus来进行修改显示内容
参考代码:

@ConversationProviderTag(
conversationType = "private",
portraitPosition = 1
)
public class MyPrivateConversationProvider extends PrivateConversationProvider {

@Override
public void bindView(View view, int position, UIConversation data) {
    super.bindView(view, position, data);
    PrivateConversationProvider.ViewHolder holder = (PrivateConversationProvider.ViewHolder)view.getTag();

        if(null != data && data.getConversationSenderId() != null && data.getConversationSenderId().equals(RongIM.getInstance().getCurrentUserId())){
            if(data.getSentStatus() != null){
                if(data.getSentStatus() == Message.SentStatus.FAILED || data.getSentStatus() == Message.SentStatus.SENDING){
                    holder.readStatus.setVisibility(View.GONE);
                } else {
                    if(data.getSentStatus() == Message.SentStatus.SENT){
                        holder.readStatus.setImageResource(R.mipmap.ic_msg_sent);
                        holder.readStatus.setVisibility(View.VISIBLE);
                    } else if(data.getSentStatus() == Message.SentStatus.READ){
                        holder.readStatus.setImageResource(R.mipmap.ic_msg_read);
                        holder.readStatus.setVisibility(View.VISIBLE);
                    }
                }
            }

        }

}}

提供下我问的工单
https://developer.rongcloud.cn/ticket/info/eB25GrlyC8EwlcdG1kY=
有问题请加Q群:142739277

你可能感兴趣的:(融云设置已读,未读消息标识)