Ejemplo n.º 1
0
 @Override
 public void onMessageReceipt(
     AVIMTypedMessage message, AVIMConversation conversation, AVIMClient client) {
   if (client.getClientId().equals(chatManager.getSelfId())) {
     chatManager.onMessageReceipt(message);
   } else {
     client.close(null);
   }
 }
Ejemplo n.º 2
0
 @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);
   }
 }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 /**
  * 获取单聊对话的另外一个人的 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();
 }
Ejemplo n.º 5
0
  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;
  }
Ejemplo n.º 6
0
 @Override
 protected void onResume() {
   CacheService.setCurConv(conversation);
   ChatManagerAdapterImpl chatManagerAdapter =
       (ChatManagerAdapterImpl) ChatManager.getInstance().getChatManagerAdapter();
   chatManagerAdapter.cancelNotification();
   super.onResume();
 }
Ejemplo n.º 7
0
 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);
               }
             }
           });
 }
Ejemplo n.º 8
0
 // ChatUser
 public List<Room> findRecentRooms() {
   return ChatManager.getInstance().getRoomsTable().selectRooms();
 }