io.rong.imlib.model.Message Java Examples
The following examples show how to use
io.rong.imlib.model.Message.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SessionAtPresenter.java From LQRWeChat with MIT License | 6 votes |
public void getRemoteHistoryMessages() { //消息中的 sentTime;第一次可传 0,获取最新 count 条。 long dateTime = 0; if (mData.size() > 0) { dateTime = mData.get(0).getSentTime(); } else { dateTime = 0; } RongIMClient.getInstance().getRemoteHistoryMessages(mConversationType, mSessionId, dateTime, mMessageCount, new RongIMClient.ResultCallback<List<Message>>() { @Override public void onSuccess(List<Message> messages) { saveHistoryMsg(messages); } @Override public void onError(RongIMClient.ErrorCode errorCode) { loadMessageError(errorCode); } }); }
Example #2
Source File: SessionAtPresenter.java From LQRWeChat with MIT License | 6 votes |
public void getLocalHistoryMessage() { //没有消息第一次调用应设置为:-1。 int messageId = -1; if (mData.size() > 0) { messageId = mData.get(0).getMessageId(); } else { messageId = -1; } RongIMClient.getInstance().getHistoryMessages(mConversationType, mSessionId, messageId, mMessageCount, new RongIMClient.ResultCallback<List<Message>>() { @Override public void onSuccess(List<Message> messages) { getView().getRefreshLayout().endRefreshing(); if (messages == null || messages.size() == 0) getRemoteHistoryMessages(); else saveHistoryMsg(messages); } @Override public void onError(RongIMClient.ErrorCode errorCode) { getView().getRefreshLayout().endRefreshing(); loadMessageError(errorCode); } }); }
Example #3
Source File: SessionAdapter.java From LQRWeChat with MIT License | 6 votes |
private void setTime(LQRViewHolderForRecyclerView helper, Message item, int position) { boolean isSend = item.getMessageDirection() == Message.MessageDirection.SEND ? true : false; long msgTime = isSend ? item.getSentTime() : item.getReceivedTime(); if (position > 0) { Message preMsg = mData.get(position - 1); boolean isSendForPreMsg = preMsg.getMessageDirection() == Message.MessageDirection.SEND ? true : false; long preMsgTime = isSendForPreMsg ? preMsg.getSentTime() : preMsg.getReceivedTime(); if (msgTime - preMsgTime > (5 * 60 * 1000)) { helper.setViewVisibility(R.id.tvTime, View.VISIBLE).setText(R.id.tvTime, TimeUtils.getMsgFormatTime(msgTime)); } else { helper.setViewVisibility(R.id.tvTime, View.GONE); } } else { helper.setViewVisibility(R.id.tvTime, View.VISIBLE).setText(R.id.tvTime, TimeUtils.getMsgFormatTime(msgTime)); } }
Example #4
Source File: SessionAtPresenter.java From LQRWeChat with MIT License | 6 votes |
private void updateMessageStatus(int messageId) { RongIMClient.getInstance().getMessage(messageId, new RongIMClient.ResultCallback<Message>() { @Override public void onSuccess(Message message) { for (int i = 0; i < mData.size(); i++) { Message msg = mData.get(i); if (msg.getMessageId() == message.getMessageId()) { mData.remove(i); mData.add(i, message); mAdapter.notifyDataSetChangedWrapper(); break; } } } @Override public void onError(RongIMClient.ErrorCode errorCode) { } }); }
Example #5
Source File: SessionAdapter.java From LQRWeChat with MIT License | 5 votes |
@Override public void convert(LQRViewHolderForRecyclerView helper, Message item, int position) { setTime(helper, item, position); setView(helper, item, position); if (!(item.getContent() instanceof GroupNotificationMessage) && !(item.getContent() instanceof RecallNotificationMessage) && (getItemViewType(position) != UNDEFINE_MSG)) { setAvatar(helper, item, position); setName(helper, item, position); setStatus(helper, item, position); setOnClick(helper, item, position); } }
Example #6
Source File: SessionAtPresenter.java From LQRWeChat with MIT License | 5 votes |
public void recallMessageFromListener(int messageId, RecallNotificationMessage recallNotificationMessage) { for (int i = 0; i < mData.size(); i++) { Message message = mData.get(i); if (message.getMessageId() == messageId) { recallMessageAndInsertMessage(recallNotificationMessage, i); break; } } }
Example #7
Source File: SessionAtPresenter.java From LQRWeChat with MIT License | 5 votes |
private void saveHistoryMsg(List<Message> messages) { //messages的时间顺序从新到旧排列,所以必须反过来加入到mData中 if (messages != null && messages.size() > 0) { for (Message msg : messages) { mData.add(0, msg); } getView().getRvMsg().moveToPosition(messages.size() - 1); } }
Example #8
Source File: SessionAtPresenter.java From LQRWeChat with MIT License | 5 votes |
private void updateMessageStatus(Message message) { for (int i = 0; i < mData.size(); i++) { Message msg = mData.get(i); if (msg.getMessageId() == message.getMessageId()) { mData.remove(i); mData.add(i, message); mAdapter.notifyDataSetChangedWrapper(); break; } } }
Example #9
Source File: SessionAdapter.java From LQRWeChat with MIT License | 5 votes |
@Override public int getItemViewType(int position) { Message msg = mData.get(position); boolean isSend = msg.getMessageDirection() == Message.MessageDirection.SEND ? true : false; MessageContent msgContent = msg.getContent(); if (msgContent instanceof TextMessage) { return isSend ? SEND_TEXT : RECEIVE_TEXT; } if (msgContent instanceof ImageMessage) { return isSend ? SEND_IMAGE : RECEIVE_IMAGE; } if (msgContent instanceof FileMessage) { FileMessage fileMessage = (FileMessage) msgContent; if (MediaFileUtils.isImageFileType(fileMessage.getName())) { return isSend ? SEND_STICKER : RECEIVE_STICKER; } else if (MediaFileUtils.isVideoFileType(fileMessage.getName())) { return isSend ? SEND_VIDEO : RECEIVE_VIDEO; } } if (msgContent instanceof LocationMessage) { return isSend ? SEND_LOCATION : RECEIVE_LOCATION; } if (msgContent instanceof GroupNotificationMessage) { return RECEIVE_NOTIFICATION; } if (msgContent instanceof VoiceMessage) { return isSend ? SEND_VOICE : RECEIVE_VOICE; } if (msgContent instanceof RedPacketMessage) { return isSend ? SEND_RED_PACKET : RECEIVE_RED_PACKET; } if (msgContent instanceof RecallNotificationMessage) { return RECALL_NOTIFICATION; } return UNDEFINE_MSG; }
Example #10
Source File: SessionAdapter.java From LQRWeChat with MIT License | 5 votes |
private void setName(LQRViewHolderForRecyclerView helper, Message item, int position) { if (item.getConversationType() == Conversation.ConversationType.PRIVATE) { helper.setViewVisibility(R.id.tvName, View.GONE); } else { helper.setViewVisibility(R.id.tvName, View.GONE); // .setText(R.id.tvName, item.getContent().getUserInfo().getName()); } }
Example #11
Source File: SessionAdapter.java From LQRWeChat with MIT License | 5 votes |
private void setAvatar(LQRViewHolderForRecyclerView helper, Message item, int position) { ImageView ivAvatar = helper.getView(R.id.ivAvatar); UserInfo userInfo = DBManager.getInstance().getUserInfo(item.getSenderUserId()); if (userInfo != null) { Glide.with(mContext).load(userInfo.getPortraitUri()).centerCrop().into(ivAvatar); } }
Example #12
Source File: SessionAdapter.java From LQRWeChat with MIT License | 5 votes |
private void setOnClick(LQRViewHolderForRecyclerView helper, Message item, int position) { helper.getView(R.id.llError).setOnClickListener(v -> RongIMClient.getInstance().deleteMessages(new int[]{item.getMessageId()}, new RongIMClient.ResultCallback<Boolean>() { @Override public void onSuccess(Boolean aBoolean) { mData.remove(position); mPresenter.setAdapter(); MessageContent content = item.getContent(); if (content instanceof TextMessage) { mPresenter.sendTextMsg(((TextMessage) content).getContent()); } else if (content instanceof ImageMessage) { mPresenter.sendImgMsg(((ImageMessage) content).getThumUri(), ((ImageMessage) content).getLocalUri()); } else if (content instanceof FileMessage) { mPresenter.sendFileMsg(new File(((FileMessage) content).getLocalPath().getPath())); } else if (content instanceof VoiceMessage) { VoiceMessage voiceMessage = (VoiceMessage) content; mPresenter.sendAudioFile(voiceMessage.getUri(), voiceMessage.getDuration()); } } @Override public void onError(RongIMClient.ErrorCode errorCode) { } }) ); helper.getView(R.id.ivAvatar).setOnClickListener(v -> { UserInfo userInfo = DBManager.getInstance().getUserInfo(item.getSenderUserId()); if (userInfo != null) { Intent intent = new Intent(mContext, UserInfoActivity.class); intent.putExtra("userInfo", userInfo); ((SessionActivity) mContext).jumpToActivity(intent); } }); }
Example #13
Source File: SessionAtPresenter.java From LQRWeChat with MIT License | 4 votes |
public void receiveNewMessage(Message message) { mData.add(message); setAdapter(); RongIMClient.getInstance().clearMessagesUnreadStatus(mConversationType, mSessionId); }
Example #14
Source File: SessionAdapter.java From LQRWeChat with MIT License | 4 votes |
public SessionAdapter(Context context, List<Message> data, SessionAtPresenter presenter) { super(context, data); mContext = context; mData = data; mPresenter = presenter; }
Example #15
Source File: SessionAtPresenter.java From LQRWeChat with MIT License | 4 votes |
private void recallMessageAndInsertMessage(RecallNotificationMessage recallNotificationMessage, int position) { RongIMClient.getInstance().insertMessage(mConversationType, mSessionId, UserCache.getId(), recallNotificationMessage); mData.remove(position); mData.add(Message.obtain(mSessionId, mConversationType, recallNotificationMessage)); mAdapter.notifyDataSetChangedWrapper(); }
Example #16
Source File: SealAppContext.java From sealtalk-android with MIT License | 4 votes |
@Override public boolean onReceived(Message message, int i) { MessageContent messageContent = message.getContent(); if (messageContent instanceof ContactNotificationMessage) { ContactNotificationMessage contactNotificationMessage = (ContactNotificationMessage) messageContent; if (contactNotificationMessage.getOperation().equals("Request")) { //对方发来好友邀请 BroadcastManager.getInstance(mContext).sendBroadcast(SealAppContext.UPDATEREDDOT); } else if (contactNotificationMessage.getOperation().equals("AcceptResponse")) { //对方同意我的好友请求 ContactNotificationMessageData c = null; try { c = JsonMananger.jsonToBean(contactNotificationMessage.getExtra(), ContactNotificationMessageData.class); } catch (HttpException e) { e.printStackTrace(); } if (c != null) { DBManager.getInstance(mContext).getDaoSession().getFriendDao().insertOrReplace(new Friend(contactNotificationMessage.getSourceUserId(), c.getSourceUserNickname(), null, null, null, null)); } BroadcastManager.getInstance(mContext).sendBroadcast(UPDATEFRIEND); BroadcastManager.getInstance(mContext).sendBroadcast(SealAppContext.UPDATEREDDOT); } // // 发广播通知更新好友列表 // BroadcastManager.getInstance(mContext).sendBroadcast(UPDATEREDDOT); // } } else if (messageContent instanceof AgreedFriendRequestMessage) {//好友添加成功消息 AgreedFriendRequestMessage agreedFriendRequestMessage = (AgreedFriendRequestMessage) messageContent; if (agreedFriendRequestMessage.getUserInfo() != null) { UserInfo bean = agreedFriendRequestMessage.getUserInfo(); DBManager.getInstance(mContext).getDaoSession().getFriendDao().insertOrReplace( new Friend(bean.getUserId(), bean.getName(), String.valueOf(bean.getPortraitUri()), null, null, null) ); } else { DBManager.getInstance(mContext).getDaoSession().getFriendDao().insertOrReplace( new Friend(agreedFriendRequestMessage.getFriendId()) ); RongIM.getInstance().refreshUserInfoCache(new UserInfo(agreedFriendRequestMessage.getUserInfo().getUserId(), agreedFriendRequestMessage.getUserInfo().getName(), agreedFriendRequestMessage.getUserInfo().getPortraitUri() )); } } else if (messageContent instanceof GroupNotificationMessage) { GroupNotificationMessage groupNotificationMessage = (GroupNotificationMessage) messageContent; NLog.e("" + groupNotificationMessage.getMessage()); if (groupNotificationMessage.getOperation().equals("Kicked")) { } else if (groupNotificationMessage.getOperation().equals("Add")) { } else if (groupNotificationMessage.getOperation().equals("Quit")) { } else if (groupNotificationMessage.getOperation().equals("Rename")) { } BroadcastManager.getInstance(mContext).sendBroadcast(SealAppContext.NETUPDATEGROUP); } else if (messageContent instanceof ImageMessage) { ImageMessage imageMessage = (ImageMessage) messageContent; Log.e("imageMessage", imageMessage.getRemoteUri().toString()); } return false; }
Example #17
Source File: SealAppContext.java From sealtalk-android with MIT License | 4 votes |
@Override public boolean onMessageLongClick(Context context, View view, Message message) { return false; }