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);
}
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;
}
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);
}
}
}
}
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;
}
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) {
}
}
Aggregations