Chat SDK for Unity and Windows v1.2.0
Public Member Functions | List of all members
AgoraChat.ChatManager Class Reference
Inheritance diagram for AgoraChat.ChatManager:

Public Member Functions

bool DeleteConversation (string conversationId, bool deleteMessages=true)
 
void DownloadAttachment (string messageId, CallBack callback=null)
 
void DownloadThumbnail (string messageId, CallBack callback=null)
 
void FetchHistoryMessagesFromServer (string conversationId, ConversationType type=ConversationType.Chat, string startMessageId=null, int count=20, MessageSearchDirection direction=MessageSearchDirection.UP, ValueCallBack< CursorResult< Message > > callback=null)
 
void FetchHistoryMessagesFromServerBy (string conversationId, ConversationType type=ConversationType.Chat, string cursor=null, int pageSize=10, FetchServerMessagesOption option=null, ValueCallBack< CursorResult< Message > > callback=null)
 
Conversation GetConversation (string conversationId, ConversationType type=ConversationType.Chat, bool createIfNeed=true)
 
Conversation GetThreadConversation (string threadId)
 
void GetConversationsFromServer (ValueCallBack< List< Conversation > > callback=null)
 
void GetConversationsFromServerWithCursor (bool pinOnly, string cursor="", int limit=20, ValueCallBack< CursorResult< Conversation > > callback=null)
 
int GetUnreadMessageCount ()
 
void ImportMessages (List< Message > messages, CallBack callback=null)
 
List< ConversationLoadAllConversations ()
 
Message LoadMessage (string messageId)
 
bool MarkAllConversationsAsRead ()
 
void RecallMessage (string messageId, CallBack callback=null)
 
Message ResendMessage (string messageId, CallBack callback=null)
 
List< MessageSearchMsgFromDB (string keywords, long timestamp=0, int maxCount=20, string from=null, MessageSearchDirection direction=MessageSearchDirection.UP)
 
void SendConversationReadAck (string conversationId, CallBack callback=null)
 
void SendMessage (ref Message message, CallBack callback=null)
 
void SendMessageReadAck (string messageId, CallBack callback=null)
 
void SendReadAckForGroupMessage (string messageId, string ackContent, CallBack callback=null)
 
bool UpdateMessage (Message message)
 
void ModifyMessage (string messageId, MessageBody.TextBody body, ValueCallBack< Message > callback=null)
 
void RemoveMessagesBeforeTimestamp (long timeStamp, CallBack callback=null)
 
void DeleteConversationFromServer (string conversationId, ConversationType conversationType, bool isDeleteServerMessages, CallBack callback=null)
 
void FetchSupportLanguages (ValueCallBack< List< SupportLanguage > > callback=null)
 
void TranslateMessage (Message message, List< string > targetLanguages, ValueCallBack< Message > callback=null)
 
void FetchGroupReadAcks (string messageId, string groupId, int pageSize=20, string startAckId=null, ValueCallBack< CursorResult< GroupReadAck > > callback=null)
 
void ReportMessage (string messageId, string tag, string reason, CallBack callback=null)
 
void AddReaction (string messageId, string reaction, CallBack callback=null)
 
void RemoveReaction (string messageId, string reaction, CallBack callback=null)
 
void GetReactionList (List< string > messageIdList, MessageType chatType, string groupId, ValueCallBack< Dictionary< string, List< MessageReaction > > > callback=null)
 
void GetReactionDetail (string messageId, string reaction, string cursor=null, int pageSize=20, ValueCallBack< CursorResult< MessageReaction > > callback=null)
 
void GetConversationsFromServerWithPage (int pageNum, int pageSize, ValueCallBack< List< Conversation > > callback=null)
 
void RemoveMessagesFromServer (string conversationId, ConversationType conversationType, List< string > messageIdList, CallBack callback=null)
 
void RemoveMessagesFromServer (string conversationId, ConversationType conversationType, long timeStamp, CallBack callback=null)
 
void PinConversation (string conversationId, bool isPinned, CallBack callback=null)
 
void FetchCombineMessageDetail (Message msg, ValueCallBack< List< Message > > callback=null)
 
void AddChatManagerDelegate (IChatManagerDelegate chatManagerDelegate)
 
void RemoveChatManagerDelegate (IChatManagerDelegate chatManagerDelegate)
 

Member Function Documentation

◆ DeleteConversation()

