即时通讯 IM API 参考 v1.3.2
Agora Java IM SDK
Public 成员函数 | Protected 成员函数 | 所有成员列表
io.agora.chat.ChatManager类 参考

Public 成员函数

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)
 
void recallMessage (ChatMessage message, String ext) throws ChatException
 
void asyncRecallMessage (final ChatMessage message, String ext, 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)
 
boolean 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 ()
 
void asyncFilterConversationsFromDB (CustomConversationFilter filter, boolean cleanConversationsCache, ValueCallBack< List< Conversation > > callBack)
 
void cleanConversationsMemoryCache ()
 
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)
 
boolean loadAllConversations ()
 
boolean deleteConversation (String conversationId, 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 (@NonNull Type type, long timeStamp, int maxCount, String from, Conversation.SearchDirection direction)
 
List< ChatMessagesearchMsgFromDB (Set< Type > types, long timeStamp, int maxCount, String from, Conversation.SearchDirection direction)
 
List< ChatMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, Conversation.SearchDirection direction)
 
List< ChatMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, Conversation.SearchDirection direction, Conversation.ChatMessageSearchScope searchScope)
 
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)
 
void asyncAddConversationMark (@NonNull List< String > conversationIds, @NonNull EMMarkType mark, CallBack callback)
 
void asyncRemoveConversationMark (@NonNull List< String > conversationIds, @NonNull EMMarkType mark, CallBack callback)
 
void asyncGetConversationsFromServerWithCursor (@NonNull String cursor, @NonNull ConversationFilter filter, ValueCallBack< CursorResult< Conversation > > callback)
 
void asyncDeleteAllMsgsAndConversations (boolean clearSeverData, CallBack deleteCallBack)
 
void asyncPinMessage (@NonNull String messageId, CallBack callBack)
 
void asyncUnPinMessage (@NonNull String messageId, CallBack callBack)
 
void asyncGetPinnedMessagesFromServer (@NonNull String conversationId, ValueCallBack< List< ChatMessage > > callBack)
 
void asyncGetMessageCount (ValueCallBack< Integer > callBack)
 

Protected 成员函数

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

详细描述

聊天管理类,该类负责管理会话(加载,删除等)、发送消息、下载消息附件等。

发送文文本消息示例如下:

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

成员函数说明

◆ ackConversationRead()

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

发送会话的已读回执,该方法只针对单聊会话。

该方法会通知服务器将此会话未读数设置为 0,消息发送方将会收到 ConversationListener#onConversationRead(String, String) 回调。 在多端多设备登录下,接收方的其他设备也会收到该回调。

群消息已读回执,详见 ackGroupMessageRead(String, String, String)

参数
conversationId会话 ID。
异常
ChatException可能抛出以下异常:Error#USER_NOT_LOGINError#SERVER_NOT_REACHABLEError#MESSAGE_INVALID 等,详见 Error

◆ ackGroupMessageRead()

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

发送群消息已读回执。

注解

设置了 ChatOptions#setRequireAck(boolean)ChatMessage#setIsNeedGroupAck(boolean) 后才能调用该方法。

发送单聊消息已读回执,详见 ackMessageRead(String, String)

会话已读回执,详见 ackConversationRead(String)

参数
to会话 ID。
messageId消息 ID。
ext扩展信息。用户通过定义关键字指定动作或命令。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ ackMessageRead()

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

发送消息的已读回执。

该方法仅适用于单聊会话,仅在 ChatOptions#setRequireAck(boolean)true 时生效。

发送群消息已读回执,详见 ackGroupMessageRead(String, String, String)

推荐进入聊天页面的时调用 ackConversationRead(String) ,其他情况下调用该方法以减少调用频率。

参数
to已读回执接收方的用户 ID。
messageId消息的 ID。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ addConversationListener()

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

注册会话监听器。

会话监听器可监听会话变化及会话已读回执。

在不需要会话监听器时,可调用 removeConversationListener(ConversationListener) 方法移除。

参数
listener要添加的会话监听,详见 ConversationListener

◆ addMessageListener()

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

注册消息监听器。

接收到新消息等回调可以通过设置此方法进行监听。

在不需要消息监听器时,可调用 removeMessageListener(MessageListener) 方法将其移除。

参数
listener要注册的消息监听,详见 MessageListener

◆ addReaction()

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

添加 Reaction。

同步方法。

参数
messageId消息 ID。
reaction要添加的消息 Reaction。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ asyncAddConversationMark()

void io.agora.chat.ChatManager.asyncAddConversationMark ( @NonNull List< String >  conversationIds,
@NonNull EMMarkType  mark,
CallBack  callback 
)

标记会话。

调用该方法会同时为本地和服务器端的会话添加标记。

参数
conversationIds会话 ID 列表。
mark要添加的会话标记。
callback该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ asyncAddReaction()

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

添加 Reaction。

异步方法。

参数
messageId消息 ID。
reaction要添加的消息 Reaction。
callback处理结果回调,失败会返回失败原因。详见 CallBack

◆ asyncDeleteAllMsgsAndConversations()

void io.agora.chat.ChatManager.asyncDeleteAllMsgsAndConversations ( boolean  clearSeverData,
CallBack  deleteCallBack 
)

清空所有会话及其消息。

异步方法。

参数
clearSeverData是否删除服务端所有会话及其消息:
  • true:是。服务端的所有会话及其消息会被清除,当前用户无法再从服务端拉取消息和会话,其他用户不受影响。
  • (默认)false:否。只清除本地所有会话及其消息,服务端的会话及其消息仍保留。
deleteCallBack该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ asyncFetchConversationsFromServer() [1/3]

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

分页从服务器获取获取会话列表。

SDK 按照会话活跃时间(会话的最后一条消息的时间戳)倒序返回会话列表。

若会话中没有消息,则 SDK 按照会话创建时间的倒序返回会话列表。

参数
limit每页期望返回的会话数量。取值范围为 [1,50]。
cursor开始获取数据的游标位置。若获取数据时传 null 或者空字符串(""),SDK 从最新活跃的会话开始获取。
callback分页获取结果 CursorResult,包含用于下次获取数据的 cursor 以及会话列表。 如果是最后一页,cursor 返回结果为空字符串。

◆ asyncFetchConversationsFromServer() [2/3]

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

从服务器获取会话列表。

异步方法。

返回
当前用户的会话列表。
弃用:
已废弃。请用 asyncFetchConversationsFromServer(int, String, ValueCallBack) 代替。

◆ asyncFetchConversationsFromServer() [3/3]

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

从服务器分页获取会话列表。

异步方法。

参数
pageNum当前页码,从 1 开始。
pageSize每页获取的会话数量,取值范围为 [1,20]。
返回
当前用户的会话列表。
弃用:
已废弃。请用 asyncFetchConversationsFromServer(int, String, ValueCallBack) 代替。

◆ asyncFetchGroupReadAcks()

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

从服务器分页获取群组消息已读回执详情。

发送群组消息回执,可调用 ackGroupMessageRead(String, String, String)

异步方法。

参数
msgId消息 ID。
pageSize每页获取的群消息已读回执数。取值范围为 [1,50]。
startAckId查询起始的已读回执 ID。该参数设置后,SDK 从指定的已读回执 ID 开始,按服务器接收已读回执的时间的逆序获取。 若该参数为空,SDK 从最新的已读回执开始按服务器接收回执时间的逆序获取。
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 
)

从服务器按消息搜索方向分页获取指定会话的所有类型的历史消息。

异步方法。

参数
conversationId会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID。
type会话类型,详见 ConversationType
pageSize每页期望获取的消息数。取值范围为 [1,50]。
startMsgId查询的起始消息 ID。该参数设置后,SDK 从指定的消息 ID 开始,按消息搜索方向获取。 如果传入消息的 ID 为空,SDK 忽略该参数,按搜索方向查询消息。
  • directionUP,SDK 从最新消息开始,按照服务器接收消息时间的逆序获取;
  • directionDOWN,SDK 从最早消息开始,按照服务器接收消息时间的正序获取。
direction消息搜索方向。详见 Conversation.SearchDirection
  • (默认)UP:按照消息中的时间戳的逆序查询;
  • DOWN:按照消息中的时间戳的正序查询;
callBack结果回调:
弃用:
已废弃。请用 asyncFetchHistoryMessages(String, ConversationType, int, String, FetchMessageOption, ValueCallBack) 代替。

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

从服务器分页获取指定会话的所有类型的历史消息。

异步方法。

参数
conversationId会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID。
type会话类型,详见 ConversationType
pageSize每页期望获取的消息条数。取值范围为 [1,50]。
startMsgId查询的起始消息 ID。该参数设置后,SDK 从指定的消息 ID 开始,按服务器接收消息的时间的逆序获取。 若该参数为空,SDK 从最新的消息开始,按服务器接收消息的时间的逆序获取。
callBack结果回调,成功则执行 ValueCallBack#onSuccess(Object),返回消息列表(不包含查询起始 ID 的消息)和下次查询的 cursor; 失败则执行 ValueCallBack#onError(int, String)
弃用:
已废弃。请用 asyncFetchHistoryMessages(String, ConversationType, int, String, FetchMessageOption, ValueCallBack) 代替。

◆ asyncFetchHistoryMessages()

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

根据消息拉取参数配置类(FetchMessageOption)从服务器分页获取指定会话的历史消息。

异步方法。

参数
conversationId会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID。
  • 聊天室:聊天室 ID。
type会话类型, 详见 ConversationType
pageSize每页期望获取的消息条数。取值范围为 [1,50]。
cursor查询的起始游标位置。
option查询历史消息的参数配置类,详见 FetchMessageOption
返回
查询到的消息列表和下次查询的 cursor。
参数
callBack结果回调:

◆ asyncFetchPinnedConversationsFromServer()

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

分页从服务器获取置顶会话。

SDK 按照会话置顶时间倒序返回。

参数
limit每页返回的会话数。取值范围为 [1,50]。
cursor开始获取数据的游标位置。若获取数据时传 null 或者空字符串(""),SDK 从最新置顶的会话开始查询。
callback分页获取结果 CursorResult,包含用于下次获取数据的 cursor 以及置顶的会话列表。 如果是最后一页,cursor 返回结果为空字符串。

◆ asyncFilterConversationsFromDB()

void io.agora.chat.ChatManager.asyncFilterConversationsFromDB ( CustomConversationFilter  filter,
boolean  cleanConversationsCache,
ValueCallBack< List< Conversation > >  callBack 
)

根据自定义会话过滤器获取本地所有会话。

调用该接口时,SDK 会根据过滤条件从本地数据库获取会话。

异步方法。

参数
filter过滤器,详见 CustomConversationFilter。若要获取全部会话,传入 null 即可。
cleanConversationsCache是否清空内存缓存的会话。
callBack结果回调,成功时回调 ValueCallBack#onSuccess(Object),返回过滤后的会话列表。

◆ asyncGetConversationsFromServerWithCursor()

void io.agora.chat.ChatManager.asyncGetConversationsFromServerWithCursor ( @NonNull String  cursor,
@NonNull ConversationFilter  filter,
ValueCallBack< CursorResult< Conversation > >  callback 
)

根据会话过滤类从服务器分页查询会话列表。

参数
cursor查询的开始位置。若传入空字符串,SDK 从最新标记操作的会话开始获取。
filter会话查询选项,包括会话标记和每页获取的会话条数。
callback该方法完成的回调,返回会话列表和用于下一次获取数据的 cursor。当 cursor 为 空字符串时,表示已获取全部数据。

