hyphenate_SDK3.0  3.8.6.1
hyphenate java IM SDK
Public Member Functions | Protected Member Functions | List of all members
com.hyphenate.chat.EMChatManager Class Reference

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< EMConversationgetConversationsByType (EMConversationType type)
 
void downloadFile (final String remoteUrl, final String localFilePath, final Map< String, String > headers, final EMCallBack callback)
 
Map< String, EMConversationgetAllConversations ()
 
Map< String, EMConversationfetchConversationsFromServer () 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< EMGroupReadAckfetchGroupReadAcks (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< EMMessagefetchHistoryMessages (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< EMMessagesearchMsgFromDB (EMMessage.Type type, long timeStamp, int maxCount, String from, EMConversation.EMSearchDirection direction)
 
List< EMMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMConversation.EMSearchDirection direction)
 

Protected Member Functions

 EMChatManager (EMClient client, EMAChatManager manager)
 

Detailed Description

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);

Member Function Documentation

◆ ackConversationRead()

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

Parameters
conversationIdConversation id
Exceptions
HyphenateExceptionMaybe throws exception EMError#USER_NOT_LOGIN, EMError#SERVER_NOT_REACHABLE, EMError#MESSAGE_INVALID and so on, see EMError

◆ ackGroupMessageRead()

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)

◆ ackMessageRead()

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.

Parameters
tothe recipient id
messageIdmessage id
Exceptions
HyphenateException

◆ addConversationListener()

void com.hyphenate.chat.EMChatManager.addConversationListener ( EMConversationListener  listener)

Add conversation listener

See also
EMConversationListener Use to listen the change of conversation and listen the conversation ack message, see EMConversationListener If has set this method need to remove the conversation listener by calls the method of removeConversationListener(EMConversationListener)
Parameters
listenerThe conversation listener will to be set, see EMConversationListener

◆ addMessageListener()

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

See also
EMMessageListener
Parameters
listenerThe message listener which is used to listen the incoming messages, see EMMessageListener

◆ asyncFetchConversationsFromServer()

void com.hyphenate.chat.EMChatManager.asyncFetchConversationsFromServer ( final EMValueCallBack< Map< String, EMConversation >>  callBack)

Fetch conversations from server Default maximum return is 100.

Asynchronously method

Returns
Return the conversation list of current user

◆ asyncFetchGroupReadAcks()

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

Parameters
msgIdThe message id which need fetch receipt
pageSizeThe page size per time fetch group message receipt
startAckIdThe start id for fetch acks, can be null, if null start from the server lastest ack.
callBackResult callback, success execute the method EMValueCallBack#onSuccess(Object), failure execute the method EMValueCallBack#onError(int, String)

◆ asyncFetchHistoryMessage()

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

Parameters
conversationIdThe conversation id which select to fetch roam message.
typeThe conversation type which select to fetch roam message.
pageSizeNumber fetched per time
startMsgIdThe start search roam message, if empty start from the server lastest message.
callBackResult 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)

◆ aysncRecallMessage()

void com.hyphenate.chat.EMChatManager.aysncRecallMessage ( final EMMessage  message,
final EMCallBack  callback 
)

Recall the sent message

Asynchronously method

Parameters
messageMessage object
callbackSend callback, see EMCallBack

◆ deleteConversation()

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

Parameters
usernameConversation ID
deleteMessagesWhether delete chat history when delete conversation
Returns
The result of delete conversation. True means success, false means failure

◆ downloadAttachment()

void com.hyphenate.chat.EMChatManager.downloadAttachment ( final EMMessage  msg)

Download the message attachment Call the method if the attachment download fails

Parameters
msgMessage to be download the attachment

◆ downloadFile()

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

Parameters
remoteUrlThe remote file url
localFilePathThe local file path
headersHttp Request Headers
callbackDownload status callback, see EMCallBack
Deprecated:
Use downloadAttachment(EMMessage) instead

◆ downloadThumbnail()

void com.hyphenate.chat.EMChatManager.downloadThumbnail ( final EMMessage  msg)

Download the thumbnail if not downloaded before or downloaded failed

Parameters
msgThe message to be downloaded thumbnail

◆ fetchConversationsFromServer()

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

Returns
Return the conversation list of current user

◆ fetchGroupReadAcks()

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

Parameters
msgIdThe message id which need fetch receipt
pageSizeThe page size per time fetch group message receipt
startAckIdThe start id for fetch acks, can be null, if null start from the server lastest ack.
Returns
The list returned ack from server and cursor for next fetch action.
Exceptions
HyphenateExceptionError code see EMError

◆ fetchHistoryMessages()

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