bool AgoraChat.ChatManager.DeleteConversation ( string  conversationId,
bool  deleteMessages = true 
)

Deletes a conversation from the local database.

If you set deleteMessages to true, local historical messages will be deleted with the conversation.

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

◆ DownloadAttachment()

void AgoraChat.ChatManager.DownloadAttachment ( string  messageId,
CallBack  callback = null 
)

Downloads the message attachment.

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

Parameters
messageIdThe ID of the message with the attachment to be downloaded.
callbackThe download status callback. See CallBack.

◆ DownloadThumbnail()

void AgoraChat.ChatManager.DownloadThumbnail ( string  messageId,
CallBack  callback = null 
)

Downloads the message thumbnail.

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

Parameters
messageIdThe ID of the message with the thumbnail to be downloaded.
callbackThe download status callback. See CallBack.

◆ FetchHistoryMessagesFromServer()

void AgoraChat.ChatManager.FetchHistoryMessagesFromServer ( string  conversationId,
ConversationType  type = ConversationType.Chat,
string  startMessageId = null,
int  count = 20,
MessageSearchDirection  direction = MessageSearchDirection.UP,
ValueCallBack< CursorResult< Message > >  callback = null 
)

Gets historical messages of the conversation from the server.

Historical messages of a conversation can also be obtained with pagination.

This is an asynchronous method.

Parameters
conversationIdThe conversation ID.
typeThe conversation type. See ConversationType.
startMessageIdThe starting message ID for the query. If null is passed, the SDK gets messages in the reverse chronological order of when the server received the messages.
countThe number of messages that you expect to get on each page.
directionThe direction in which the message is fetched. MessageSearchDirection can be set with following:
  • UP: fetch messages before the timestamp of the specified message ID;
  • DOWN: fetch messages after the timestamp of the specified message ID.
callbackThe result callback. Returns the list of obtained messages.

◆ FetchHistoryMessagesFromServerBy()

void AgoraChat.ChatManager.FetchHistoryMessagesFromServerBy ( string  conversationId,
ConversationType  type = ConversationType.Chat,
string  cursor = null,
int  pageSize = 10,
FetchServerMessagesOption  option = null,
ValueCallBack< CursorResult< Message > >  callback = null 
)

Gets historical messages of a conversation from the server according the parameter configuration class for pulling historical messages FetchServerMessagesOption.

Historical messages of a conversation can be obtained with pagination.

This is an asynchronous method.

Parameters
conversationIdThe conversation ID.
typeThe conversation type. See ConversationType.
cursorThe cursor position from which to start querying data.
pageSizeThe number of messages that you expect to get on each page. The value range is [1,50].
optionThe parameter configuration class for pulling historical messages from the server. See FetchServerMessagesOption.
callbackThe result callback. The SDK returns the list of obtained messages.

◆ GetConversation()

Conversation AgoraChat.ChatManager.GetConversation ( string  conversationId,
ConversationType  type = ConversationType.Chat,
bool  createIfNeed = true 
)

Gets the local conversation object.

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

Parameters
conversationIdThe conversation ID.
typeThe conversation type. See ConversationType.
createIfNeedWhether to automatically create a conversation if the conversation is not found.
  • true: Yes.
  • false: No.
Returns
The conversation found. Returns null if the conversation is not found.

◆ GetThreadConversation()

Conversation AgoraChat.ChatManager.GetThreadConversation ( string  threadId)

Gets the local thread conversation object.

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

Parameters
threadIdThe threadId ID.
Returns
The conversation found. Returns null if the conversation is not found.

◆ GetConversationsFromServer()

void AgoraChat.ChatManager.GetConversationsFromServer ( ValueCallBack< List< Conversation > >  callback = null)

Gets all conversations from the server.

An empty list will be returned if no conversation is found.

Parameters
callbackThe list of obtained conversations. See ValueCallBack.

◆ GetConversationsFromServerWithCursor()

void AgoraChat.ChatManager.GetConversationsFromServerWithCursor ( bool  pinOnly,
string  cursor = "",
int  limit = 20,
ValueCallBack< CursorResult< Conversation > >  callback = null 
)

Gets the conversations from the server.

Parameters
pingOnlyWhether to return pinned conversations only:
  • true: Yes. The SDK only returns pinned conversations in the reverse chronological order of their pinning.
  • false: No.
