hyphenate_SDK3.0
3.8.6.1
hyphenate java IM SDK
|
Public Member Functions | |
void | sendMessage (final EMMessage msg) |
void | ackConversationRead (String conversationId) throws HyphenateException |
void | ackMessageRead (String to, String messageId) throws HyphenateException |
void | ackGroupMessageRead (String to, String messageId, String ext) throws HyphenateException |
void | recallMessage (EMMessage message) throws HyphenateException |
void | aysncRecallMessage (final EMMessage message, final EMCallBack callback) |
EMMessage | getMessage (String messageId) |
EMConversation | getConversation (String id) |
EMConversation | getConversation (String id, EMConversationType type) |
EMConversation | getConversation (String username, EMConversationType type, boolean createIfNotExists) |
void | markAllConversationsAsRead () |
int | getUnreadMsgsCount () |
int | getUnreadMessageCount () |
void | saveMessage (EMMessage message) |
boolean | updateMessage (EMMessage message) |
void | downloadAttachment (final EMMessage msg) |
void | downloadThumbnail (final EMMessage msg) |
synchronized void | importMessages (List< EMMessage > msgs) |
List< EMConversation > | getConversationsByType (EMConversationType type) |
void | downloadFile (final String remoteUrl, final String localFilePath, final Map< String, String > headers, final EMCallBack callback) |
Map< String, EMConversation > | getAllConversations () |
Map< String, EMConversation > | fetchConversationsFromServer () throws HyphenateException |
void | asyncFetchConversationsFromServer (final EMValueCallBack< Map< String, EMConversation >> callBack) |
void | loadAllConversations () |
boolean | deleteConversation (String username, boolean deleteMessages) |
void | addMessageListener (EMMessageListener listener) |
void | removeMessageListener (EMMessageListener listener) |
void | addConversationListener (EMConversationListener listener) |
void | removeConversationListener (EMConversationListener listener) |
void | setMessageListened (EMMessage message) |
void | setVoiceMessageListened (EMMessage message) |
boolean | updateParticipant (String from, String changeTo) |
EMCursorResult< EMGroupReadAck > | fetchGroupReadAcks (String msgId, int pageSize, String startAckId) throws HyphenateException |
void | asyncFetchGroupReadAcks (final String msgId, final int pageSize, final String startAckId, final EMValueCallBack< EMCursorResult< EMGroupReadAck >> callBack) |
EMCursorResult< EMMessage > | fetchHistoryMessages (String conversationId, EMConversationType type, int pageSize, String startMsgId) throws HyphenateException |
void | asyncFetchHistoryMessage (final String conversationId, final EMConversationType type, final int pageSize, final String startMsgId, final EMValueCallBack< EMCursorResult< EMMessage >> callBack) |
List< EMMessage > | searchMsgFromDB (EMMessage.Type type, long timeStamp, int maxCount, String from, EMConversation.EMSearchDirection direction) |
List< EMMessage > | searchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMConversation.EMSearchDirection direction) |
Protected Member Functions | |
EMChatManager (EMClient client, EMAChatManager manager) | |
Chat manager, responsible for managing conversations (such as: load, delete), sending messages, downloading attachments and so on Such as, send a text message:
EMMessage message = EMMessage.createTxtSendMessage(content, toChatUsername); EMClient.getInstance().chatManager().sendMessage(message);
void com.hyphenate.chat.EMChatManager.ackConversationRead | ( | String | conversationId | ) | throws HyphenateException |
Send read conversation ack to server, only for single chat conversation Send it will inform the sever set the conversation reading to 0, and conversationist (with multiple devices) will receive a callback method EMConversationListener#onConversationRead(String, String)
Send group message ack to sever, see ackGroupMessageRead(String, String, String)
Suggestion: the method can be called when enter the chat page, other session can call the method of ackMessageRead(String, String) , can reduce the number of call to ackMessageRead(String, String) when there are a large number of unread messages
conversationId | Conversation id |
HyphenateException | Maybe throws exception EMError#USER_NOT_LOGIN, EMError#SERVER_NOT_REACHABLE, EMError#MESSAGE_INVALID and so on, see EMError |
void com.hyphenate.chat.EMChatManager.ackGroupMessageRead | ( | String | to, |
String | messageId, | ||
String | ext | ||
) | throws HyphenateException |
Send group message ack to server Precondition: set EMOptions#setRequireAck(boolean) and EMMessage#setIsNeedGroupAck(boolean)
Send single chat message ack to server, see ackMessageRead(String, String); Send conversation ack to server, see ackConversationRead(String)
void com.hyphenate.chat.EMChatManager.ackMessageRead | ( | String | to, |
String | messageId | ||
) | throws HyphenateException |
Send read ack to server, only for single chat Precondition: set EMOptions#setRequireAck(boolean)
Send group message ack to sever, see ackGroupMessageRead(String, String, String)
Suggestion: calls ackConversationRead(String) on entering a chat page, then calls the current method in other scenarios, can reduce the times this method is called.
to | the recipient id |
messageId | message id |
HyphenateException |
void com.hyphenate.chat.EMChatManager.addConversationListener | ( | EMConversationListener | listener | ) |
Add conversation listener
listener | The conversation listener will to be set, see EMConversationListener |
void com.hyphenate.chat.EMChatManager.addMessageListener | ( | EMMessageListener | listener | ) |
Add message listener Receives new messages and so on can set the method to listen, see EMMessageListener
listener | The message listener which is used to listen the incoming messages, see EMMessageListener |
void com.hyphenate.chat.EMChatManager.asyncFetchConversationsFromServer | ( | final EMValueCallBack< Map< String, EMConversation >> | callBack | ) |
Fetch conversations from server Default maximum return is 100.
Asynchronously method
void com.hyphenate.chat.EMChatManager.asyncFetchGroupReadAcks | ( | final String | msgId, |
final int | pageSize, | ||
final String | startAckId, | ||
final EMValueCallBack< EMCursorResult< EMGroupReadAck >> | callBack | ||
) |
Fetch ack details for group messages from server Fetch by page Send group ack, see ackConversationRead(String)
Asynchronously method
msgId | The message id which need fetch receipt |
pageSize | The page size per time fetch group message receipt |
startAckId | The start id for fetch acks, can be null, if null start from the server lastest ack. |
callBack | Result callback, success execute the method EMValueCallBack#onSuccess(Object), failure execute the method EMValueCallBack#onError(int, String) |
void com.hyphenate.chat.EMChatManager.asyncFetchHistoryMessage | ( | final String | conversationId, |
final EMConversationType | type, | ||
final int | pageSize, | ||
final String | startMsgId, | ||
final EMValueCallBack< EMCursorResult< EMMessage >> | callBack | ||
) |
Fetch conversation roam messages from server Fetch by page
Asynchronously method
conversationId | The conversation id which select to fetch roam message. |
type | The conversation type which select to fetch roam message. |
pageSize | Number fetched per time |
startMsgId | The start search roam message, if empty start from the server lastest message. |
callBack | Result callback, success execute the method EMValueCallBack#onSuccess(Object), return messages from server and cursor for next fetch action; failue execute the method EMValueCallBack#onError(int, String) |
void com.hyphenate.chat.EMChatManager.aysncRecallMessage | ( | final EMMessage | message, |
final EMCallBack | callback | ||
) |
Recall the sent message
Asynchronously method
message | Message object |
callback | Send callback, see EMCallBack |
boolean com.hyphenate.chat.EMChatManager.deleteConversation | ( | String | username, |
boolean | deleteMessages | ||
) |
Delete conversation and messages from local database If set true for deleteMessages, delete the local chat history when delete the conversation
username | Conversation ID |
deleteMessages | Whether delete chat history when delete conversation |
void com.hyphenate.chat.EMChatManager.downloadAttachment | ( | final EMMessage | msg | ) |
Download the message attachment Call the method if the attachment download fails
msg | Message to be download the attachment |
void com.hyphenate.chat.EMChatManager.downloadFile | ( | final String | remoteUrl, |
final String | localFilePath, | ||
final Map< String, String > | headers, | ||
final EMCallBack | callback | ||
) |
Download the file from server
remoteUrl | The remote file url |
localFilePath | The local file path |
headers | Http Request Headers |
callback | Download status callback, see EMCallBack |
void com.hyphenate.chat.EMChatManager.downloadThumbnail | ( | final EMMessage | msg | ) |
Download the thumbnail if not downloaded before or downloaded failed
msg | The message to be downloaded thumbnail |
Map<String, EMConversation> com.hyphenate.chat.EMChatManager.fetchConversationsFromServer | ( | ) | throws HyphenateException |
Fetch conversations from server, Default maximum return is 100.
Synchronization method will block the current thread
EMCursorResult<EMGroupReadAck> com.hyphenate.chat.EMChatManager.fetchGroupReadAcks | ( | String | msgId, |
int | pageSize, | ||
String | startAckId | ||
) | throws HyphenateException |
Fetch ack details for group messages from server. Fetch by page Send group ack, see ackConversationRead(String)
Synchronization method will block the current thread
msgId | The message id which need fetch receipt |
pageSize | The page size per time fetch group message receipt |
startAckId | The start id for fetch acks, can be null, if null start from the server lastest ack. |
HyphenateException | Error code see EMError |
EMCursorResult<EMMessage> com.hyphenate.chat.EMChatManager.fetchHistoryMessages | ( | String | conversationId, |
EMConversationType | type, | ||
int | pageSize, | ||
String | startMsgId | ||
) | throws HyphenateException |
Fetch conversation roam messages from server Fetch by page
Synchronization method will block the current thread
conversationId | The conversation id which select to fetch roam message |
type | The conversation type which select to fetch roam message, see EMConversationType |
pageSize | Number fetched per time |
startMsgId | The start search roam message, if empty start from the server lastest message. |
HyphenateException | Error code see EMError |
Map<String, EMConversation> com.hyphenate.chat.EMChatManager.getAllConversations | ( | ) |
Get all conversations from local Load from memory first, if not then load from local database
EMConversation com.hyphenate.chat.EMChatManager.getConversation | ( | String | id | ) |
Get conversation object by the specified ID Return null if not find
id | Conversation ID |
EMConversation com.hyphenate.chat.EMChatManager.getConversation | ( | String | id, |
EMConversationType | type | ||
) |
Get conversation by conversation id and conversation type Return null if not find
id | Conversation ID |
type | The conversation type, see EMConversationType |
EMConversation com.hyphenate.chat.EMChatManager.getConversation | ( | String | username, |
EMConversationType | type, | ||
boolean | createIfNotExists | ||
) |
Get conversation object by conversation id and conversation type If not find, either a new object or an empty object is returned based on the value of CreateIFNotExists
username | Conversation ID |
type | The conversation type, see EMConversationType |
createIfNotExists | Whether Create conversation by the value if not find |
List<EMConversation> com.hyphenate.chat.EMChatManager.getConversationsByType | ( | EMConversationType | type | ) |
Get list of conversations by conversation type
type | The conversation type, see EMConversationType |
EMMessage com.hyphenate.chat.EMChatManager.getMessage | ( | String | messageId | ) |
get message through message id
messageId | message id |
int com.hyphenate.chat.EMChatManager.getUnreadMessageCount | ( | ) |
Get unread message count
int com.hyphenate.chat.EMChatManager.getUnreadMsgsCount | ( | ) |
Get unread message count
synchronized void com.hyphenate.chat.EMChatManager.importMessages | ( | List< EMMessage > | msgs | ) |
Import messages to local database. Make sure the message's sender or receiver is current user Recommend import up to 1000 messages per operation
msgs | The message list of be imported |
void com.hyphenate.chat.EMChatManager.loadAllConversations | ( | ) |
Load all conversations from local database into memory Generally used after a successful login to speed up the loading of the conversation list
void com.hyphenate.chat.EMChatManager.markAllConversationsAsRead | ( | ) |
mark all messages as read For local conversations
void com.hyphenate.chat.EMChatManager.recallMessage | ( | EMMessage | message | ) | throws HyphenateException |
Recall the sent message
Synchronization method block the current thread
message | Message object |
HyphenateException | See EMError |
void com.hyphenate.chat.EMChatManager.removeConversationListener | ( | EMConversationListener | listener | ) |
Remove the conversation listener After set addConversationListener(EMConversationListener) need to remove the listener by calls this method
listener | the conversation listener set before |
void com.hyphenate.chat.EMChatManager.removeMessageListener | ( | EMMessageListener | listener | ) |
Remove the message listener After set addMessageListener(EMMessageListener) should calls this method
listener | The message listener set before need to remove |
void com.hyphenate.chat.EMChatManager.saveMessage | ( | EMMessage | message | ) |
Save the message to memory and local database CMD type message not be stored in database
message | The emssage to store |
List<EMMessage> com.hyphenate.chat.EMChatManager.searchMsgFromDB | ( | EMMessage.Type | type, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
EMConversation.EMSearchDirection | direction | ||
) |
Search message from database according the parameters Note: Cautious about memory usage when the maxCount is large, currently the limited number of search data is 400 at a time
type | Message type, TXT、VOICE、IMAGE and so on, see EMMessage.Type |
timeStamp | The timestamp for search |
maxCount | The max number of message to search |
from | A user id or a group id searches for messages, usually refers to the conversation ID |
List<EMMessage> com.hyphenate.chat.EMChatManager.searchMsgFromDB | ( | String | keywords, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
EMConversation.EMSearchDirection | direction | ||
) |
Search message from database based the parameters Note: Cautious about memory usage when the maxCount is large, currently the limited number of search data is 400 at a time
keywords | The keywords in message. |
timeStamp | The timestamp for search |
maxCount | The max number of message to search |
from | A user id or a group id searches for messages, usually refers to the conversation ID |
void com.hyphenate.chat.EMChatManager.sendMessage | ( | final EMMessage | msg | ) |
Send message If is voice, picture and other message with attachment, SDK will automatically upload the attachment Can set whether upload to chat sever by EMOptions#setAutoTransferMessageAttachments(boolean), the default value is true The send message status, can set listener by EMMessage#setMessageStatusCallback(EMCallBack), we should set it before the method of sendMessage(), otherwise the listener may be recycled by the system
msg | Message object to be sent, not be null |
void com.hyphenate.chat.EMChatManager.setMessageListened | ( | EMMessage | message | ) |
Set message to listened, used for voice message
message | The message object to set |
void com.hyphenate.chat.EMChatManager.setVoiceMessageListened | ( | EMMessage | message | ) |
Set message to listened, used for voice message
message | The message object to set |
boolean com.hyphenate.chat.EMChatManager.updateMessage | ( | EMMessage | message | ) |
Update the local message Update the memory and local database
message | The message objec to update |
boolean com.hyphenate.chat.EMChatManager.updateParticipant | ( | String | from, |
String | changeTo | ||
) |
Update database records, change username 'from' to 'changeTo', take effect on message table, conversation table, contacts, blacklist table Note: this operation does not update data stored in memory cache.
from | The userId before replace |
changeTo | The userId after replace |