@Override public void onMessageReceipt( AVIMTypedMessage message, AVIMConversation conversation, AVIMClient client) { if (client.getClientId().equals(chatManager.getSelfId())) { chatManager.onMessageReceipt(message); } else { client.close(null); } }
@Override public void onMessage( AVIMTypedMessage message, AVIMConversation conversation, AVIMClient client) { if (chatManager.getSelfId() == null) { LogUtils.d("selfId is null, please call setupManagerWithUserId "); } if (client.getClientId().equals(chatManager.getSelfId())) { chatManager.onMessage(message, conversation, client); } else { // 收到其它的client的消息,可能是上一次别的client登录未正确关闭,这里关边掉。 client.close(null); } }
public static void chatByConversation(Context from, AVIMConversation conv) { CacheService.registerConv(conv); ChatManager.getInstance().registerConversation(conv); Intent intent = new Intent(from, ChatRoomActivity.class); intent.putExtra(CONVID, conv.getConversationId()); from.startActivity(intent); }
/** * 获取单聊对话的另外一个人的 userId * * @param conversation * @return 如果非法对话,则为 selfId */ public static String otherIdOfConversation(AVIMConversation conversation) { if (isValidConversation(conversation)) { if (typeOfConversation(conversation) == ConversationType.Single) { List<String> members = conversation.getMembers(); if (members.size() == 2) { if (members.get(0).equals(ChatManager.getInstance().getSelfId())) { return members.get(1); } else { return members.get(0); } } } } // 尽管异常,返回可以使用的 userId return ChatManager.getInstance().getSelfId(); }
public static boolean isValidConversation(AVIMConversation conversation) { if (conversation == null) { LogUtils.d("invalid reason : conversation is null"); return false; } if (conversation.getMembers() == null || conversation.getMembers().size() == 0) { LogUtils.d("invalid reason : conversation members null or empty"); return false; } Object type = conversation.getAttribute(ConversationType.TYPE_KEY); if (type == null) { LogUtils.d("invalid reason : type is null"); return false; } int typeInt = (Integer) type; if (typeInt == ConversationType.Single.getValue()) { if (conversation.getMembers().size() != 2 || conversation.getMembers().contains(ChatManager.getInstance().getSelfId()) == false) { LogUtils.d("invalid reason : oneToOne conversation not correct"); return false; } } else if (typeInt == ConversationType.Group.getValue()) { } else { LogUtils.d("invalid reason : typeInt wrong"); return false; } return true; }
@Override protected void onResume() { CacheService.setCurConv(conversation); ChatManagerAdapterImpl chatManagerAdapter = (ChatManagerAdapterImpl) ChatManager.getInstance().getChatManagerAdapter(); chatManagerAdapter.cancelNotification(); super.onResume(); }
public static void chatByUserId(final Activity from, String userId) { final ProgressDialog dialog = Utils.showSpinnerDialog(from); ChatManager.getInstance() .fetchConversationWithUserId( userId, new AVIMConversationCreatedCallback() { @Override public void done(AVIMConversation conversation, AVException e) { dialog.dismiss(); if (Utils.filterException(e)) { chatByConversation(from, conversation); } } }); }
// ChatUser public List<Room> findRecentRooms() { return ChatManager.getInstance().getRoomsTable().selectRooms(); }