cursorThe position from which to start getting data.
limitThe number of conversations that you expect to get on each page. The value range is [1,50].
callbackThe list of obtained conversations. See ValueCallBack.

◆ GetUnreadMessageCount()

int AgoraChat.ChatManager.GetUnreadMessageCount ( )

Gets the unread message count.

Returns
The count of unread messages.

◆ ImportMessages()

void AgoraChat.ChatManager.ImportMessages ( List< Message messages,
CallBack  callback = null 
)

Imports messages to the local database.

You can only import messages that you sent or received.

Parameters
messagesThe messages to be imported.
Returns
Whether messages are successfully imported to the local database.
  • true: Yes.
  • false: No.

◆ LoadAllConversations()

List< Conversation > AgoraChat.ChatManager.LoadAllConversations ( )

Loads all conversations from the local database into the memory.

To accelerate the loading, call this method immediately after the user is logged in.

Returns
The list of loaded conversations.

◆ LoadMessage()

Message AgoraChat.ChatManager.LoadMessage ( string  messageId)

Loads a specified message from the local database into the memory.

Parameters
messageIdThe ID of the message to be loaded.
Returns
The loaded message object.

◆ MarkAllConversationsAsRead()

bool AgoraChat.ChatManager.MarkAllConversationsAsRead ( )

Marks all local conversations as read.

Returns
Whether all local conversations are marked as read.
  • true: Yes.
  • false: No.

◆ RecallMessage()

void AgoraChat.ChatManager.RecallMessage ( string  messageId,
CallBack  callback = null 
)

Recalls the message.

This is an asynchronous method.

Parameters
messageThe ID of the message to be recalled.
callbackThe recall status callback. See CallBack.

◆ ResendMessage()

Message AgoraChat.ChatManager.ResendMessage ( string  messageId,
CallBack  callback = null 
)

Resends the message.[Deprecated]

This is an asynchronous method.

Parameters
messageThe ID of the message to be resent.
callbackThe resending status callback. See CallBack.
Returns
The message that is resent.

◆ SearchMsgFromDB()

List< Message > AgoraChat.ChatManager.SearchMsgFromDB ( string  keywords,
long  timestamp = 0,
int  maxCount = 20,
string  from = null,
MessageSearchDirection  direction = MessageSearchDirection.UP 
)

Queries local messages.

Note If you want to query a great number of messages, pay attention to the memory consumption. A maximum number of 200 messages can be retrieved each time.

Parameters
keywordsThe keyword for query. The data format is String.
timestampThe Unix timestamp for query, which is in milliseconds.
maxCountThe maximum number of messages to retrieve.
fromThe message source, which is usually a conversation ID.
directionThe query direction. See MessageSearchDirection.
Returns
The list of messages.

◆ SendConversationReadAck()

void AgoraChat.ChatManager.SendConversationReadAck ( string  conversationId,
CallBack  callback = null 
)

Sends the conversation read receipt to the server. After this method is called, the sever will set the message status from unread to read. The SDK triggers the IChatManagerDelegate#OnConversationRead(string from, string to) callback on the message sender's client, notifying that the messages are read. This also applies to multi-device scenarios.

Parameters
conversationIdThe conversation ID.
callbackThe result callback. See CallBack.

◆ SendMessage()

void AgoraChat.ChatManager.SendMessage ( ref Message  message,
CallBack  callback = null 
)

Sends a message。

This is an asynchronous method.

For attachment messages such as voice or image, the SDK will automatically upload the attachment by default. See Options#ServerTransfer.

Parameters
msgThe message object to be sent. Ensure that you set this parameter.
callbackThe result callback. See CallBack.

◆ SendMessageReadAck()

void AgoraChat.ChatManager.SendMessageReadAck ( string  messageId,
CallBack  callback = null 
)

Sends the read receipt of a message to the server.

After this method is called, the sever will set the message status from unread to read.

The SDK triggers the IChatManagerDelegate#OnMessagesRead(List<Message>) callback on the message sender's client, notifying that the messages are read. This also applies to multi-device scenarios.

Parameters
messageIdThe message ID.
callbackThe result callback. SeeCallBack.

◆ SendReadAckForGroupMessage()

void AgoraChat.ChatManager.SendReadAckForGroupMessage ( string  messageId,
string  ackContent,
CallBack  callback = null 
)

Sends the group message receipt to the server.

You can only call the method after setting the following method: Options#RequireAck(boolean) and Message#IsNeedGroupAck(boolean).

