Chat SDK for Android v1.2.1
agora java chat SDK
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 asyncRecallMessage (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)
 
Conversation getConversation (String username, ConversationType type, boolean createIfNotExists, boolean isChatThread)
 
void markAllConversationsAsRead ()
 
int getUnreadMessageCount ()
 
void saveMessage (ChatMessage message)
 
boolean updateMessage (ChatMessage message)
 
void asyncModifyMessage (String messageId, MessageBody messageBodyModified, final ValueCallBack< ChatMessage > callBack)
 
void downloadAttachment (final ChatMessage msg)
 
void downloadThumbnail (final ChatMessage msg)
 
void downloadAndParseCombineMessage (ChatMessage message, ValueCallBack< List< ChatMessage > > callback)
 
synchronized void importMessages (List< ChatMessage > msgs)
 
List< ConversationgetConversationsByType (ConversationType type)
 
Map< String, ConversationgetAllConversations ()
 
List< ConversationgetAllConversationsBySort ()
 
Map< String, ConversationfetchConversationsFromServer () throws ChatException
 
void asyncFetchConversationsFromServer (final ValueCallBack< Map< String, Conversation > > callBack)
 
void asyncFetchConversationsFromServer (int pageNum, int pageSize, final ValueCallBack< Map< String, Conversation > > callBack)
 
void asyncFetchPinnedConversationsFromServer (final int limit, final String cursor, final ValueCallBack< CursorResult< Conversation > > callback)
 
void asyncFetchConversationsFromServer (final int limit, final String cursor, final ValueCallBack< CursorResult< Conversation > > callback)
 
void asyncPinConversation (final String conversationId, boolean isPinned, final CallBack callback)
 
void loadAllConversations ()
 
boolean deleteConversation (String username, boolean deleteMessages)
 
void deleteConversationFromServer (String username, ConversationType type, boolean isDeleteServerMessages, CallBack deleteCallBack)
 
void addMessageListener (MessageListener listener)
 
void removeMessageListener (MessageListener listener)
 
void addConversationListener (ConversationListener listener)
 
void removeConversationListener (ConversationListener listener)
 
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
 
CursorResult< ChatMessagefetchHistoryMessages (String conversationId, ConversationType type, int pageSize, String startMsgId, Conversation.SearchDirection direction) throws ChatException
 
void asyncFetchHistoryMessage (final String conversationId, final ConversationType type, final int pageSize, final String startMsgId, final ValueCallBack< CursorResult< ChatMessage > > callBack)
 
void asyncFetchHistoryMessage (final String conversationId, final ConversationType type, final int pageSize, final String startMsgId, final Conversation.SearchDirection direction, final ValueCallBack< CursorResult< ChatMessage > > callBack)
 
void asyncFetchHistoryMessages (String conversationId, ConversationType type, int pageSize, String cursor, FetchMessageOption option, final ValueCallBack< CursorResult< ChatMessage > > callBack)
 
List< ChatMessagesearchMsgFromDB (Type type, long timeStamp, int maxCount, String from, Conversation.SearchDirection direction)
 
List< ChatMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, Conversation.SearchDirection direction)
 
void deleteMessagesBeforeTimestamp (long timeStamp, CallBack callback)
 
void asyncReportMessage (String msgId, String tag, String reportReason, CallBack callBack)
 
void reportMessage (String msgId, String tag, String reportReason) throws ChatException
 
void fetchSupportLanguages (ValueCallBack< List< Language > > callBack)
 
void translateMessage (ChatMessage message, List< String > languages, ValueCallBack< ChatMessage > callBack)
 
void addReaction (final String messageId, final String reaction) throws ChatException
 
void asyncAddReaction (final String messageId, final String reaction, final CallBack callback)
 
void removeReaction (final String messageId, final String reaction) throws ChatException
 
void asyncRemoveReaction (final String messageId, final String reaction, final CallBack callback)
 
Map< String, List< MessageReaction > > getReactionList (final List< String > messageIdList, final ChatMessage.ChatType chatType, final String groupId) throws ChatException
 
void asyncGetReactionList (final List< String > messageIdList, final ChatMessage.ChatType chatType, final String groupId, final ValueCallBack< Map< String, List< MessageReaction > > > callback)
 
CursorResult< MessageReactiongetReactionDetail (final String messageId, final String reaction, final String cursor, final int pageSize) throws ChatException
 
void asyncGetReactionDetail (final String messageId, final String reaction, final String cursor, final int pageSize, final ValueCallBack< CursorResult< MessageReaction > > callback)
 

Protected Member Functions

void removeMessagesFromServer (String conversationId, ConversationType type, List< String > msgIdList, CallBack callBack)
 
void removeMessagesFromServer (String conversationId, ConversationType type, long beforeTimeStamp, CallBack callBack)
 

Detailed Description

The chat manager class, responsible for sending and receiving messages, managing conversations (including loading and deleting conversations), and downloading attachments.

The sample code for sending a text message is as follows:

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

Member Function Documentation

◆ ackConversationRead()

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

Sends the conversation read receipt to the server.

This method is only for one-to-one chat conversations.

This method will inform the sever to set the unread message count of the conversation to 0. The message sender will receive the ConversationListener#onConversationRead(String, String) callback. The message recipient that has logged in to multiple devices, will also receive the callback.

If you want to send a read receipt for a group message, call ackGroupMessageRead(String, String, String).

Parameters
conversationIdThe conversation ID.
Exceptions
ChatExceptionThe possible exceptions are as follows: Error#USER_NOT_LOGIN, Error#SERVER_NOT_REACHABLE, and Error#MESSAGE_INVALID. See Error.

◆ ackGroupMessageRead()

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

Sends the read receipt for a group message to the server.

Note

You can only call this method after setting ChatOptions#setRequireAck(boolean) and ChatMessage#setIsNeedGroupAck(boolean) to true.

To send the read recipient for a one-to-one chat message to the server, call ackMessageRead(String, String).

To send the conversation read receipt to the server, call ackConversationRead(String).

Parameters
toThe conversation ID.
messageIdThe message ID.
extThe extension information, which is a custom keyword that specifies a custom action or command.
Exceptions
ChatExceptionA description of the exception, see Error.

◆ ackMessageRead()

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

Sends the read receipt for a message to the server.

Note

This method applies to one-to-one chats only.

This method only takes effect if you set ChatOptions#setRequireAck(boolean) as true.

To send the read receipt for a group message, call ackGroupMessageRead(String, String, String).

We recommend that you call ackConversationRead(String) when opening the chat page, and call this method in other cases to reduce the number of method calls.

Parameters
toThe message for which the read receipt is to be sent.
messageIdThe message ID.
Exceptions
ChatExceptionA description of the exception, see Error.

◆ addConversationListener()

void io.agora.chat.ChatManager.addConversationListener ( ConversationListener  listener)

Adds the conversation listener.

After a conversation listener is added, you can listen for conversation changes and conversation read receipts.

You can call the removeConversationListener(ConversationListener) method to remove the conversation listener when it is not required.

Parameters
listenerThe conversation listener to add. See ConversationListener.

◆ addMessageListener()

void io.agora.chat.ChatManager.addMessageListener ( MessageListener  listener)

Adds the message listener.

After a message listener is added, you can listen for new messages when they arrive.

You can call removeMessageListener(MessageListener) to remove the message listener when it is not required.

Parameters
listenerThe message listener to add. See MessageListener.

◆ addReaction()

void io.agora.chat.ChatManager.addReaction ( final String  messageId,
final String  reaction 
) throws ChatException

Adds a Reaction.

This is a synchronous method.

Parameters
messageIdThe message ID.
reactionThe Reaction content.
Exceptions
ChatExceptionA description of the exception. See Error.

◆ asyncAddReaction()

void io.agora.chat.ChatManager.asyncAddReaction ( final String  messageId,
final String  reaction,
final CallBack  callback 
)

Adds a Reaction.

This is an asynchronous method.

Parameters
messageIdThe message ID.
reactionThe message Reaction to add.
callbackThe result callback which contains the error information if the method fails. See CallBack.

◆ asyncFetchConversationsFromServer() [1/3]

void io.agora.chat.ChatManager.asyncFetchConversationsFromServer ( final int  limit,
final String  cursor,
final ValueCallBack< CursorResult< Conversation > >  callback 
)

Gets the list of conversations from the server with pagination.

The SDK retrieves the list of conversations in the reverse chronological order of their active time (generally the timestamp of the last message).

If there is no message in the conversation, the SDK retrieves the list of conversations in the reverse chronological order of their creation time.

Parameters
limitThe number of conversations that you expect to get on each page. The value range is [1,50].
cursorThe position from which to start to get data. If you pass in null or an empty string (""), the SDK retrieves conversations from the latest active one.
callbackThe query result CursorResult, including the cursor for getting data next time and the conversation list. For the last page, the return value of cursor is an empty string.

◆ asyncFetchConversationsFromServer() [2/3]

void io.agora.chat.ChatManager.asyncFetchConversationsFromServer ( final ValueCallBack< Map< String, Conversation > >  callBack)

Gets the conversation list from the server.

This is an asynchronous method.

Returns
The conversation list of the current user.
Deprecated:
Deprecated. Use asyncFetchConversationsFromServer(int, String, ValueCallBack) instead.

◆ asyncFetchConversationsFromServer() [3/3]

void io.agora.chat.ChatManager.asyncFetchConversationsFromServer ( int  pageNum,
int  pageSize,
final ValueCallBack< Map< String, Conversation > >  callBack 
)

Gets the conversation list from the server with pagination.

This is an asynchronous method.

Parameters
pageNumThe current page number, starting from 1.
pageSizeThe number of conversations to get on each page. The value range is [1,20].
Returns
The conversation list of the current user.
Deprecated:
Deprecated. Use asyncFetchConversationsFromServer(int, String, ValueCallBack) instead.

◆ asyncFetchGroupReadAcks()

void io.agora.chat.ChatManager.asyncFetchGroupReadAcks ( final String  msgId,
final int  pageSize,
final String  startAckId,
final ValueCallBack< CursorResult< GroupReadAck > >  callBack 
)

Uses the pagination to get read receipts for the group message from the server.

To send a read receipt for a group message, you can call ackGroupMessageRead(String, String, String).

This is an asynchronous method.

Parameters
msgIdThe message ID.
pageSizeThe number of read receipts for the group message that you expect to get on each page. The value range is [1,50].
startAckIdThe starting read receipt ID for query. After this parameter is set, the SDK retrieves read receipts, from the specified one, in the reverse chronological order of when the server receives them. If this parameter is set as null or an empty string, the SDK retrieves read receipts, from the latest one, in the reverse chronological order of when the server receives them.
callBackThe result callback:

◆ asyncFetchHistoryMessage() [1/2]

void io.agora.chat.ChatManager.asyncFetchHistoryMessage ( final String  conversationId,
final ConversationType  type,
final int  pageSize,
final String  startMsgId,
final Conversation.SearchDirection  direction,
final ValueCallBack< CursorResult< ChatMessage > >  callBack 
)

Uses the pagination to get the messages of all types in the conversation from the server according to the message search direction.

This is an asynchronous method.

Parameters
conversationIdThe conversation ID.
  • One-to-one chat: The ID of the peer user;
  • Group chat: The group ID.
typeThe conversation type. See ConversationType.
pageSizeThe number of messages that you expect to get on each page. The value range is [1,50].
startMsgIdThe starting message ID for query. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If this parameter is set as "null" or an empty string, the SDK retrieves messages according to the message search direction while ignoring this parameter.
  • If direction is set as UP, the SDK retrieves messages, starting from the latest one, in the reverse chronological order of when the server receives them.
  • If direction is set as DOWN, the SDK retrieves messages, starting from the oldest one, in the chronological order of when the server receives them.
directionThe message search direction. See Conversation.SearchDirection.
  • (Default) UP: The SDK retrieves messages in the descending order of the timestamp included in them.
    • DOWN: The SDK retrieves messages in the ascending order of the timestamp included in them.
callBackThe result callback:

◆ asyncFetchHistoryMessage() [2/2]

void io.agora.chat.ChatManager.asyncFetchHistoryMessage ( final String  conversationId,
final ConversationType  type,
final int  pageSize,
final String  startMsgId,
final ValueCallBack< CursorResult< ChatMessage > >  callBack 
)

Uses the pagination to get the messages of all types in the conversation from the server.

This is an asynchronous method.

Parameters
conversationIdThe conversation ID.
  • One-to-one chat: The ID of the peer user;
  • Group chat: The group ID.
typeThe conversation type. See ConversationType.
pageSizeThe number of messages that you expect to get on each page. The value range is [1,50].
startMsgIdThe starting message ID for query. After this parameter is set, the SDK retrieves messages, starting from the specified one, in the reverse chronological order of when the server receives them. If this parameter is set as "null" or an empty string, the SDK retrieves messages, starting from the latest one, in the reverse chronological order of when the server receives them.
callBackThe result callback:

◆ asyncFetchHistoryMessages()

void io.agora.chat.ChatManager.asyncFetchHistoryMessages ( String  conversationId,
ConversationType  type,
int  pageSize,
String  cursor,
FetchMessageOption  option,
final ValueCallBack< CursorResult< ChatMessage > >  callBack 
)

/**

Uses the pagination to get the messages in the conversation from the server according to the message pulling parameter configuration class (FetchMessageOption).

This is a asynchronous method.

Parameters
conversationIdThe conversation ID.
  • One-to-one chat: The ID of the peer user;
  • Group chat: The group ID.
typeThe conversation type. See ConversationType.
pageSizeThe number of messages you expect to get on each page. The value range is [1,50].
cursorThe cursor position from which to start querying data.
optionThe parameter configuration class for querying historical messages. See FetchMessageOption.
Returns
The list of retrieved messages and the cursor for the next query.
Parameters
callBackThe result callback:

◆ asyncFetchPinnedConversationsFromServer()

void io.agora.chat.ChatManager.asyncFetchPinnedConversationsFromServer ( final int  limit,
final String  cursor,
final ValueCallBack< CursorResult< Conversation > >  callback 
)

Get the list of pinned conversations from the server with pagination.

The SDK returns pinned conversations in the reverse chronological order of their pinning.

Parameters
limitThe number of conversations that you expect to get on each page. The value range is [1,50].
cursorThe position from which to start getting data. If you pass in null or an empty string (""), the SDK retrieves the pinned conversations from the latest pinned one.
callbackThe query result CursorResult, including the cursor for getting data next time and the list of pinned conversations. For the last page, the return value of cursor is an empty string.

◆ asyncGetReactionDetail()

void io.agora.chat.ChatManager.asyncGetReactionDetail ( final String  messageId,
final String  reaction,
final String  cursor,
final int  pageSize,
final ValueCallBack< CursorResult< MessageReaction > >  callback 
)

Gets the Reaction details.

This is an asynchronous method.

Parameters
messageIdThe message ID.
reactionThe Reaction content.
cursorThe cursor position from which to start querying data.
pageSizeThe number of Reactions you expect to get on each page.
callbackThe query result CursorResult, which contains the cursor for the next query and MessageReaction list (only the first data entry is used).

◆ asyncGetReactionList()

void io.agora.chat.ChatManager.asyncGetReactionList ( final List< String >  messageIdList,
final ChatMessage.ChatType  chatType,
final String  groupId,
final ValueCallBack< Map< String, List< MessageReaction > > >  callback 
)

Gets the list of Reactions.

This is an asynchronous method.

Parameters
messageIdListThe message ID.
chatTypeThe conversation type. Only one-to-one chats (ChatMessage.ChatType#Chat and group chats (ChatMessage.ChatType#GroupChat) are allowed.
groupIdThe group ID, which is valid only for group chats.
callbackThe Reaction list under the specified message ID. The UserList of MessageReaction indicates the summary data, which only contains the information of the first three users.

◆ asyncModifyMessage()

void io.agora.chat.ChatManager.asyncModifyMessage ( String  messageId,
MessageBody  messageBodyModified,
final ValueCallBack< ChatMessage callBack 
)

Modifies a message.

After this method is called to modify a message, both the local message and the message on the server are modified.

This method can only modify a text message in one-to-one chats or group chats, but not in chat rooms.

Upon a message modification, the callback MessageListener#onMessageContentChanged(ChatMessage, String, long) will be received by the message recipient(s) and in multi-device login scenarios.

Parameters
messageIdThe ID of the message to modify.
messageBodyModifiedThe modified message body.
callBackThe message modification callback. A object of the ValueCallBack class. See ValueCallBack,contains the message modified.

◆ asyncPinConversation()

void io.agora.chat.ChatManager.asyncPinConversation ( final String  conversationId,
boolean  isPinned,
final CallBack  callback 
)

Sets whether to pin a conversation.

Parameters
conversationIdThe conversation ID.
isPinnedWhether to pin the conversation:
  • true:Yes.
  • false: No. The conversation is unpinned.
    Parameters
    callbackThe callback for setting whether to pin the conversation.

◆ asyncRecallMessage()

void io.agora.chat.ChatManager.asyncRecallMessage ( final ChatMessage  message,
final CallBack  callback 
)

Recalls the sent message.

This is an asynchronous method.

Parameters
messageThe message object.
callbackA object of the CallBack class. See CallBack.

◆ asyncRemoveReaction()

void io.agora.chat.ChatManager.asyncRemoveReaction ( final String  messageId,
final String  reaction,
final CallBack  callback 
)

Deletes a Reaction.

This is an asynchronous method.

Parameters
messageIdThe message ID.
reactionThe Reaction to delete.
callbackThe result callback which contains the error information if the method fails. See CallBack.

◆ asyncReportMessage()

void io.agora.chat.ChatManager.asyncReportMessage ( String  msgId,
String  tag,
String  reportReason,
CallBack  callBack 
)

Reports an inappropriate message.

This is an asynchronous method.

Parameters
msgIdThe ID of the message to report.
tagThe tag of the inappropriate message. You need to type a custom tag, like porn or ad.
reportReasonThe reporting reason. You need to type a specific reason.
callBackThe result callback. See CallBack.

◆ deleteConversation()

boolean io.agora.chat.ChatManager.deleteConversation ( String  username,
boolean  deleteMessages 
)

Deletes a conversation and its local messages from the local database.

Parameters
usernameThe conversation ID.
deleteMessagesWhether to delete the historical messages with the conversation.
  • true: Yes.
  • false: No.
Returns
Whether the conversation is successfully deleted.
  • true: Yes.
  • false: No.

◆ deleteConversationFromServer()

void io.agora.chat.ChatManager.deleteConversationFromServer ( String  username,
ConversationType  type,
boolean  isDeleteServerMessages,
CallBack  deleteCallBack 
)

Deletes the specified conversation and its historical messages from the server.

This is an asynchronous method.

Parameters
usernameThe conversation ID.
typeThe conversation type. See ConversationType.
isDeleteServerMessagesWhether to delete the historical messages with the conversation.
  • true: Yes
  • false: No
deleteCallBackThe callback for the deletion of the conversation and its historical messages.
  • true: Success;
  • false: Failure.

◆ deleteMessagesBeforeTimestamp()

void io.agora.chat.ChatManager.deleteMessagesBeforeTimestamp ( long  timeStamp,
CallBack  callback 
)

Deletes local historical messages with a Unix timestamp before a specified one.

Parameters
timeStampThe starting Unix timestamp in the message for query. This unit is millisecond.
callbackThe result callback. See CallBack.

◆ downloadAndParseCombineMessage()

void io.agora.chat.ChatManager.downloadAndParseCombineMessage ( ChatMessage  message,
ValueCallBack< List< ChatMessage > >  callback 
)

Downloads and parses the attachment of the combined message.

For a combined message, this method downloads and parses the attachment and returns the message list at the first call; for subsequent calls, there are two cases: 1.If the attachment already exits, this method directly parses it and returns the message list. 2.If the attachment does not exist, this method downloads it before parsing it and returning the message list.

Parameters
messageThe combined message to download and parse.
callbackThe completion callback. If this call succeeds, calls ValueCallBack#onSuccess(Object) and returns the parsed message list; If this call fails, calls ValueCallBack#onError(int, String).

◆ downloadAttachment()

void io.agora.chat.ChatManager.downloadAttachment ( final ChatMessage  msg)

Downloads the message attachment.

You can also call this method if the attachment fails to be downloaded automatically.

Parameters
msgThe ID of the message with the attachment to be downloaded.

◆ downloadThumbnail()

void io.agora.chat.ChatManager.downloadThumbnail ( final ChatMessage  msg)

Downloads the message thumbnail.

Parameters
msgThe message with the thumbnail to be downloaded. Only the image messages and video messages have a thumbnail.

◆ fetchConversationsFromServer()

Map< String, Conversation > io.agora.chat.ChatManager.fetchConversationsFromServer ( ) throws ChatException

Gets the conversation list from the server.

You can pull 10 conversations within 7 days by default (each conversation contains the latest historical message).

This is a synchronous method and blocks the current thread.

Returns
The conversation list of the current user.
Deprecated:
Deprecated. Use asyncFetchConversationsFromServer(int, String, ValueCallBack) instead.

◆ fetchGroupReadAcks()

CursorResult< GroupReadAck > io.agora.chat.ChatManager.fetchGroupReadAcks ( String  msgId,
int  pageSize,
String  startAckId 
) throws ChatException

Uses the pagination to get read receipts for a group message from the server.

To send a read receipt for a group message, you can call ackGroupMessageRead(String, String, String).

This is a synchronous method and blocks the current thread.

Parameters
msgIdThe message ID.
pageSizeThe number of read receipts for the group message that you expect to get on each page. The value range is [1,50].
startAckIdThe starting read receipt ID for query. After this parameter is set, the SDK retrieves read receipts, from the specified one, in the reverse chronological order of when the server receives them. If this parameter is set as null or an empty string, the SDK retrieves read receipts, from the latest one, in the reverse chronological order of when the server receives them.
Returns
The list of retrieved read receipts (excluding the one with the starting ID) and the cursor for the next query.
Exceptions
ChatExceptionA description of the exception. See Error.

◆ fetchHistoryMessages() [1/2]

CursorResult< ChatMessage > io.agora.chat.ChatManager.fetchHistoryMessages ( String  conversationId,
ConversationType  type,
int  pageSize,
String  startMsgId 
) throws ChatException

Uses the pagination to get the messages of all types in the conversation from the server.

This is a synchronous method and blocks the current thread.

Parameters
conversationIdThe conversation ID.
  • One-to-one chat: The ID of the peer user;
  • Group chat: The group ID.
typeThe conversation type. See ConversationType.
pageSizeThe number of messages that you expect to get on each page. The value range is [1,50].
startMsgIdThe starting message ID for query. After this parameter is set, the SDK retrieves messages, from the specified one, in the reverse chronological order of when the server receives them. If this parameter is set as null or an empty string, the SDK retrieves messages, starting from the latest one, in the reverse chronological order of when the server receives them.
Returns
The list of retrieved messages (excluding the one with the starting message ID) and the cursor for the next query.
Exceptions
ChatExceptionA description of the exception. See Error.

◆ fetchHistoryMessages() [2/2]

CursorResult< ChatMessage > io.agora.chat.ChatManager.fetchHistoryMessages ( String  conversationId,
ConversationType  type,
int  pageSize,
String  startMsgId,
Conversation.SearchDirection  direction 
) throws ChatException

Uses the pagination to get the messages of all types in the conversation from the server according to the message search direction.

This is a synchronous method and blocks the current thread.

Parameters
conversationIdThe conversation ID.
  • One-to-one chat: The ID of the peer user;
  • Group chat: The group ID.
typeThe conversation type. See ConversationType.
pageSizeThe number of messages you expect to get on each page. The value range is [1,50].
startMsgIdThe starting message ID for query. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If this parameter is set as "null" or an empty string, the SDK retrieves messages according to the message search direction while ignoring this parameter.
  • If direction is set as UP, the SDK retrieves messages, starting from the latest one, in the reverse chronological order of when the server receives them.
  • If direction is set as DOWN, the SDK retrieves messages, starting from the oldest one, in the chronological order of the time the server receives them.
directionThe message search direction. See Conversation.SearchDirection.
  • (Default) UP: The SDK retrieves messages in the reverse chronological order of when the server receives them.
    • DOWN: The SDK retrieves messages in the chronological order of the time the server receives them.
Returns
The list of retrieved messages (excluding the one with the starting message ID) and the cursor for the next query.
Exceptions
ChatExceptionA description of the exception. See Error.

◆ fetchSupportLanguages()

void io.agora.chat.ChatManager.fetchSupportLanguages ( ValueCallBack< List< Language > >  callBack)

Gets all languages supported by the translation service.

Parameters
callBackThe result callback. See CallBack.

◆ getAllConversations()

Map< String, Conversation > io.agora.chat.ChatManager.getAllConversations ( )

Gets all local conversations.

Conversations will be first retrieved from the memory. If no conversation is found, the SDK retrieves from the local database.

Returns
The retrieved conversations.

◆ getAllConversationsBySort()

List< Conversation > io.agora.chat.ChatManager.getAllConversationsBySort ( )

Gets all local conversations.

Pinned conversations are listed at the top of the list and followed by unpinned conversations.

The SDK returns conversations in the descending order of the timestamp of the latest message in them, with the pinned ones at the top of the list and followed by the unpinned ones.

Conversations will be first retrieved from the memory. If no conversation is found, the SDK retrieves from the local database.

Returns
The sorted conversation list.

◆ getConversation() [1/4]

Conversation io.agora.chat.ChatManager.getConversation ( String  id)

Gets the conversation object by conversation ID.

The SDK will return null if the conversation is not found.

Parameters
idThe conversation ID.
Returns
The conversation with the specified ID. The SDK returns null if the conversation is not found.

◆ getConversation() [2/4]

Conversation io.agora.chat.ChatManager.getConversation ( String  id,
ConversationType  type 
)

Gets the conversation by conversation ID and type.

The SDK will return null if the conversation is not found.

Parameters
idThe conversation ID:
  • One-to-one chat: The ID of the peer user;
  • Group chat: The group ID;
  • Chat room chat: The chat room ID;
  • Message thread: The message thread ID.
typeThe conversation type. See ConversationType
Returns
The conversation object found by ID and type. The SDK returns null if the conversation is not found.

◆ getConversation() [3/4]

Conversation io.agora.chat.ChatManager.getConversation ( String  username,
ConversationType  type,
boolean  createIfNotExists 
)

Gets the conversation object by user ID or group ID and conversation type.

Parameters
usernameThe conversation ID:
  • One-to-one chat: The ID of the peer user;
  • Group chat: The group ID;
  • Chat room chat: The chat room ID;
  • Message thread: The message thread ID.
typeThe conversation type. See ConversationType.
createIfNotExistsWhether to create a conversation if the specified conversation is not found:
  • true: Yes;
  • false: No.
Returns
The retrieved conversation object. The SDK returns null if the conversation is not found.

◆ getConversation() [4/4]

Conversation io.agora.chat.ChatManager.getConversation ( String  username,
ConversationType  type,
boolean  createIfNotExists,
boolean  isChatThread 
)

Get conversation object by conversation id and conversation type.

If the conversation is not found, you can create a new object based on the value of CreateIFNotExists or an empty object.

Parameters
usernameThe conversation ID.
  • - One-to-one chat: The ID of the peer user;
    • Group chat: The group ID;
    • Chat room chat: The chat room ID;
    • Message thread: The message thread ID.
typeThe conversation type. See ConversationType.
createIfNotExistsWhether to create a conversation if the specified conversation is not found:
  • true: Yes;
  • false: No.
isChatThreadWhether to search for the chat thread conversation.
  • true: Yes;
    • false: No.
Returns
The retrieved conversation object. The SDK returns null if the conversation is not found.

◆ getConversationsByType()

List< Conversation > io.agora.chat.ChatManager.getConversationsByType ( ConversationType  type)

Gets the list of conversations by conversation type.

Parameters
typeThe conversation type. See ConversationType.
Returns
The list of conversations of the specified type.

◆ getMessage()

ChatMessage io.agora.chat.ChatManager.getMessage ( String  messageId)

Gets the message by message ID.

Parameters
messageIdThe message ID.
Returns
The message object with the specified ID. The SDK returns null if the message does not exist.

◆ getReactionDetail()

CursorResult< MessageReaction > io.agora.chat.ChatManager.getReactionDetail ( final String  messageId,
final String  reaction,
final String  cursor,
final int  pageSize 
) throws ChatException

Gets the Reaction details.

This is a synchronous method.

Parameters
messageIdThe message ID.
reactionThe Reaction content.
cursorThe cursor position from which to start querying data.
pageSizeThe number of Reactions you expect to get on each page.
Returns
The query result CursorResult, which contains the list of obtained Reactions and the cursor for the next query. If the cursor is null, all data is obtained.
Exceptions
ChatExceptionA description of the exception, see Error.

◆ getReactionList()

Map< String, List< MessageReaction > > io.agora.chat.ChatManager.getReactionList ( final List< String >  messageIdList,
final ChatMessage.ChatType  chatType,
final String  groupId 
) throws ChatException

Gets the list of Reactions.

This is a synchronous method.

Parameters
messageIdListThe message ID.
chatTypeThe conversation type. Only the one-to-one chats (ChatMessage.ChatType#Chat and group chats (ChatMessage.ChatType#GroupChat) are allowed.
groupIdThe group ID, which is invalid only for group chats.
Returns
map The Reaction list under the specified message ID. The UserList of MessageReaction indicates the summary data, which only contains the information of the first three users.
Exceptions
ChatExceptionA description of the exception. See Error.

◆ getUnreadMessageCount()

int io.agora.chat.ChatManager.getUnreadMessageCount ( )

Gets the unread message count.

Returns
The count of unread messages.

◆ importMessages()

synchronized void io.agora.chat.ChatManager.importMessages ( List< ChatMessage msgs)

Imports messages to the local database.

You can only import messages that you sent or received.

It is recommended that you import at most 1,000 messages each time.

Parameters
msgsThe messages to import.

◆ loadAllConversations()

void io.agora.chat.ChatManager.loadAllConversations ( )

Loads all conversations from the local database into the memory.

Generally, this method is called upon successful login to speed up the loading of the conversation list.

◆ markAllConversationsAsRead()

void io.agora.chat.ChatManager.markAllConversationsAsRead ( )

Marks all conversations as read.

This method is for the local conversations only.

◆ recallMessage()

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

Recalls the sent message.

If the recipient is offline when the message is delivered and recalled, the recipient only receives the callback MessageListener#onMessageRecalled instead of the message.

This is a synchronous method and blocks the current thread.

Parameters
messageThe message instance.
Exceptions
ChatExceptionA description of the exception. See Error.

◆ removeConversationListener()

void io.agora.chat.ChatManager.removeConversationListener ( ConversationListener  listener)

Removes the conversation listener.

After adding a conversation listener with addConversationListener(ConversationListener), you can call this method to remove it when it is not required.

Parameters
listenerThe conversation listener to remove.

◆ removeMessageListener()

void io.agora.chat.ChatManager.removeMessageListener ( MessageListener  listener)

Removes the message listener.

After adding a message listener with addMessageListener(MessageListener), you can call this method to remove it when it is not required.

Parameters
listenerThe message listener to remove.

◆ removeMessagesFromServer() [1/2]

void io.agora.chat.ChatManager.removeMessagesFromServer ( String  conversationId,
ConversationType  type,
List< String >  msgIdList,
CallBack  callBack 
)
protected

Unidirectionally removes historical message by message ID from the server.

Parameters
conversationIdThe conversation ID.
typeThe conversation type.
msgIdListThe list of IDs of messages to be removed.
callBackThe result callback which contains the error information if the method fails. See CallBack.

◆ removeMessagesFromServer() [2/2]

void io.agora.chat.ChatManager.removeMessagesFromServer ( String  conversationId,
ConversationType  type,
long  beforeTimeStamp,
CallBack  callBack 
)
protected

Unidirectionally removes historical message by timestamp from the server.

Parameters
conversationIdThe conversation ID.
typeThe conversation type.
beforeTimeStampThe UNIX timestamp in millisecond. Messages with a timestamp smaller than the specified one will be removed.
callBackThe result callback which contains the error information if the method fails. See CallBack.

◆ removeReaction()

void io.agora.chat.ChatManager.removeReaction ( final String  messageId,
final String  reaction 
) throws ChatException

Deletes a Reaction.

This is a synchronous method.

Parameters
messageIdThe message ID.
reactionThe Reaction content to delete.
Exceptions
ChatExceptionA description of the exception. See Error.

◆ reportMessage()

void io.agora.chat.ChatManager.reportMessage ( String  msgId,
String  tag,
String  reportReason 
) throws ChatException

Reports an inappropriate message.

This is a synchronous method and blocks the current thread.

Parameters
msgIdThe ID of the inappropriate message.
tagThe tag of the inappropriate message. You need to type a custom tag, like porn or ad.
reportReasonThe reporting reason. You need to type a specific reason.
Exceptions
ChatExceptionA description of the exception. See Error.

◆ saveMessage()

void io.agora.chat.ChatManager.saveMessage ( ChatMessage  message)

Saves the message to the memory and local database.

The command messages (type: Type#CMD, message body: CmdMessageBody) are not saved locally.

Parameters
messageThe message to store.

◆ searchMsgFromDB() [1/2]

List< ChatMessage > io.agora.chat.ChatManager.searchMsgFromDB ( String  keywords,
long  timeStamp,
int  maxCount,
String  from,
Conversation.SearchDirection  direction 
)

Retrieves messages with keywords in the conversation in the local database.

Parameters
keywordsThe keywords for query.
timeStampThe starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If you set this parameter as a negative value, the SDK retrieves messages, starting from the current time, in the descending order of the timestamp included in them.
maxCountThe maximum number of messages to retrieve each time. The value range is [1,400].
fromThe user ID of the message sender in one-to-one chat or group chat. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation.
directionThe message search direction. See Conversation.SearchDirection.
  • (Default) UP: The SDK retrieves messages in the descending order of the timestamp included in them.
    • DOWN: The SDK retrieves messages in the ascending order of the timestamp included in them.
Returns
The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

◆ searchMsgFromDB() [2/2]

List< ChatMessage > io.agora.chat.ChatManager.searchMsgFromDB ( Type  type,
long  timeStamp,
int  maxCount,
String  from,
Conversation.SearchDirection  direction 
)

Retrieves messages of a certain type in the conversation from the local database.

Parameters
typeThe message type. See Type.
timeStampThe starting Unix timestamp in the message for query. The unit is millisecond. After this parameter is set, the SDK retrieves messages, starting from the specified one, according to the message search direction. If you set this parameter as a negative value, the SDK retrieves messages, starting from the current time, in the descending order of the timestamp included in them.
maxCountThe maximum number of messages to retrieve each time. The value range is [1,400].
fromThe user ID of the message sender in one-to-one chat or group chat. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation.
directionThe message search direction. See Conversation.SearchDirection.
  • (Default) UP: The SDK retrieves messages in the descending order of the timestamp included in them.
    • DOWN: The SDK retrieves messages in the ascending order of the timestamp included in them.
Returns
The list of retrieved messages (excluding the one with the starting timestamp). If no message is obtained, an empty list is returned.

◆ sendMessage()

void io.agora.chat.ChatManager.sendMessage ( final ChatMessage  msg)

Sends a message。

For a voice or image message or a message with an attachment, the SDK will automatically upload the attachment.

You can determine whether to upload the attachment to the chat sever by setting ChatOptions#setAutoTransferMessageAttachments(boolean).

To listen for the message sending status, call ChatMessage#setMessageStatusCallback(CallBack).

Parameters
msgThe message object to be sent. Make sure to set the param.

◆ setVoiceMessageListened()

void io.agora.chat.ChatManager.setVoiceMessageListened ( ChatMessage  message)

Marks a voice message as listened.

Parameters
messageThe message object.

◆ translateMessage()

void io.agora.chat.ChatManager.translateMessage ( ChatMessage  message,
List< String >  languages,
ValueCallBack< ChatMessage callBack 
)

Translates a text message.

Parameters
messageThe message object for translation.
languagesThe list of target language codes.
callBackThe result callback. See CallBack.

◆ updateMessage()

boolean io.agora.chat.ChatManager.updateMessage ( ChatMessage  message)

Updates the local message.

This method updates the message in both the memory and the local database at the same time.

Parameters
messageThe message object to update.

◆ updateParticipant()

boolean io.agora.chat.ChatManager.updateParticipant ( String  from,
String  changeTo 
)

Changes the data of one contact in the local database to those of the other contact.

Note

  • This method brings changes to data such as the message list, the conversation list, contact list, the block list in the database.
  • This method does not update the data stored in the memory.
Parameters
fromThe user ID of the original contact.
changeToThe user ID of the new contact.
Returns
The operation result.
  • true: Success.
  • false: Failure.

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