Search in sources :

Example 1 with EMTextMessageBody

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

the class EaseDingMessageHelperTest method createDingMessage.

private EMMessage createDingMessage(String conversationId, String originalMsgId) {
    EMAMessage _msg = EMAMessage.createSendMessage("", "", null, EMMessage.ChatType.Chat.ordinal());
    _msg.setTo(conversationId);
    EMMessage msg = new EMMessage(_msg);
    msg.setMsgId(originalMsgId);
    EMTextMessageBody txtBody = new EMTextMessageBody("1");
    msg.addBody(txtBody);
    msg.setAttribute(KEY_DING, true);
    msg.setChatType(EMMessage.ChatType.GroupChat);
    return msg;
}
Also used : EMTextMessageBody(com.hyphenate.chat.EMTextMessageBody) EMAMessage(com.hyphenate.chat.adapter.message.EMAMessage) EMMessage(com.hyphenate.chat.EMMessage)

Example 2 with EMTextMessageBody

use of com.hyphenate.chat.EMTextMessageBody 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 3 with EMTextMessageBody

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

the class EaseCommonUtils method getMessageDigest.

/**
 * Get digest according message type and content
 *
 * @param message
 * @param context
 * @return
 */
public static String getMessageDigest(EMMessage message, Context context) {
    String digest = "";
    switch(message.getType()) {
        case LOCATION:
            if (message.direct() == EMMessage.Direct.RECEIVE) {
                digest = getString(context, R.string.location_recv);
                digest = String.format(digest, message.getFrom());
                return digest;
            } else {
                digest = getString(context, R.string.location_prefix);
            }
            break;
        case IMAGE:
            digest = getString(context, R.string.picture);
            break;
        case VOICE:
            digest = getString(context, R.string.voice_prefix);
            break;
        case VIDEO:
            digest = getString(context, R.string.video);
            break;
        case TXT:
            EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
            if (message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_VOICE_CALL, false)) {
                digest = getString(context, R.string.voice_call) + txtBody.getMessage();
            } else if (message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) {
                digest = getString(context, R.string.video_call) + txtBody.getMessage();
            } else if (message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)) {
                if (!TextUtils.isEmpty(txtBody.getMessage())) {
                    digest = txtBody.getMessage();
                } else {
                    digest = getString(context, R.string.dynamic_expression);
                }
            } else {
                digest = txtBody.getMessage();
            }
            break;
        case FILE:
            digest = getString(context, R.string.file);
            break;
        default:
            EMLog.e(TAG, "error, unknow type");
            return "";
    }
    return digest;
}
Also used : EMTextMessageBody(com.hyphenate.chat.EMTextMessageBody)

Example 4 with EMTextMessageBody

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

the class EaseChatRowText method onSetUpView.

@Override
public void onSetUpView() {
    EMTextMessageBody txtBody = (EMTextMessageBody) message.getBody();
    Spannable span = EaseSmileUtils.getSmiledText(context, txtBody.getMessage());
    // 设置内容
    contentView.setText(span, BufferType.SPANNABLE);
}
Also used : EMTextMessageBody(com.hyphenate.chat.EMTextMessageBody) Spannable(android.text.Spannable)

Aggregations

EMTextMessageBody (com.hyphenate.chat.EMTextMessageBody)4 EMMessage (com.hyphenate.chat.EMMessage)2 Spannable (android.text.Spannable)1 EMImageMessageBody (com.hyphenate.chat.EMImageMessageBody)1 EMAMessage (com.hyphenate.chat.adapter.message.EMAMessage)1 File (java.io.File)1