Reference: To send the one-to-one chat message receipt to server, call SendMessageReadAck(String); To send the conversation receipt to the server, call SendConversationReadAck(String).

Parameters
messageIdThe message ID.
ackContentThe ack content information. Developer self-defined command string that can be used for specifying custom action/command.
callbackThe result callback. SeeCallBack.

◆ UpdateMessage()

bool AgoraChat.ChatManager.UpdateMessage ( Message  message)

Updates the local message.

After this method is called, messages in both the local memory and local database will be updated.

Parameters
messageThe message object to update.
Returns
Whether the local message is successfully updated.
  • true: Yes.
  • false: No.

◆ ModifyMessage()

void AgoraChat.ChatManager.ModifyMessage ( string  messageId,
MessageBody.TextBody  body,
ValueCallBack< Message callback = null 
)

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.

Parameters
messageIdThe ID of the message to modify.
bodyThe modified message body.
callBackThe result callback. See CallBack().

◆ RemoveMessagesBeforeTimestamp()

void AgoraChat.ChatManager.RemoveMessagesBeforeTimestamp ( long  timeStamp,
CallBack  callback = null 
)

Removes messages that are sent and received before the Unix timestamp from the local memory and database.

Parameters
timeStampThe starting Unix timestamp for removal.
callbackThe removal result callback. See CallBack.

◆ DeleteConversationFromServer()

void AgoraChat.ChatManager.DeleteConversationFromServer ( string  conversationId,
ConversationType  conversationType,
bool  isDeleteServerMessages,
CallBack  callback = null 
)

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

This is an asynchronous method.

Parameters
conversationIdThe conversation ID.
conversationTypeThe conversation type. See ConversationType.
isDeleteServerMessagesWhether to delete the historical messages with the conversation.
  • true: Yes.
  • false: No.
callbackCallback for whether the conversation is deleted. See CallBack.

◆ FetchSupportLanguages()

void AgoraChat.ChatManager.FetchSupportLanguages ( ValueCallBack< List< SupportLanguage > >  callback = null)

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

Parameters
callBack完成的回调,详见 ValueCallBack()

Fetches all languages what the translate service supports.

Parameters
callBackThe result callback,see ValueCallBack().

◆ TranslateMessage()

void AgoraChat.ChatManager.TranslateMessage ( Message  message,
List< string >  targetLanguages,
ValueCallBack< Message callback = null 
)

Translates a message.

Parameters
messageThe message object.
languagesThe list of the target languages.
callBackThe result callback,see CallBack().

◆ FetchGroupReadAcks()

void AgoraChat.ChatManager.FetchGroupReadAcks ( string  messageId,
string  groupId,
int  pageSize = 20,
string  startAckId = null,
ValueCallBack< CursorResult< GroupReadAck > >  callback = null 
)

Fetches the ack details for group messages from server.

Fetches by page.

Reference: If you want to send group message receipt, see SendReadAckForGroupMessage.

This is an asynchronous method.

Parameters
msgIdThe message ID.
groupIdThe group ID。
pageSizeThe number of records per page.
startAckIdThe start ID for fetch receipts, can be null. If you set it as null, the SDK will start from the server's latest receipt.
callBackThe result callback, if successful, the SDK will execute the method ValueCallBack#onSuccess(Object), if the call failed, the SDK will execute the method ValueCallBack#onError(int, String).

◆ ReportMessage()

void AgoraChat.ChatManager.ReportMessage ( string  messageId,
string  tag,
string  reason,
CallBack  callback = null 
)

Reports a violation message.

Parameters
messageIdThe ID of the message to report.
tagThe tag of the inappropriate message. You need to type a custom tag, like porn or ad.
reasonThe reporting reason. You need to type a specific reason.
callBackThe result callback,see CallBack().

◆ AddReaction()

void AgoraChat.ChatManager.AddReaction ( string  messageId,
string  reaction,
CallBack  callback = null 
)

Adds a reaction.

This is an asynchronous method.

Parameters
messageIdThe message ID.
reactionThe message reaction.
callbackThe result callback which contains the error information if the method fails.

◆ RemoveReaction()

void AgoraChat.ChatManager.RemoveReaction ( string  messageId,
string  reaction,
CallBack  callback = null 
)

Deletes a reaction.

This is an asynchronous method.

