agora_chat_SDK  3.8.2
agorajavachatSDK
Public Member Functions | Protected Member Functions | List of all members
io.agora.chat.ChatManager Class Reference

Public Member Functions

void sendMessage (final ChatMessage msg)
 
void ackConversationRead (String conversationId) throws ChatException
 
void ackMessageRead (String to, String messageId) throws ChatException
 
void ackGroupMessageRead (String to, String messageId, String ext) throws ChatException
 
void recallMessage (ChatMessage message) throws ChatException
 
void aysncRecallMessage (final ChatMessage message, final CallBack callback)
 
ChatMessage getMessage (String messageId)
 
Conversation getConversation (String id)
 
Conversation getConversation (String id, ConversationType type)
 
Conversation getConversation (String username, ConversationType type, boolean createIfNotExists)
 
void markAllConversationsAsRead ()
 
int getUnreadMsgsCount ()
 
int getUnreadMessageCount ()
 
void saveMessage (ChatMessage message)
 
boolean updateMessage (ChatMessage message)
 
void downloadAttachment (final ChatMessage msg)
 
void downloadThumbnail (final ChatMessage msg)
 
synchronized void importMessages (List< ChatMessage > msgs)
 
List< ConversationgetConversationsByType (ConversationType type)
 
void downloadFile (final String remoteUrl, final String localFilePath, final Map< String, String > headers, final CallBack callback)
 
Map< String, ConversationgetAllConversations ()
 
Map< String, ConversationfetchConversationsFromServer () throws ChatException
 
void asyncFetchConversationsFromServer (final ValueCallBack< Map< String, Conversation >> callBack)
 
void loadAllConversations ()
 
boolean deleteConversation (String username, boolean deleteMessages)
 
void addMessageListener (MessageListener listener)
 
void removeMessageListener (MessageListener listener)
 
void addConversationListener (ConversationListener listener)
 
void removeConversationListener (ConversationListener listener)
 
void setMessageListened (ChatMessage message)
 
void setVoiceMessageListened (ChatMessage message)
 
boolean updateParticipant (String from, String changeTo)
 
CursorResult< GroupReadAckfetchGroupReadAcks (String msgId, int pageSize, String startAckId) throws ChatException
 
void asyncFetchGroupReadAcks (final String msgId, final int pageSize, final String startAckId, final ValueCallBack< CursorResult< GroupReadAck >> callBack)
 
CursorResult< ChatMessagefetchHistoryMessages (String conversationId, ConversationType type, int pageSize, String startMsgId) throws ChatException
 
void asyncFetchHistoryMessage (final String conversationId, final ConversationType type, final int pageSize, final String startMsgId, final ValueCallBack< CursorResult< ChatMessage >> callBack)
 
List< ChatMessagesearchMsgFromDB (ChatMessage.Type type, long timeStamp, int maxCount, String from, Conversation.SearchDirection direction)
 
List< ChatMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, Conversation.SearchDirection direction)
 