Parameters
conversationIdThe conversation id which select to fetch roam message
typeThe conversation type which select to fetch roam message, see EMConversationType
pageSizeNumber fetched per time
startMsgIdThe start search roam message, if empty start from the server lastest message.
Returns
Server return messages and cursor for next fetch action.
Exceptions
HyphenateExceptionError code see EMError

◆ getAllConversations()

Map<String, EMConversation> com.hyphenate.chat.EMChatManager.getAllConversations ( )

Get all conversations from local Load from memory first, if not then load from local database

Returns
Return the map of conversations from memory or local database

◆ getConversation() [1/3]

EMConversation com.hyphenate.chat.EMChatManager.getConversation ( String  id)

Get conversation object by the specified ID Return null if not find

Parameters
idConversation ID
Returns
The existing conversation found by conversation ID, null if not found

◆ getConversation() [2/3]

EMConversation com.hyphenate.chat.EMChatManager.getConversation ( String  id,
EMConversationType  type 
)

Get conversation by conversation id and conversation type Return null if not find

Parameters
idConversation ID
typeThe conversation type, see EMConversationType
Returns
The conversation object found according to the id and type, null if not found

◆ getConversation() [3/3]

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

Parameters
usernameConversation ID
typeThe conversation type, see EMConversationType
createIfNotExistsWhether Create conversation by the value if not find
Returns
The conversation object found according to the id and type, null if not found

◆ getConversationsByType()

List<EMConversation> com.hyphenate.chat.EMChatManager.getConversationsByType ( EMConversationType  type)

Get list of conversations by conversation type

Parameters
typeThe conversation type, see EMConversationType
Returns
List of conversation in specified type

◆ getMessage()

EMMessage com.hyphenate.chat.EMChatManager.getMessage ( String  messageId)

get message through message id

Parameters
messageIdmessage id
Returns
The message object obtained by the specified ID, may be null

◆ getUnreadMessageCount()

int com.hyphenate.chat.EMChatManager.getUnreadMessageCount ( )

Get unread message count

Returns
The count of unread messages

◆ getUnreadMsgsCount()

int com.hyphenate.chat.EMChatManager.getUnreadMsgsCount ( )

Get unread message count

Returns
The count of unread messages
Deprecated:
Use EMChatManager#getUnreadMessageCount() instead

◆ importMessages()

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

Parameters
msgsThe message list of be imported

◆ loadAllConversations()

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

◆ markAllConversationsAsRead()

void com.hyphenate.chat.EMChatManager.markAllConversationsAsRead ( )

mark all messages as read For local conversations

◆ recallMessage()

void com.hyphenate.chat.EMChatManager.recallMessage ( EMMessage  message) throws HyphenateException

Recall the sent message

Synchronization method block the current thread

Parameters
messageMessage object
Exceptions
HyphenateExceptionSee EMError

◆ removeConversationListener()

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

Parameters
listenerthe conversation listener set before

◆ removeMessageListener()

void com.hyphenate.chat.EMChatManager.removeMessageListener ( EMMessageListener  listener)

Remove the message listener After set addMessageListener(EMMessageListener) should calls this method

Parameters
listenerThe message listener set before need to remove

◆ saveMessage()

void com.hyphenate.chat.EMChatManager.saveMessage ( EMMessage  message)

Save the message to memory and local database CMD type message not be stored in database

Parameters
messageThe emssage to store

◆ searchMsgFromDB() [1/2]

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

Parameters
typeMessage type, TXT、VOICE、IMAGE and so on, see EMMessage.Type
timeStampThe timestamp for search
maxCountThe max number of message to search
fromA user id or a group id searches for messages, usually refers to the conversation ID
Returns
The list of searched messages

◆ searchMsgFromDB() [2/2]

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

Parameters
keywordsThe keywords in message.
timeStampThe timestamp for search
maxCountThe max number of message to search
fromA user id or a group id searches for messages, usually refers to the conversation ID
Returns
The list of searched messages

◆ sendMessage()

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

Parameters
msgMessage object to be sent, not be null

◆ setMessageListened()

void com.hyphenate.chat.EMChatManager.setMessageListened ( EMMessage  message)

Set message to listened, used for voice message

Parameters
messageThe message object to set
Deprecated:
Use EMChatManager#setVoiceMessageListened(EMMessage) instead

◆ setVoiceMessageListened()

void com.hyphenate.chat.EMChatManager.setVoiceMessageListened ( EMMessage  message)

Set message to listened, used for voice message

Parameters
messageThe message object to set

◆ updateMessage()

boolean com.hyphenate.chat.EMChatManager.updateMessage ( EMMessage  message)

Update the local message Update the memory and local database

Parameters
messageThe message objec to update

◆ updateParticipant()

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.

Parameters
fromThe userId before replace
changeToThe userId after replace
Returns
Operation result, if any update operations on those tables failed, result is false

The documentation for this class was generated from the following file: