Search in sources :

Example 11 with EMMessage

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

the class EaseChatRowPresenter method handleSendMessage.

protected void handleSendMessage(final EMMessage message) {
    EMMessage.Status status = message.status();
    // Update the view according to the message current status.
    getChatRow().updateView(message);
    if (status == EMMessage.Status.SUCCESS || status == EMMessage.Status.FAIL) {
        return;
    }
    message.setMessageStatusCallback(new EMCallBack() {

        @Override
        public void onSuccess() {
            getChatRow().updateView(message);
        }

        @Override
        public void onError(int code, String error) {
            Log.i("EaseChatRowPresenter", "onError: " + code + ", error: " + error);
            getChatRow().updateView(message);
        }

        @Override
        public void onProgress(int progress, String status) {
            getChatRow().updateView(message);
        }
    });
    // Already in progress, do not send again
    if (status == EMMessage.Status.INPROGRESS) {
        return;
    }
    // Send the message
    EMClient.getInstance().chatManager().sendMessage(message);
}
Also used : EMCallBack(com.hyphenate.EMCallBack) EMMessage(com.hyphenate.chat.EMMessage)

Example 12 with EMMessage

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

the class EaseMessageAdapter method getView.

@SuppressLint("NewApi")
public View getView(final int position, View convertView, ViewGroup parent) {
    EMMessage message = getItem(position);
    EaseChatRowPresenter presenter = null;
    if (convertView == null) {
        presenter = createChatRowPresenter(message, position);
        convertView = presenter.createChatRow(context, message, position, this);
        convertView.setTag(presenter);
    } else {
        presenter = (EaseChatRowPresenter) convertView.getTag();
    }
    presenter.setup(message, position, itemClickListener, itemStyle);
    return convertView;
}
Also used : EaseChatRowPresenter(com.hyphenate.easeui.widget.presenter.EaseChatRowPresenter) EMMessage(com.hyphenate.chat.EMMessage) SuppressLint(android.annotation.SuppressLint)

Example 13 with EMMessage

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

the class EaseAtMessageHelper method parseMessages.

/**
 * 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);
            }
        }
    }
}
Also used : JSONArray(org.json.JSONArray) EMMessage(com.hyphenate.chat.EMMessage)

Example 14 with EMMessage

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

the class EaseDingMessageHelper method createDingMessage.

/**
 * Create a ding-type message.
 */
public EMMessage createDingMessage(String to, String content) {
    EMMessage message = EMMessage.createTxtSendMessage(content, to);
    message.setAttribute(KEY_DING, true);
    return message;
}
Also used : EMMessage(com.hyphenate.chat.EMMessage)

Example 15 with EMMessage

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

the class EaseDingMessageHelper method sendAckMessage.

public void sendAckMessage(EMMessage message) {
    if (!validateMessage(message)) {
        return;
    }
    if (message.isAcked()) {
        return;
    }
    // May a user login from multiple devices, so do not need to send the ack msg.
    if (EMClient.getInstance().getCurrentUser().equalsIgnoreCase(message.getFrom())) {
        return;
    }
    try {
        // cmd-type message will not store in native database.
        EMMessage msg = EMMessage.createSendMessage(EMMessage.Type.CMD);
        msg.setTo(message.getFrom());
        msg.setAttribute(KEY_CONVERSATION_ID, message.getTo());
        msg.setAttribute(KEY_DING_ACK, true);
        msg.addBody(new EMCmdMessageBody(message.getMsgId()));
        EMClient.getInstance().chatManager().sendMessage(msg);
        message.setAcked(true);
        EMLog.i(TAG, "Send the group ack cmd-type message.");
    } catch (Exception e) {
    }
}
Also used : EMCmdMessageBody(com.hyphenate.chat.EMCmdMessageBody) HyphenateException(com.hyphenate.exceptions.HyphenateException) 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