Protected Member Functions

 ChatManager (ChatClient 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:

    ChatMessage message = ChatMessage.createTxtSendMessage(content, toChatUsername);
    ChatClient.getInstance().chatManager().sendMessage(message);

Member Function Documentation

void io.agora.chat.ChatManager.ackConversationRead ( String  conversationId) throws ChatException

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 ConversationListener#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
ChatExceptionMaybe throws exception Error#USER_NOT_LOGIN, Error#SERVER_NOT_REACHABLE, Error#MESSAGE_INVALID and so on, see Error
void io.agora.chat.ChatManager.ackGroupMessageRead ( String  to,
String  messageId,
String  ext 
) throws ChatException

Send group message ack to server Precondition: set ChatOptions#setRequireAck(boolean) and ChatMessage#setIsNeedGroupAck(boolean)

Send single chat message ack to server, see ackMessageRead(String, String); Send conversation ack to server, see ackConversationRead(String)

void io.agora.chat.ChatManager.ackMessageRead ( String  to,
String  messageId 
) throws ChatException

Send read ack to server, only for single chat Precondition: set ChatOptions#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
ChatException
void io.agora.chat.ChatManager.addConversationListener ( ConversationListener  listener)

Add conversation listener

See also
ConversationListener Use to listen the change of conversation and listen the conversation ack message, see ConversationListener If has set this method need to remove the conversation listener by calls the method of removeConversationListener(ConversationListener)
Parameters
listenerThe conversation listener will to be set, see ConversationListener
void io.agora.chat.ChatManager.addMessageListener ( MessageListener  listener)

Add message listener Receives new messages and so on can set the method to listen, see MessageListener

See also
MessageListener
Parameters
listenerThe message listener which is used to listen the incoming messages, see MessageListener
void io.agora.chat.ChatManager.asyncFetchConversationsFromServer ( final ValueCallBack< Map< String, Conversation >>  callBack)

Fetch conversations from server Default maximum return is 100.

Asynchronously method

Returns
Return the conversation list of current user
void io.agora.chat.ChatManager.asyncFetchGroupReadAcks ( final String  msgId,
final int  pageSize,
final String  startAckId,
final ValueCallBack< CursorResult< GroupReadAck >>  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 ValueCallBack#onSuccess(Object), failure execute the method ValueCallBack#onError(int, String)
void io.agora.chat.ChatManager.asyncFetchHistoryMessage ( final String  conversationId,
final ConversationType  type,
final int  pageSize,
final String  startMsgId,
final ValueCallBack< CursorResult< ChatMessage >>  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 ValueCallBack#onSuccess(Object), return messages from server and cursor for next fetch action; failue execute the method ValueCallBack#onError(int, String)
void io.agora.chat.ChatManager.aysncRecallMessage ( final ChatMessage  message,
final CallBack  callback 
)

Recall the sent message

Asynchronously method

Parameters
messageMessage object
callbackSend callback, see CallBack
boolean io.agora.chat.ChatManager.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
void io.agora.chat.ChatManager.downloadAttachment ( final ChatMessage  msg)

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

Parameters
msgMessage to be download the attachment
void io.agora.chat.ChatManager.downloadFile ( final String  remoteUrl,
final String  localFilePath,
final Map< String, String >  headers,
final CallBack  callback 
)

Download the file from server

Parameters
remoteUrlThe remote file url
localFilePathThe local file path
headersHttp Request Headers
callbackDownload status callback, see CallBack
Deprecated:
Use downloadAttachment(ChatMessage) instead
void io.agora.chat.ChatManager.downloadThumbnail ( final ChatMessage  msg)

Download the thumbnail if not downloaded before or downloaded failed

Parameters
msgThe message to be downloaded thumbnail
Map<String, Conversation> io.agora.chat.ChatManager.fetchConversationsFromServer ( ) throws ChatException

Fetch conversations from server, Default maximum return is 100.

Synchronization method will block the current thread

Returns
Return the conversation list of current user
CursorResult<GroupReadAck> io.agora.chat.ChatManager.fetchGroupReadAcks ( String  msgId,
int  pageSize,
String  startAckId 
) throws ChatException

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
ChatExceptionError code see Error
CursorResult<ChatMessage> io.agora.chat.ChatManager.fetchHistoryMessages ( String  conversationId,
ConversationType  type,
int  pageSize,
String  startMsgId 
) throws ChatException

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 ConversationType
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
ChatExceptionError code see Error
Map<String, Conversation> io.agora.chat.ChatManager.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
Conversation io.agora.chat.ChatManager.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
Conversation io.agora.chat.ChatManager.getConversation ( String  id,
ConversationType  type 
)

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

Parameters
idConversation ID
typeThe conversation type, see ConversationType
Returns
The conversation object found according to the id and type, null if not found
Conversation io.agora.chat.ChatManager.getConversation ( String  username,
ConversationType  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 ConversationType
createIfNotExistsWhether Create conversation by the value if not find
Returns
The conversation object found according to the id and type, null if not found
List<Conversation> io.agora.chat.ChatManager.getConversationsByType ( ConversationType  type)

Get list of conversations by conversation type

Parameters
typeThe conversation type, see ConversationType
Returns
List of conversation in specified type
ChatMessage io.agora.chat.ChatManager.getMessage ( String  messageId)

get message through message id

Parameters
messageIdmessage id
Returns
The message object obtained by the specified ID, may be null
int io.agora.chat.ChatManager.getUnreadMessageCount ( )

Get unread message count

Returns
The count of unread messages
int io.agora.chat.ChatManager.getUnreadMsgsCount ( )

Get unread message count

Returns
The count of unread messages
Deprecated:
Use ChatManager#getUnreadMessageCount() instead
synchronized void io.agora.chat.ChatManager.importMessages ( List< ChatMessage 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
void io.agora.chat.ChatManager.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 io.agora.chat.ChatManager.markAllConversationsAsRead ( )

mark all messages as read For local conversations

void io.agora.chat.ChatManager.recallMessage ( ChatMessage  message) throws ChatException

Recall the sent message

Synchronization method block the current thread

Parameters
messageMessage object
Exceptions
ChatExceptionSee Error
void io.agora.chat.ChatManager.removeConversationListener ( ConversationListener  listener)

Remove the conversation listener After set addConversationListener(ConversationListener) need to remove the listener by calls this method

Parameters
listenerthe conversation listener set before
void io.agora.chat.ChatManager.removeMessageListener ( MessageListener  listener)

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

Parameters
listenerThe message listener set before need to remove
void io.agora.chat.ChatManager.saveMessage ( ChatMessage  message)

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

Parameters
messageThe emssage to store
List<ChatMessage> io.agora.chat.ChatManager.searchMsgFromDB ( ChatMessage.Type  type,
long  timeStamp,
int  maxCount,
String  from,
Conversation.SearchDirection  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 ChatMessage.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
List<ChatMessage> io.agora.chat.ChatManager.searchMsgFromDB ( String  keywords,
long  timeStamp,
int  maxCount,
String  from,
Conversation.SearchDirection  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
void io.agora.chat.ChatManager.sendMessage ( final ChatMessage  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 ChatOptions#setAutoTransferMessageAttachments(boolean), the default value is true The send message status, can set listener by ChatMessage#setMessageStatusCallback(CallBack), 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
void io.agora.chat.ChatManager.setMessageListened ( ChatMessage  message)

Set message to listened, used for voice message

Parameters
messageThe message object to set
Deprecated:
Use ChatManager#setVoiceMessageListened(ChatMessage) instead
void io.agora.chat.ChatManager.setVoiceMessageListened ( ChatMessage  message)

Set message to listened, used for voice message

Parameters
messageThe message object to set
boolean io.agora.chat.ChatManager.updateMessage ( ChatMessage  message)

Update the local message Update the memory and local database

Parameters
messageThe message objec to update
boolean io.agora.chat.ChatManager.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: