Search in sources :

Example 6 with EMMessage

use of com.hyphenate.chat.EMMessage in project SmartCampus by Vegen.

the class EaseChatFragment method onMessageReceived.

// implement methods in EMMessageListener
@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) || message.conversationId().equals(toChatUsername)) {
            messageList.refreshSelectLast();
            EaseUI.getInstance().getNotifier().vibrateAndPlayTone(message);
            conversation.markMessageAsRead(message.getMsgId());
        } else {
            EaseUI.getInstance().getNotifier().onNewMsg(message);
        }
    }
}
Also used : EMMessage(com.hyphenate.chat.EMMessage)

Example 7 with EMMessage

use of com.hyphenate.chat.EMMessage in project SmartCampus by Vegen.

the class EaseChatFragment method sendAtMessage.

/**
 * send @ message, only support group chat message
 * @param content
 */
@SuppressWarnings("ConstantConditions")
private void sendAtMessage(String content) {
    if (chatType != EaseConstant.CHATTYPE_GROUP) {
        EMLog.e(TAG, "only support group chat message");
        return;
    }
    EMMessage message = EMMessage.createTxtSendMessage(content, toChatUsername);
    EMGroup group = EMClient.getInstance().groupManager().getGroup(toChatUsername);
    if (EMClient.getInstance().getCurrentUser().equals(group.getOwner()) && EaseAtMessageHelper.get().containsAtAll(content)) {
        message.setAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG, EaseConstant.MESSAGE_ATTR_VALUE_AT_MSG_ALL);
    } else {
        message.setAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG, EaseAtMessageHelper.get().atListToJsonArray(EaseAtMessageHelper.get().getAtMessageUsernames(content)));
    }
    sendMessage(message);
}
Also used : EMGroup(com.hyphenate.chat.EMGroup) EMMessage(com.hyphenate.chat.EMMessage)

Example 8 with EMMessage

use of com.hyphenate.chat.EMMessage in project SmartCampus by Vegen.

the class EaseChatFragment method sendFileMessage.

protected void sendFileMessage(String filePath) {
    EMMessage message = EMMessage.createFileSendMessage(filePath, toChatUsername);
    sendMessage(message);
}
Also used : EMMessage(com.hyphenate.chat.EMMessage)

Example 9 with EMMessage

use of com.hyphenate.chat.EMMessage in project SmartCampus by Vegen.

the class EaseChatFragment method forwardMessage.

/**
 * 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() == ChatType.ChatRoom) {
        EMClient.getInstance().chatroomManager().leaveChatRoom(forward_msg.getTo());
    }
}
Also used : EMImageMessageBody(com.hyphenate.chat.EMImageMessageBody) EMTextMessageBody(com.hyphenate.chat.EMTextMessageBody) File(java.io.File) EMMessage(com.hyphenate.chat.EMMessage)

Example 10 with EMMessage

use of com.hyphenate.chat.EMMessage in project SmartCampus by Vegen.

the class EaseChatFragment method sendTextMessage.

// send message
protected void sendTextMessage(String content) {
    if (EaseAtMessageHelper.get().containsAtUsername(content)) {
        sendAtMessage(content);
    } else {
        EMMessage message = EMMessage.createTxtSendMessage(content, toChatUsername);
        sendMessage(message);
    }
}
Also used : EMMessage(com.hyphenate.chat.EMMessage)

Aggregations

EMMessage (com.hyphenate.chat.EMMessage)24 File (java.io.File)4 EMCallBack (com.hyphenate.EMCallBack)3 SuppressLint (android.annotation.SuppressLint)2 EMCmdMessageBody (com.hyphenate.chat.EMCmdMessageBody)2 EMGroup (com.hyphenate.chat.EMGroup)2 EMTextMessageBody (com.hyphenate.chat.EMTextMessageBody)2 EMAMessage (com.hyphenate.chat.adapter.message.EMAMessage)2 EaseAvatarOptions (com.hyphenate.easeui.domain.EaseAvatarOptions)2 EaseImageView (com.hyphenate.easeui.widget.EaseImageView)2 Date (java.util.Date)2 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 DisplayMetrics (android.util.DisplayMetrics)1 TextView (android.widget.TextView)1 EMChatRoom (com.hyphenate.chat.EMChatRoom)1 EMConversation (com.hyphenate.chat.EMConversation)1 EMFileMessageBody (com.hyphenate.chat.EMFileMessageBody)1 EMImageMessageBody (com.hyphenate.chat.EMImageMessageBody)1 EMVideoMessageBody (com.hyphenate.chat.EMVideoMessageBody)1