agora_chat_SDK 1.0.6
agora java chat 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 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)
 
Conversation getConversation (String username, ConversationType type, boolean createIfNotExists, boolean isChatThread)
 
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 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 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
 
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)
 
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)
 
void deleteMessagesBeforeTimestamp (long timeStamp, CallBack callback)
 
void asyncReportMessage (String msgId, String reportTarget, String reportReason, CallBack callBack)
 
void reportMessage (String msgId, String reportTarget, 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 成员函数

 ChatManager (ChatClient client, EMAChatManager manager, EMAReactionManager reactionManager)
 

详细描述

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

比如,发送一条文本消息:

ChatMessage message = ChatMessage.createTxtSendMessage(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扩展信息。ext 属性是用户自己定义的关键字,接收后,解析出自定义的字符串,可以自行处理。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ ackMessageRead()

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

发送消息的已读回执。

该方法仅适用于单聊会话。

注意:如果设置 ChatOptions#setRequireAck(boolean)false,当前方法将失效。

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

建议:在进入聊天页面的时调用 ackConversationRead(String) ,其他场景再调用此方法,可以大量减少调用此方法的次数。

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

◆ addConversationListener()

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

注册会话监听。

用于监听会话变化及监听会话已读回执,详见 ConversationListener

需要配合 removeConversationListener(ConversationListener) 使用。

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

◆ addMessageListener()

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

注册消息监听。

接受到新消息等回调可以通过设置此方法进行监听,详见 MessageListener

如果需要移除监听,可以和 removeMessageListener(MessageListener) 方法配合使用。

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

◆ addReaction()

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

添加 Reaction。

同步方法。

参数
messageId消息 ID。
reaction消息 Reaction 内容。

◆ asyncAddReaction()

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

添加 Reaction。

异步方法。

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

◆ asyncFetchConversationsFromServer()

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

从服务器获取会话列表。 该功能需联系商务开通,开通后,用户默认可拉取 7 天内的 10 个会话(每个会话包含最新一条历史消息),如需调整会话数量或时间限制请联系商务经理。

异步方法。

返回
返回当前用户的会话列表。

◆ 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每页获取群消息已读回执的条数。
startAckId已读回执的 ID,如果为空,从最新的回执向前开始获取。
callBack结果回调,成功执行 ValueCallBack#onSuccess(Object),失败执行 ValueCallBack#onError(int, String)

◆ 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。
type会话类型,详见 ConversationType
pageSize每页获取的条数。
startMsgId漫游消息的开始消息 ID,如果为空,根据 direction , 当检索方向为 io.agora.chat.Conversation.SearchDirection#UP 时, 从最新的消息向前开始获取;当检索方向为 io.agora.chat.Conversation.SearchDirection#DOWN 时, 从最旧的消息向后开始获取。
direction漫游消息检索方向,io.agora.chat.Conversation.SearchDirection#UP为检索 时间戳消息小于开始消息时间戳的消息,io.agora.chat.Conversation.SearchDirection#DOWN 为检索时间戳消息大于开始消息时间戳的消息。
callBack结果回调,成功则执行 ValueCallBack#onSuccess(Object), 返回消息列表和用于继续获取历史消息的 Cursor; 失败则执行 ValueCallBack#onError(int, String)

◆ 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。
type会话类型,详见 ConversationType
pageSize每页获取的条数。
startMsgId漫游消息的开始消息 ID,如果为空,从最新的消息向前开始获取。
callBack结果回调,成功则执行 ValueCallBack#onSuccess(Object), 返回消息列表和用于继续获取历史消息的 Cursor; 失败则执行 ValueCallBack#onError(int, 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 
)

获取 Reaction 详细信息。

异步方法。

参数
messageId消息 ID。
reaction消息 Reaction。
cursor查询 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 的用户列表为概要数据,只包含前三个用户信息)。

◆ 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  reportTarget,
String  reportReason,
CallBack  callBack 
)

举报违规消息

参数
msgId违规的消息id。
reportTarget举报类型(例如:涉黄、涉恐)
reportReason举报原因。
callBack执行上报结果 成功执行 CallBack#onSuccess(),失败执行CallBack#onError(int, String)

◆ aysncRecallMessage()

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

撤回发送成功的消息。

异步方法。

参数
message消息对象。
callback一个 CallBack 类型的对象,详见 CallBack

◆ deleteConversation()

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

删除指定 ID 的对话和本地的聊天记录。 如果将 deleteMessages 设为 true,删除会话的同时也会删除本地的聊天记录。

参数
username会话 ID。
deleteMessages是否同时删除本地的聊天记录。
  • true 表示删除;
  • false 表示不删除。
返回
删除会话结果。
  • true 代表删除成功;
  • false 代表删除失败。

◆ deleteConversationFromServer()

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

删除服务端的指定 ID 的对话和聊天记录,内部异步操作。

参数
username会话 ID。
type会话类型 ConversationType
isDeleteServerMessages是否同时删除服务端的聊天记录。
  • true:删除服务端会话的同时也会删除服务端的聊天记录。
  • false 表示删除服务端会话的同时不删除服务端的聊天记录。
deleteCallBack删除服务端会话与记录成功与否的回调。
  • true 代表删除成功;
  • false 代表删除失败。

◆ deleteMessagesBeforeTimestamp()

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

删除时间戳之前的本地消息记录。

参数
timeStampUnix 时间戳,单位为毫秒。
callback删除结果回调,详见 CallBack

◆ downloadAttachment()

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

下载消息的附件。

未成功下载的附件,可调用此方法再次下载。

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

◆ downloadFile()

void io.agora.chat.ChatManager.downloadFile ( final String  remoteUrl,
final String  localFilePath,
final Map< String, String >  headers,
final CallBack  callback 
)

从服务器下载文件。

参数
remoteUrl服务器上的远程文件路径。
localFilePath本地要生成的文件路径。
headers请求头。
callback下载结果回调,详见 CallBack
弃用:
使用 downloadAttachment(ChatMessage) 代替。

◆ downloadThumbnail()

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

下载消息的缩略图。

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

◆ fetchConversationsFromServer()

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

从服务器获取会话列表。 该功能需联系商务开通,开通后,用户默认可拉取 7 天内的 10 个会话(每个会话包含最新一条历史消息),如需调整会话数量或时间限制请联系商务经理。

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

返回
返回当前用户的会话列表。

◆ fetchGroupReadAcks()

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

从服务器获取群组消息回执详情。

分页获取。

参考: 发送群组消息回执,详见 ackGroupMessageRead(String, String, String)

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

参数
msgId需要获取回执的消息 ID。
pageSize每次获取群消息已读回执的条数。
startAckId已读回执的 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。
type会话类型, 详见 ConversationType
pageSize每页获取的条数。
startMsgId漫游消息的开始消息 ID,如果为空,从最新的消息向前开始获取。
返回
返回消息列表和用于继续获取历史消息的 Cursor。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ 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。
type会话类型, 详见 ConversationType
pageSize每页获取的条数。
startMsgId漫游消息的开始消息 ID,如果为空,根据 direction , 当检索方向为 io.agora.chat.Conversation.SearchDirection#UP 时, 从最新的消息向前开始获取;当检索方向为 io.agora.chat.Conversation.SearchDirection#DOWN 时, 从最旧的消息向后开始获取。
direction漫游消息检索方向,io.agora.chat.Conversation.SearchDirection#UP为检索 时间戳消息小于开始消息时间戳的消息,io.agora.chat.Conversation.SearchDirection#DOWN 为检索时间戳消息大于开始消息时间戳的消息。
返回
返回消息列表和用于继续获取历史消息的 Cursor。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ fetchSupportLanguages()

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

获取翻译服务支持的语言

参数
callBack完成回调

◆ getAllConversations()

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

从本地获取当前所有的会话。

先从内存中加载,如果内存中没有再从数据库中加载。

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

◆ 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。
type会话类型。
返回
根据指定 ID 以及会话类型找到的会话对象,没有找到会返回空值。

◆ getConversation() [3/4]

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

根据用户或群组 ID 以及会话类型获取会话。

没有找到的话,可以根据 createIfNotExists 的值返回一个新建对象或者空对象。

参数
username会话 ID。
type会话类型。
createIfNotExists没找到相应会话时是否自动创建。
  • true 表示没有找到相应会话时会自动创建会话;
  • false 表示没有找到相应会话时不创建会话。
返回
根据指定 ID 以及会话类型找到的会话对象,如果没有找到会返回空值。

◆ getConversation() [4/4]

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

根据用户或群组id以及会话类型获取会话。

没有找到的话,根据createIfNotExists的值返回一个新建对象或者空对象。

参数
username会话ID。
type会话类型。
createIfNotExists没找到相应会话时是否自动创建。
  • true 表示没有找到相应会话时会自动创建会话;
    • false 表示没有找到相应会话时不创建会话。
isChatThread是否查找子区会话。
  • true 表示查找子区会话;
    • false 表示不查找子区会话。
返回
根据指定 ID 以及会话类型找到的会话对象,如果没有找到会返回空值。 ChatManager#getConversation(String, ConversationType, boolean, boolean)

◆ 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查询 cursor。
pageSize每页获取的 Reaction 条数。
cursor返回 cursor 和 MessageReaction 列表(仅使用该列表第一个数据即可)。cursor 为空值说明数据已全部获取到。
返回
CursorResult 包含 cursor(cursor 为空表示数据已全部获取)和 MessageReaction 列表。

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

获取未读消息数。

返回
未读消息数。

◆ getUnreadMsgsCount()

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

获取未读消息数。

返回
未读消息数。
弃用:
使用 ChatManager#getUnreadMessageCount() 替代。

◆ importMessages()

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

向消息数据库导入多条聊天记录。 在调用此函数时要保证,消息的发送方或者接收方是当前用户。 已经对函数做过速度优化,推荐一次导入 1,000 条以内的数据。

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

◆ loadAllConversations()

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

从数据库加载本地所有的会话到内存中。 一般在登录成功后使用此方法,可以加快会话列表的加载速度。

◆ markAllConversationsAsRead()

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

把所有的会话都设成已读。

这里针对的是本地会话。

◆ recallMessage()

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

撤回发送成功的消息。

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

参数
message消息对象。
异常
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

◆ 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  reportTarget,
String  reportReason 
) throws ChatException

举报违规消息。

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

参数
msgId违规的消息id。
reportTarget举报类型(例如:涉黄、涉恐)
reportReason举报原因。
异常
ChatException如果有异常会在这里抛出,包含错误码和错误描述,详见 Error

◆ saveMessage()

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

保存消息到本地。 比如系统提示消息会存到内存中的会话和数据库。

注意: CMD 类型数据不保存在本地。

参数
message待存储的消息。

◆ searchMsgFromDB() [1/2]

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

根据传入的参数从本地存储中搜索指定数量的消息。

注意:当 maxCount 非常大时,需要考虑内存消耗,目前限制一次最多搜索 400 条数据。

参数
type消息类型,文本、图片、语音、视频等,详见 ChatMessage.Type
timeStamp搜索消息的时间点,Unix 时间戳。
maxCount搜索结果的最大条数。
from搜索来自某人或者某群的消息,一般是指会话 ID。
返回
消息列表。

◆ searchMsgFromDB() [2/2]

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

根据传入的参数从本地存储中搜索指定数量的消息。

注意:当 maxCount 非常大时,需要考虑内存消耗,目前限制一次最多搜索 400 条数据。

参数
keywords搜索消息中的关键词。
timeStamp搜索消息的时间点。
maxCount一次搜索结果的最大条数。
from搜索来自某人或者某群的消息,一般是指会话 ID。
返回
消息列表。

◆ sendMessage()

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

发送消息。

参考: 如果是语音,图片类等有附件的消息,SDK 会自动上传附件。 可以通过 ChatOptions#setAutoTransferMessageAttachments(boolean) 设置是否上传到聊天服务器。

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

参数
msg待发送消息对象,不能为空。

◆ setMessageListened()

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

将消息设置为已听。 一般用于语音消息。

参数
message要设置的消息对象。
弃用:
请使用 ChatManager#setVoiceMessageListened(ChatMessage) 替代。

◆ 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要翻译的目标语言code列表
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

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