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