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; } }
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 ""; } }