Java Code Examples for com.hyphenate.chat.EMMessage.ChatType#GroupChat

The following examples show how to use com.hyphenate.chat.EMMessage.ChatType#GroupChat . 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: EaseChatFragment.java    From Social with Apache License 2.0 6 votes vote down vote up
@Override
public void onMessageReceived(List<EMMessage> messages) {

    for (EMMessage message : messages) {
              String username = null;
              // 群组消息
              if (message.getChatType() == ChatType.GroupChat || message.getChatType() == ChatType.ChatRoom) {
                  username = message.getTo();
              } else {
                  // 单聊消息
                  username = message.getFrom();
              }
  
              // 如果是当前会话的消息,刷新聊天页面
              if (username.equals(toChatUsername)) {
                  messageList.refreshSelectLast();
                  // 声音和震动提示有新消息
                  EaseUI.getInstance().getNotifier().viberateAndPlayTone(message);
              } else {
                  // 如果消息不是和当前聊天ID的消息
                  EaseUI.getInstance().getNotifier().onNewMsg(message);
              }
    }
}
 
Example 2
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
@Override
public void onMessageReceived(List<EMMessage> messages) {
    for (EMMessage message : messages) {
        String username = null;
        // group message
        if (message.getChatType() == ChatType.GroupChat || message.getChatType() == ChatType.ChatRoom) {
            username = message.getTo();
        } else {
            // single chat message
            username = message.getFrom();
        }

        // if the message is for current conversation
        if (username.equals(toChatUsername) || message.getTo().equals(toChatUsername)) {
            messageList.refreshSelectLast();
            EaseUI.getInstance().getNotifier().vibrateAndPlayTone(message);
        } else {
            EaseUI.getInstance().getNotifier().onNewMsg(message);
        }
    }
}
 
Example 3
Source File: EaseChatFragment.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onMessageReceived(List<EMMessage> messages) {

    for (EMMessage message : messages) {
              String username = null;
              // 群组消息
              if (message.getChatType() == ChatType.GroupChat || message.getChatType() == ChatType.ChatRoom) {
                  username = message.getTo();
              } else {
                  // 单聊消息
                  username = message.getFrom();
              }
  
              // 如果是当前会话的消息,刷新聊天页面
              if (username.equals(toChatUsername)) {
                  messageList.refreshSelectLast();
                  // 声音和震动提示有新消息
                  EaseUI.getInstance().getNotifier().viberateAndPlayTone(message);
              } else {
                  // 如果消息不是和当前聊天ID的消息
                  EaseUI.getInstance().getNotifier().onNewMsg(message);
              }
    }
}
 
Example 4
Source File: EaseAtMessageHelper.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * parse the message, get and save group id if I was mentioned(@)
 * @param messages
 */
public void parseMessages(List<EMMessage> messages) {
    int size = atMeGroupList.size();
    EMMessage[] msgs = messages.toArray(new EMMessage[messages.size()]);
    for(EMMessage msg : msgs){
        if(msg.getChatType() == ChatType.GroupChat){
            String groupId = msg.getTo();
            try {
                JSONArray jsonArray = msg.getJSONArrayAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG);
                for(int i = 0; i < jsonArray.length(); i++){
                    String username = jsonArray.getString(i);
                    if(EMClient.getInstance().getCurrentUser().equals(username)){
                        if(!atMeGroupList.contains(groupId)){
                            atMeGroupList.add(groupId);
                            break;
                        }
                    }
                }
            } catch (Exception e1) {
                //Determine whether is @ all message
                String usernameStr = msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG, null);
                if(usernameStr != null){
                    if(usernameStr.toUpperCase().equals(EaseConstant.MESSAGE_ATTR_VALUE_AT_MSG_ALL)){
                        if(!atMeGroupList.contains(groupId)){
                            atMeGroupList.add(groupId);
                        }
                    }
                }
            }
            
            if(atMeGroupList.size() != size){
                EasePreferenceManager.getInstance().setAtMeGroups(atMeGroupList);
            }
        }
    }
}