Parameters
messageIdThe message ID.
reactionThe reaction content.
callbackThe result callback which contains the error information if the method fails.

◆ GetReactionList()

void AgoraChat.ChatManager.GetReactionList ( List< string >  messageIdList,
MessageType  chatType,
string  groupId,
ValueCallBack< Dictionary< string, List< MessageReaction > > >  callback = null 
)

Gets the list of Reactions.

This is an asynchronous method.

Parameters
messageIdListThe message ID.
chatTypeThe chat type. Only one-to-one chat (ConversationType.Chat and group chat (ConversationType.Group) are allowed.
groupIdThe group ID, which is valid only when the chat type is group chat.
callbackThe result callback, which contains the Reaction list under the specified message ID(The user list of EMMessageReaction is the summary data, which only contains the information of the first three users).

◆ GetReactionDetail()

void AgoraChat.ChatManager.GetReactionDetail ( string  messageId,
string  reaction,
string  cursor = null,
int  pageSize = 20,
ValueCallBack< CursorResult< MessageReaction > >  callback = null 
)

Gets the reaction details.

This is an asynchronous method.

Parameters
messageIdThe message ID.
reactionThe reaction content.
cursorThe query cursor.
pageSizeThe number of Reactions you expect to get on each page.
callbackThe result callback, which contains the reaction list obtained from the server and the cursor for the next query. Returns null if all the data is fetched.

◆ GetConversationsFromServerWithPage()

void AgoraChat.ChatManager.GetConversationsFromServerWithPage ( int  pageNum,
int  pageSize,
ValueCallBack< List< Conversation > >  callback = null 
)

Gets the conversations from the server.

An empty list will be returned if no conversation is found.

Parameters
pageNumThe current page number.
pageSizeThe number of conversations to get on each page.
callbackThe list of obtained conversations. See ValueCallBack.

◆ RemoveMessagesFromServer() [1/2]

void AgoraChat.ChatManager.RemoveMessagesFromServer ( string  conversationId,
ConversationType  conversationType,
List< string >  messageIdList,
CallBack  callback = null 
)

Removes messages in a conversation (from both local storage and the server).

This is an asynchronous method.

Parameters
conversationIdThe conversation ID.
conversationTypeThe conversation type. See ConversationType.
messageIdListThe list of IDs of messages to be removed.
callbackCallback for the operation. See CallBack.

◆ RemoveMessagesFromServer() [2/2]

void AgoraChat.ChatManager.RemoveMessagesFromServer ( string  conversationId,
ConversationType  conversationType,
long  timeStamp,
CallBack  callback = null 
)

Removes messages in a conversation (from both local storage and the server).

This is an asynchronous method.

Parameters
conversationIdThe conversation ID.
conversationTypeThe conversation type. See ConversationType.
timeStampThe specified Unix timestamp in miliseconds. Messages with a timestamp before the specified one will be removed from the conversation.
callbackCallback for the operation. See CallBack.

◆ PinConversation()

void AgoraChat.ChatManager.PinConversation ( string  conversationId,
bool  isPinned,
CallBack  callback = null 
)

Set the conversation pin or not.

This is an asynchronous method.

Parameters
conversationIdThe conversation ID.
isPinnedPin the conversation or not.
callbackCallback for the operation. See CallBack.

◆ FetchCombineMessageDetail()

void AgoraChat.ChatManager.FetchCombineMessageDetail ( Message  msg,
ValueCallBack< List< Message > >  callback = null 
)

Gets and parses the combined message.

Parameters
msgThe combined message to get and parse.
callbackIf success, a list of original messages included in the combined message are returned; otherwise, an error is returned. See ValueCallBack.

◆ AddChatManagerDelegate()

void AgoraChat.ChatManager.AddChatManagerDelegate ( IChatManagerDelegate  chatManagerDelegate)

Adds a chat manager listener.

Parameters
chatManagerDelegateThe chat manager listener to add. It is inherited from IChatManagerDelegate.

◆ RemoveChatManagerDelegate()

void AgoraChat.ChatManager.RemoveChatManagerDelegate ( IChatManagerDelegate  chatManagerDelegate)

移除聊天管理器的监听器。

Parameters
chatManagerDelegate要移除的聊天管理器的监听器,继承自 IChatManagerDelegate

Removes a chat manager listener.

Parameters
chatManagerDelegateThe chat manager listener to remove. It is inherited from IChatManagerDelegate.