◆ asyncGetMessageCount()

void io.agora.chat.ChatManager.asyncGetMessageCount ( ValueCallBack< Integer >  callBack)

获取本地数据库中消息总数

该方法为异步方法。

参数
callBack该方法完成调用的回调。如果该方法成功,会包含本地数据库中消息总数。如果该方法调用失败,会包含调用失败的原因。

◆ asyncGetPinnedMessagesFromServer()

void io.agora.chat.ChatManager.asyncGetPinnedMessagesFromServer ( @NonNull String  conversationId,
ValueCallBack< List< ChatMessage > >  callBack 
)

从服务端获取置顶消息。

该方法为异步方法。

参数
conversationId会话 ID。
callBack该方法完成调用的回调。如果该方法成功,会包含所有置顶的消息。如果该方法调用失败,会包含调用失败的原因。

◆ asyncGetReactionDetail()

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

获取 Reaction 详细信息。

异步方法。

参数
messageId消息 ID。
reaction消息 Reaction。
cursor查询的起始游标位置。
pageSize每页期望获取的 Reaction 数。
callback处理结果回调,包含 cursor 和 MessageReaction 列表(仅使用该列表第一个数据即可)。

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

获取 Reaction 列表。

异步方法。

参数
messageIdList消息 ID。
chatType会话类型,仅支持单聊(ChatMessage.ChatType#Chat )和群聊(ChatMessage.ChatType#GroupChat)。
groupId群组 ID,该参数只对群聊生效。
callback处理结果回调,包含消息 ID 对应的 Reaction 列表(MessageReaction 的用户列表 UserList 为概要数据,只包含前三个用户信息)。

◆ asyncModifyMessage()

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

修改消息内容。

调用该方法修改消息内容后,本地和服务端的消息均会修改。

调用该方法只能修改单聊和群聊中的文本消息,不能修改聊天室消息。

多设备和该消息的接收方可通过 MessageListener#onMessageContentChanged(ChatMessage, String, long) 回调监听消息是否有变更。

参数
messageId消息 ID。
messageBodyModified内容修改后的消息体。
callBack消息修改是否成功的回调。ValueCallBack 类的对象,详见 ValueCallBack,包含已修改的消息对象。

◆ asyncPinConversation()

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

设置是否置顶会话。

参数
conversationId会话 ID。
isPinned是否置顶会话:
  • true:置顶;
  • false: 取消置顶。
callback设置会话置顶状态的结果回调。

◆ asyncPinMessage()

void io.agora.chat.ChatManager.asyncPinMessage ( @NonNull String  messageId,
CallBack  callBack 
)

置顶消息。

该方法为异步方法。

参数
messageId消息 ID。
callBack该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ asyncRecallMessage() [1/2]

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

撤回发送成功的消息。

异步方法。

参数
message消息对象。
callbackCallBack 类的对象,详见 CallBack

◆ asyncRecallMessage() [2/2]

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

撤回发送成功的消息。

异步方法。

参数
message消息对象。
ext扩展信息。
callbackCallBack 类的对象,详见 CallBack

◆ asyncRemoveConversationMark()

void io.agora.chat.ChatManager.asyncRemoveConversationMark ( @NonNull List< String >  conversationIds,
@NonNull EMMarkType  mark,
CallBack  callback 
)

取消标记会话。

调用该方法会同时为本地和服务器端的会话添加标记。

参数
conversationIds会话 ID 列表。
mark要移除的会话标记。
callback该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ asyncRemoveReaction()

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

删除 Reaction。

异步方法。

参数
messageId消息 ID。
reaction要删除的 Reaction。
callback处理结果回调,详见 CallBack

◆ asyncReportMessage()

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

举报非法消息。

异步方法。

参数
msgId要举报的消息 ID。
tag非法消息的标签。你需要填写自定义标签,例如涉政广告
reportReason举报原因。你需要自行填写举报原因。
callback结果回调,详见 CallBack

◆ asyncUnPinMessage()

void io.agora.chat.ChatManager.asyncUnPinMessage ( @NonNull String  messageId,
CallBack  callBack 
)

取消置顶消息。

该方法为异步方法。

参数
messageId消息 ID。
callBack该方法完成调用的回调。如果该方法调用失败,会包含调用失败的原因。

◆ cleanConversationsMemoryCache()

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

清除本地内存中的所有会话释放内存。

注意:释放内存后,通过 getAllConversations()getAllConversationsBySort() 从内存里获取到的会话数可能为 0。通过getUnreadMessageCount()获取到的未读消息数可能为 0。

若需要获取所有会话和未读数,需要先调用 loadAllConversations()或者 asyncFilterConversationsFromDB(CustomConversationFilter, boolean, ValueCallBack) 从数据库重新加载会话到内存里。

◆ deleteConversation()

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

删除指定会话及其本地历史消息。

参数
conversationId会话 ID。
deleteMessages删除会话时是否同时删除本地的历史消息。
  • true:删除;
  • false:不删除。
返回
会话是否删除成功。
  • true:是;
  • false: 否。

◆ deleteConversationFromServer()

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

删除服务端的指定会话及其历史消息。

异步方法。

参数
username会话 ID。
type会话类型,详见 ConversationType
isDeleteServerMessages删除会话时是否同时删除历史消息。
  • true:是;
  • false: 否。
deleteCallBack删除服务端会话及其历史消息成功与否的回调。
  • true:删除成功;
  • false:删除失败。

◆ deleteMessagesBeforeTimestamp()

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

删除指定时间戳之前的本地历史消息。

参数
timeStamp查询的消息的起始 Unix 时间戳,单位为毫秒。
callback删除结果回调,详见 CallBack

◆ downloadAndParseCombineMessage()

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

下载并解析合并消息的附件。

对于一条合并消息,首次调用该方法会下载和解析合并消息附件,然后返回消息列表,而后续调用会存在以下情况:

  1. 若附件已存在,该方法会直接解析附件并返回消息列表。
  2. 若附件不存在,该方法首先会下载附件,然后解析合并消息附件并返回消息列表。
参数
message要下载和解析的合并消息。
callback结果回调,成功时回调 ValueCallBack#onSuccess(Object),返回解析成功的消息列表; 失败时回调 ValueCallBack#onError(int, String)

◆ downloadAttachment()

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

下载消息的附件。

若附件自动下载失败,也可以调用此方法下载。

参数
msg要下载附件的消息。

◆ downloadThumbnail()

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

下载消息的缩略图。

参数
msg要下载缩略图的消息。只有图片消息和视频消息有缩略图。

◆ fetchConversationsFromServer()

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

从服务器获取会话列表。

用户默认可拉取 7 天内的 10 个会话(每个会话包含最新一条历史消息)。

同步方法,会阻塞当前线程。

返回
当前用户的会话列表。
弃用:
已废弃。请用 asyncFetchConversationsFromServer(int, String, ValueCallBack) 代替。

◆ fetchGroupReadAcks()

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

从服务器分页获取群组消息已读回执详情。

发送群组消息回执,可调用 ackGroupMessageRead(String, String, String)

同步方法,会阻塞当前线程。

参数
msgId消息 ID。
pageSize每页期望返回的群消息已读数。取值范围[1,50]。
startAckId查询起始的已读回执 ID。该参数设置后,SDK 从指定的已读回执 ID 开始,按服务器接收已读回执的时间的逆序获取。 若该参数为空,SDK 从最新的已读回执开始按服务器接收回执时间的逆序获取。
返回
返回消息列表(不包含查询起始 ID 的已读回执)和用于继续获取群消息回执的 cursor。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ fetchHistoryMessages() [1/2]

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

从服务器分页获取指定会话的所有类型的历史消息。

同步方法,会阻塞当前线程。

参数
conversationId会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID。
type会话类型, 详见 ConversationType
pageSize每页期望获取的消息条数。取值范围为 [1,50]。
startMsgId开始获取的消息 ID。该参数设置后,SDK 从指定的消息 ID 开始,按服务器接收消息的时间的逆序获取。 若该参数为空,SDK 从最新的消息开始,按服务器接收消息的时间的逆序获取。
返回
消息列表(不包含查询起始 ID 的消息)和下次查询的 cursor。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error
弃用:
已废弃。请用 asyncFetchHistoryMessages(String, ConversationType, int, String, FetchMessageOption, ValueCallBack) 代替。

◆ fetchHistoryMessages() [2/2]

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

从服务器分页按消息搜索方向获取指定会话的所有类型的历史消息。

同步方法,会阻塞当前线程。

参数
conversationId会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID。
type会话类型。详见 ConversationType
pageSize每页期望获取的消息条数。取值范围为 [1,50]。
startMsgId查询的起始消息 ID。该参数设置后,SDK 从指定的消息 ID 开始,按消息检索方向获取。如果传入消息的 ID 为空,SDK 忽略该参数,按搜索方向查询消息。
  • directionUP,SDK 从最新消息开始,按照服务器接收消息时间的逆序获取;
  • directionDOWN,SDK 从最早消息开始,按照服务器接收消息时间的正序获取。
direction消息搜索方向。详见 Conversation.SearchDirection
  • (默认)UP:按照服务器接收消息时间的逆序获取;
  • DOWN:按照服务器接收消息时间的正序获取。
返回
消息列表(不包含查询起始 ID 的消息)和下次查询的 cursor。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error
弃用:
已废弃。请用 asyncFetchHistoryMessages(String, ConversationType, int, String, FetchMessageOption, ValueCallBack) 代替。

◆ fetchSupportLanguages()

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

获取翻译服务支持的语言。

参数
callback结果回调,详见 CallBack

◆ getAllConversations()

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

获取本地当前所有会话。

该方法会先从内存中获取,如果未找到任何会话,从本地数据库获取。

返回
本地内存或者数据库中所有的会话。

◆ getAllConversationsBySort()

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

获取本地当前所有会话。

SDK 按照最近一条消息的时间戳的倒序返回会话,置顶会话在前,非置顶会话在后。

该方法会先从内存中获取,如果未找到任何会话,SDK 从本地数据库获取。

返回
排序后的会话列表。

◆ getConversation() [1/4]

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

获取指定 ID 的会话对象。

参数
id会话 ID。
返回
根据指定会话 ID 找到的会话对象,如果没有找到会返回空值。

◆ getConversation() [2/4]

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

根据会话 ID 以及会话类型获取会话。

没有找到返回空值。

参数
id会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID;
  • 聊天室:聊天室 ID;
  • 子区:子区 ID。
type会话类型,详见 ConversationType
返回
根据指定 ID 以及会话类型找到的会话对象,未找到会返回空值。

◆ getConversation() [3/4]

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

根据会话 ID 和会话类型获取会话。

参数
username会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID;
  • 聊天室:聊天室 ID;
  • 子区:子区 ID。
type会话类型,详见 ConversationType
createIfNotExists未找到指定会话时是否创建一个新会话。
  • true:是;
  • false:否。
返回
找到的会话对象,如果未找到,返回空值。

◆ getConversation() [4/4]

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

根据会话 ID 以及会话类型获取会话。

参数
username会话 ID。
  • 单聊:对端用户的用户 ID;
  • 群聊:群组 ID;
  • 聊天室:聊天室 ID;
  • 子区:子区 ID。
type会话类型,详见 ConversationType
createIfNotExists未找到指定会话时是否创建一个新会话。
  • true:是;
    • false:否。
isChatThread是否查找子区会话。
  • true:是;
    • false:否。
返回
找到的会话对象。如果未找到,返回空值。

◆ getConversationsByType()

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

获取指定类型的所有会话。

参数
type会话类型,详见 ConversationType
返回
指定类型的会话列表。

◆ getMessage()

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

获取指定 ID 的消息对象。

参数
messageId消息 ID。
返回
根据指定 ID 获取的消息对象,如果消息不存在会返回空值。

◆ getReactionDetail()

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

获取 Reaction 详细信息。

同步方法。

参数
messageId消息 ID。
reaction消息 Reaction 内容。
cursor查询的起始游标位置。
pageSize每页期望获取的 Reaction 数。
返回
获取结果 CursorResult,包含 cursor 和 Reaction 列表。若 cursor 为空表示数据已全部获取。

◆ getReactionList()

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

获取 Reaction 列表。

同步方法。

参数
messageIdList消息 ID。
chatType会话类型,仅支持单聊(ChatMessage.ChatType#Chat)和群聊(ChatMessage.ChatType#GroupChat)。
groupId群组 ID,该参数仅对群聊生效。
返回
map 指定消息 ID 对应的 Reaction 列表(MessageReaction 的用户列表 UserList 为概要数据,只包含前三个用户信息)。

◆ getUnreadMessageCount()

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

获取未读消息数。

返回
未读消息数。

◆ importMessages()

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

将消息导入本地数据库。

你只能将你发送或接收的消息导入本地数据库。

推荐一次导入 1,000 条以内的数据。

参数
msgs需要导入数据库的消息。

◆ loadAllConversations()

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

从数据库加载本地所有的会话到内存中。

一般在登录成功后使用此方法,可以加快会话列表的加载速度。

◆ markAllConversationsAsRead()

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

将所有会话都设成已读。

该方法仅适用于本地会话。

返回
是否成功标记所有会话为已读。

◆ recallMessage() [1/2]

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

撤回发送成功的消息。

若消息发送和撤回时接收方为离线状态,接收方会收到消息撤回回调 MessageListener#onMessageRecalled,不会收到该消息。

同步方法,会阻塞当前线程。

参数
message消息对象。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ recallMessage() [2/2]

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

撤回发送成功的消息。

若消息发送和撤回时接收方为离线状态,接收方会收到消息撤回回调 MessageListener#onMessageRecalled,不会收到该消息。

同步方法,会阻塞当前线程。

参数
message消息对象。
ext扩展信息
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ removeConversationListener()

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

移除会话监听器。

调用 addConversationListener(ConversationListener) 添加会话监听器后再调用本方法移除。

参数
listener要移除的会话监听器,详见 ConversationListener

◆ removeMessageListener()

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

移除消息监听器。

调用 addMessageListener(MessageListener) 添加消息监听后再调用本方法移除。

参数
listener要移除的监听器,详见 MessageListener

◆ removeMessagesFromServer() [1/2]

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

根据消息 ID 单向删除漫游消息。

参数
conversationId会话 ID。
type会话类型。
msgIdList要删除的消息 ID 列表。
callBack处理结果回调,详见 CallBack

◆ removeMessagesFromServer() [2/2]

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

根据时间戳单向删除漫游消息。

参数
conversationId会话 ID。
type会话类型。
beforeTimeStampUNIX 时间戳,单位为毫秒。若消息的 UNIX 时间戳小于设置的值,则会被删除。
callBack处理结果回调,详见 CallBack

◆ removeReaction()

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

删除 Reaction。

同步方法。

参数
messageId消息 ID。
reaction要删除的 Reaction。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ reportMessage()

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

举报非法消息。

同步方法,会阻塞当前线程。

参数
msgId要举报的消息 ID。
tag非法消息的标签。你需要填写自定义标签,例如涉政广告
reportReason举报原因。你需要自行填写举报原因。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ saveMessage()

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

保存消息到内存和本地数据库。

命令消息(类型见:Type#CMD,消息体见:CmdMessageBody)不会在本地保存。

参数
message待存储的消息。

◆ searchMsgFromDB() [1/4]

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

从本地数据库获取一定数量的特定类型的消息。

参数
type消息类型。详见 Type
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从当前时间开始搜索。
maxCount每次获取的最大消息数。取值范围为 [1,400]。
from消息发送方的用户 ID。若设置为 null 或空字符串,搜索消息时对发送方不限制。
direction消息搜索方向。详见 Conversation.SearchDirection
  • (默认)UP:按照消息中的时间戳的逆序查询;
  • DOWN:按照消息中的时间戳的正序查询。
返回
消息列表(不包含查询起始时间戳对应的消息)。若未查找到任何消息,返回空列表。

◆ searchMsgFromDB() [2/4]

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

从本地数据库获取一定数量的多种类型的消息。

参数
types消息类型。详见 Type
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从当前时间开始搜索。
maxCount每次获取的最大消息数。取值范围为 [1,400]。
from消息发送方的用户 ID。若设置为 null 或空字符串,搜索消息时对发送方不限制。
direction消息搜索方向。详见 Conversation.SearchDirection
  • (默认)UP:按照消息中的时间戳的逆序查询;
  • DOWN:按照消息中的时间戳的正序查询。
返回
消息列表(不包含查询起始时间戳对应的消息)。若未查找到任何消息,返回空列表。

◆ searchMsgFromDB() [3/4]

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

从本地数据库获取包含特定关键字的消息。

参数
keywords查询关键字。
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从当前时间开始搜索。
maxCount每次获取的最大消息数。取值范围为 [1,400]。
from消息发送方的用户 ID。若设置为 null 或空字符串,搜索消息时对发送方不限制。
direction消息搜索方向。详见 Conversation.SearchDirection
  • (默认)UP:按照消息中的时间戳的逆序查询;
  • DOWN:按照消息中的时间戳的正序查询。
返回
消息列表(不包含查询起始时间戳对应的消息)。若未查找到任何消息,返回空列表。

◆ searchMsgFromDB() [4/4]

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

从本地数据库获取包含特定关键字的消息。

参数
keywords查询关键字。
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从当前时间开始搜索。
maxCount每次获取的最大消息数。取值范围为 [1,400]。如果设为小于等于 0,SDK 会获取一条消息。
from消息发送方的用户 ID。若设置为 null 或空字符串,搜索消息时对发送方不限制。
direction消息搜索方向。详见 Conversation.SearchDirection
  • (默认)UP:按照消息中的时间戳的逆序查询;
  • DOWN:按照消息中的时间戳的正序查询。
searchScope消息搜索范围。详见 Conversation.ChatMessageSearchScope
返回
消息列表(不包含查询起始时间戳对应的消息)。若未查找到任何消息,返回空列表。

◆ sendMessage()

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

发送消息。

如果是语音,图片类等有附件的消息,SDK 会自动上传附件。

可以通过 ChatOptions#setAutoTransferMessageAttachments(boolean) 设置是否上传到聊天服务器。

发送消息的状态,可以通过设置 ChatMessage#setMessageStatusCallback(CallBack) 进行监听。

参数
msg要发送的消息,必填。

◆ setVoiceMessageListened()

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

将语音消息设置为已听。

参数
message要设置的消息对象。

◆ translateMessage()

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

翻译一条文本消息。

参数
message要翻译的消息对象。
languages目标语言代码列表。
callback结果回调,详见 CallBack

◆ updateMessage()

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

更新本地消息。

该方法会同时更新本地内存和数据库中的消息。

参数
message要更新的消息对象。

◆ updateParticipant()

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

将数据库中指定联系人的相关信息变更成另外一个联系人。

注解
  • 消息列表,会话列表,联系人列表和黑名单列表等相关信息会发生变化。
  • 该方法不会更新内存中数据。
参数
from原联系人的用户 ID。
changeTo新联系人的用户 ID。
返回
返回更新结果,任何列表更新失败,均会返回 false

该类的文档由以下文件生成: