Java Code Examples for com.hyphenate.chat.EMMessage#getChatType()

The following examples show how to use com.hyphenate.chat.EMMessage#getChatType() . 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: MyEaseChatFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
/**
 * 转发消息
 *
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id);
    EMMessage.Type type = forward_msg.getType();
    switch (type) {
        case TXT:
            if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
                sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(),
                        forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null));
            }else{
                // 获取消息内容,发送消息
                String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage();
                sendTextMessage(content);
            }
            break;
        case IMAGE:
            // 发送图片
            String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl();
            if (filePath != null) {
                File file = new File(filePath);
                if (!file.exists()) {
                    // 不存在大图发送缩略图
                    filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath();
                }
                sendImageMessage(filePath);
            }
            break;
        default:
            break;
    }

    if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){
        EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example 5
Source File: EaseChatFragment.java    From Social with Apache License 2.0 5 votes vote down vote up
/**
 * 转发消息
 * 
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id);
    EMMessage.Type type = forward_msg.getType();
    switch (type) {
    case TXT:
        if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
            sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(),
                    forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null));
        }else{
            // 获取消息内容,发送消息
            String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage();
            sendTextMessage(content);
        }
        break;
    case IMAGE:
        // 发送图片
        String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl();
        if (filePath != null) {
            File file = new File(filePath);
            if (!file.exists()) {
                // 不存在大图发送缩略图
                filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath();
            }
            sendImageMessage(filePath);
        }
        break;
    default:
        break;
    }
    
    if(forward_msg.getChatType() == ChatType.ChatRoom){
        EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example 6
Source File: EaseChatRowVoicePlayClickListener.java    From Social with Apache License 2.0 5 votes vote down vote up
public EaseChatRowVoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity context) {
	this.message = message;
	voiceBody = (EMVoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = context;
	this.chatType = message.getChatType();
}
 
Example 7
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);
            }
        }
    }
}
 
Example 8
Source File: EaseChatFragment.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
/**
 * forward message
 * 
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id);
    EMMessage.Type type = forward_msg.getType();
    switch (type) {
    case TXT:
        if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
            sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(),
                    forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null));
        }else{
            // get the content and send it
            String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage();
            sendTextMessage(content);
        }
        break;
    case IMAGE:
        // send image
        String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl();
        if (filePath != null) {
            File file = new File(filePath);
            if (!file.exists()) {
                // send thumb nail if original image does not exist
                filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath();
            }
            sendImageMessage(filePath);
        }
        break;
    default:
        break;
    }
    
    if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){
        EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example 9
Source File: EaseChatRowVoicePlayClickListener.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public EaseChatRowVoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity context) {
	this.message = message;
	voiceBody = (EMVoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = context;
	this.chatType = message.getChatType();
}
 
Example 10
Source File: EaseChatFragment.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 转发消息
 * 
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final EMMessage forward_msg = EMClient.getInstance().chatManager().getMessage(forward_msg_id);
    EMMessage.Type type = forward_msg.getType();
    switch (type) {
    case TXT:
        if(forward_msg.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)){
            sendBigExpressionMessage(((EMTextMessageBody) forward_msg.getBody()).getMessage(),
                    forward_msg.getStringAttribute(EaseConstant.MESSAGE_ATTR_EXPRESSION_ID, null));
        }else{
            // 获取消息内容,发送消息
            String content = ((EMTextMessageBody) forward_msg.getBody()).getMessage();
            sendTextMessage(content);
        }
        break;
    case IMAGE:
        // 发送图片
        String filePath = ((EMImageMessageBody) forward_msg.getBody()).getLocalUrl();
        if (filePath != null) {
            File file = new File(filePath);
            if (!file.exists()) {
                // 不存在大图发送缩略图
                filePath = ((EMImageMessageBody) forward_msg.getBody()).thumbnailLocalPath();
            }
            sendImageMessage(filePath);
        }
        break;
    default:
        break;
    }
    
    if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){
        EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example 11
Source File: EaseChatRowVoicePlayClickListener.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
public EaseChatRowVoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity context) {
	this.message = message;
	voiceBody = (EMVoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = context;
	this.chatType = message.getChatType();
}
 
Example 12
Source File: HxChatBaseItemView.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
protected void setUserData(RcvHolder holder, EMMessage emMessage, final int position)
{
    if (emMessage.direct() == EMMessage.Direct.RECEIVE)
    {
        //设置头像
        if (mUserBean != null && StringUtil.isNotEmpty(mUserBean.getLocalHead()))
            CommonUtils.getInstance()
                    .getImageDisplayer()
                    .display(mContext, (ImageView) holder.findView(R.id.img_chat_listitem_head),
                            mUserBean.getLocalHead(), 150, 150, R.drawable.default_avatar, R.drawable.default_avatar);
        else
            holder.setImgResource(R.id.img_chat_listitem_head, R.drawable.default_avatar);
        //设置名字
        //单聊不显示名字
        if (emMessage.getChatType() == EMMessage.ChatType.Chat)
        {
            holder.setVisibility(R.id.tv_chat_listitem_name, View.GONE);
        } else
        {
            holder.setVisibility(R.id.tv_chat_listitem_name, View.VISIBLE);
            if (mUserBean != null)
                holder.setTvText(R.id.tv_chat_listitem_name, mUserBean.getDisplayName());
            else
                holder.setTvText(R.id.tv_chat_listitem_name, emMessage.getUserName());
        }
    } else
    {
        //本方头像为默认头像
        holder.setImgResource(R.id.img_chat_listitem_head, R.drawable.default_avatar);
        //不显示名字
        holder.setVisibility(R.id.tv_chat_listitem_name, View.GONE);
    }
}
 
Example 13
Source File: MyEaseChatFragment.java    From Social with Apache License 2.0 4 votes vote down vote up
@Override
public void onMessageReceived(List<EMMessage> messages) {
    Log.d("MyEaseChatFragmetn", "新消息!!!!!!!!!");
    for (EMMessage message : messages) {
        String username = null;
        // 群组消息
        if (message.getChatType() == EMMessage.ChatType.GroupChat || message.getChatType() == EMMessage.ChatType.ChatRoom) {
            username = message.getTo();
        } else {
            // 单聊消息
            username = message.getFrom();
        }

        // 如果是当前会话的消息,刷新聊天页面
        Log.d("MyEaseChatFragment", "username = "  + username + "\n" + "tochatUser = "+ toChatUsername);
        if (username.equals(toChatUsername)) {
            messageList.refreshSelectLast();
        } else {
            // 如果消息不是和当前聊天ID的消息
            NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext());
            builder.setTicker("新消息");
            builder.setContentTitle(SharedPreferenceUtil.getUserNickname(message.getUserName()));
            builder.setContentText("发来消息,请查看");
            builder.setSmallIcon(R.mipmap.logo);
            builder.setLights(0xff00ff00, 300, 1000);
            //默认系统设置
            builder.setDefaults(NotificationCompat.DEFAULT_ALL);

            //builder.setContentInfo("This is content info");
            builder.setAutoCancel(true);
            Intent intent = new Intent(getContext(), ChatActivity.class);
            intent.putExtra("friend_id", messages.get(0).getUserName());
            PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            builder.setContentIntent(pendingIntent);
            NotificationManager notificationManager = (NotificationManager)getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(4, builder.build());

            //EaseUI.getInstance().getNotifier().viberateAndPlayTone(messages.get(0));
            //应用在后台,通知栏提示新消息
            if(!EaseUI.getInstance().hasForegroundActivies()){
            }

        }
    }
}