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; }
public static int getVersionCode(Context ctx) { int versionCode = 0; try { versionCode = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode; } catch (PackageManager.NameNotFoundException e) { LogUtils.logException(e); } return versionCode; }
public static String getVersionName(Context ctx) { String versionName = null; try { versionName = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionName; } catch (PackageManager.NameNotFoundException e) { // TODO Auto-generated catch block LogUtils.logException(e); } return versionName; }
public static ConversationType typeOfConversation(AVIMConversation conversation) { if (isValidConversation(conversation)) { Object typeObject = conversation.getAttribute(ConversationType.TYPE_KEY); int typeInt = (Integer) typeObject; return ConversationType.fromInt(typeInt); } else { LogUtils.e("invalid conversation "); // 因为 Group 不需要取 otherId,检查没那么严格,避免导致崩溃 return ConversationType.Group; } }
List<AVIMTypedMessage> filterTypedMessages(List<AVIMMessage> messages) { List<AVIMTypedMessage> resultMessages = new ArrayList<>(); for (AVIMMessage msg : messages) { if (msg instanceof AVIMTypedMessage) { resultMessages.add((AVIMTypedMessage) msg); } else { LogUtils.i("unexpected message " + msg.getContent()); } } return resultMessages; }
@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); } }
private void onMessage( final AVIMTypedMessage message, final AVIMConversation conversation, AVIMClient imClient) { if (message == null || message.getMessageId() == null) { LogUtils.d("may be SDK Bug, message or message id is null"); return; } if (!ConversationHelper.isValidConversation(conversation)) { LogUtils.d("receive msg from invalid conversation"); } if (lookUpConversationById(conversation.getConversationId()) == null) { registerConversation(conversation); } LogUtils.d("receive message, content :", message.getContent()); roomsTable.insertRoom(message.getConversationId()); roomsTable.increaseUnreadCount(message.getConversationId()); MessageEvent messageEvent = new MessageEvent(message, MessageEvent.Type.Come); eventBus.post(messageEvent); if (currentChattingConvid == null || !currentChattingConvid.equals(message.getConversationId())) { chatManagerAdapter.shouldShowNotification(context, selfId, conversation, message); } }
public static String nameOfConversation(AVIMConversation conversation) { if (isValidConversation(conversation)) { if (typeOfConversation(conversation) == ConversationType.Single) { String otherId = otherIdOfConversation(conversation); AVUser user = AVUserCacheUtils.getCachedUser(otherId); if (user != null) { return user.getUsername(); } else { LogUtils.e("use is null"); return "对话"; } } else { return conversation.getName(); } } else { return ""; } }