Chat SDK for Unity and Windows v1.2.1
Public Member Functions | Public Attributes | Properties | List of all members
AgoraChat.Conversation Class Reference
Inheritance diagram for AgoraChat.Conversation:

Public Member Functions

void MarkMessageAsRead (string messageId)
 
void MarkAllMessageAsRead ()
 
bool InsertMessage (Message message)
 
bool AppendMessage (Message message)
 
bool UpdateMessage (Message message)
 
bool DeleteMessage (string messageId)
 
bool DeleteMessages (long startTime, long endTime)
 
bool DeleteAllMessages ()
 
Message LoadMessage (string messageId)
 
void LoadMessagesWithMsgType (MessageBodyType type, string sender=null, long timestamp=-1, int count=20, MessageSearchDirection direction=MessageSearchDirection.UP, ValueCallBack< List< Message > > callback=null)
 
void LoadMessages (string startMessageId=null, int count=20, MessageSearchDirection direction=MessageSearchDirection.UP, ValueCallBack< List< Message > > callback=null)
 
void LoadMessagesWithKeyword (string keywords, string sender=null, long timestamp=-1, int count=20, MessageSearchDirection direction=MessageSearchDirection.UP, ValueCallBack< List< Message > > callback=null)
 
void LoadMessagesWithTime (long startTime, long endTime, int count=20, ValueCallBack< List< Message > > callback=null)
 
int MessagesCount ()
 

Public Attributes

string Id
 
ConversationType Type
 
bool IsThread
 
bool IsPinned
 
long PinnedTime
 

Properties

Message LastMessage [get]
 
Message LastReceivedMessage [get]
 
Dictionary< string, string > Ext [get, set]
 
int UnReadCount [get]
 

Member Function Documentation

◆ MarkMessageAsRead()

void AgoraChat.Conversation.MarkMessageAsRead ( string  messageId)

Marks a message as read.

Parameters
messageIdThe message ID.

◆ MarkAllMessageAsRead()

void AgoraChat.Conversation.MarkAllMessageAsRead ( )

Marks all unread messages in the conversation as read.

◆ InsertMessage()

bool AgoraChat.Conversation.InsertMessage ( Message  message)

Inserts a message into a conversation in the local database.

To insert the message correctly, ensure that the conversation ID of the message is the same as that of the conversation.

The message will be inserted based on the Unix timestamp included in it. Upon message insertion, the SDK will automatically update attributes of the conversation, including latestMessage.

Parameters
messageThe message instance.
Returns
Whether the message is successfully inserted.
  • true: Yes.
  • false: No.

◆ AppendMessage()

bool AgoraChat.Conversation.AppendMessage ( Message  message)

Inserts a message to the end of a conversation in the local database.

The conversation ID of the message should be the same as that of the conversation to make sure that the message is correctly inserted.

After a message is inserted, the SDK will automatically update attributes of the conversation, including latestMessage.

Parameters
messageThe message instance.
Returns
Whether the message is successfully inserted.
  • true: Yes.
  • false: No.

◆ UpdateMessage()

bool AgoraChat.Conversation.UpdateMessage ( Message  message)

Updates a message in the local database.

The ID of the message remains unchanged during message updates.

After a message is updated, the SDK will automatically update attributes of the conversation, including latestMessage.

Parameters
messageThe message to be updated.
Returns
Whether this message is successfully updated.
  • true: Yes.
  • false: No.

◆ DeleteMessage()

bool AgoraChat.Conversation.DeleteMessage ( string  messageId)

Deletes a message from the local database.

Parameters
messageIdThe ID of the message to be deleted.
Returns
Whether the message is successfully deleted.
  • true: Yes.
  • false: No.

◆ DeleteMessages()

bool AgoraChat.Conversation.DeleteMessages ( long  startTime,
long  endTime 
)

Deletes messages sent or received in a certain period from the local database.

Parameters
startTimeThe starting Unix timestamp for message deletion. The unit is millisecond.
endTimeThe ending Unix timestamp for message deletion. The unit is millisecond.
Returns
Whether the message is successfully deleted.
  • true: Yes.
  • false: No.

◆ DeleteAllMessages()

bool AgoraChat.Conversation.DeleteAllMessages ( )

Deletes all the messages in the conversation.

This method deletes all messages in the conversation from both the memory and the local database.

Returns
Whether messages are successfully deleted.
  • true: Yes.
  • false: No.

◆ LoadMessage()

Message AgoraChat.Conversation.LoadMessage ( string  messageId)

Loads a message. The SDK first retrieves the message from the memory. If no message is found, the SDK retrieves it from the local database and loads it.

Parameters
messageIdThe ID of the message to load.
Returns
The message instance. If the message is not found in both the local memory and local database, the SDK returns null.

◆ LoadMessagesWithMsgType()

void AgoraChat.Conversation.LoadMessagesWithMsgType ( MessageBodyType  type,
string  sender = null,
long  timestamp = -1,
int  count = 20,
MessageSearchDirection  direction = MessageSearchDirection.UP,
ValueCallBack< List< Message > >  callback = null 
)

Loads the messages of a specific type.

The SDK first retrieves the messages from the memory. If no message is found, the SDK will retrieve them from the local database and load them.

Parameters
typeThe type of messages to load. Ensure that you set this parameter.
senderThe user ID of the message sender. Ensure that you set this parameter.
timestampThe starting Unix timestamp for query. The default value is -1, indicating the current Unix timestamp.
countThe maximum number of messages to load. The default value is 20.
directionThe message loading direction. By default, the SDK loads messages in the reverse chronological order of the Unix timestamp (SortMessageByServerTime) in the message. See MessageSearchDirection.
callbackThe loading result callback. If success, a list of loaded messages are returned; otherwise, an error is returned. See ValueCallBack.

◆ LoadMessages()

void AgoraChat.Conversation.LoadMessages ( string  startMessageId = null,
int  count = 20,
MessageSearchDirection  direction = MessageSearchDirection.UP,
ValueCallBack< List< Message > >  callback = null 
)

Loads the messages, starting from a specific message ID.

The SDK first retrieves the messages from the memory. If no message is found, the SDK will retrieve them from the local database and load them.

Parameters
startMessageIdThe starting message ID for loading. If this parameter is set as "" or null, the SDK will load from the latest message.
countThe maximum number of messages to load. The default value is 20.
directionThe message loading direction. By default, the SDK loads messages in the reverse chronological order of the Unix timestamp (SortMessageByServerTime) in the messages. See MessageSearchDirection.
callbackThe loading result callback. If success, a list of loaded messages are returned; otherwise, an error is returned. See ValueCallBack.

◆ LoadMessagesWithKeyword()

void AgoraChat.Conversation.LoadMessagesWithKeyword ( string  keywords,
string  sender = null,
long  timestamp = -1,
int  count = 20,
MessageSearchDirection  direction = MessageSearchDirection.UP,
ValueCallBack< List< Message > >  callback = null 
)

Loads the messages by keywords.

The SDK first retrieves the messages from the memory. If no message is found, the SDK will retrieve them from the local database and load them.

Parameters
keywordsThe keywords for query.
senderThe user ID of the message sender.
timestampThe starting Unix timestamp for query. The default value is -1, indicating the current Unix timestamp.
countThe maximum number of messages to load. The default value is 20.
directionThe message loading direction. By default, the SDK loads messages in the reverse chronological order of the Unix timestamp (SortMessageByServerTime) in the messages. See MessageSearchDirection.
callbackThe loading result callback. If success, a list of loaded messages are returned; otherwise, an error is returned. See ValueCallBack.

◆ LoadMessagesWithTime()

void AgoraChat.Conversation.LoadMessagesWithTime ( long  startTime,
long  endTime,
int  count = 20,
ValueCallBack< List< Message > >  callback = null 
)

Loads the messages within a period.

Note

The SDK first retrieves the messages from the memory. If no message is found, the SDK will retrieve them from the local database and load them.

Pay attention to the memory usage when you load a great number of messages.

Parameters
startTimeStampThe starting Unix timestamp for query.
endTimeStampThe ending Unix timestamp for query.
countThe maximum number of messages to load. The default value is 20.
callbackThe loading result callback. If success, a list of loaded messages are returned; otherwise, an error is returned. See ValueCallBack.

◆ MessagesCount()

int AgoraChat.Conversation.MessagesCount ( )

Gets the count of all messages in this conversation in the local database.

Returns
The count of all the messages in this conversation.

Member Data Documentation

◆ Id

string AgoraChat.Conversation.Id

The conversation ID.

◆ Type

ConversationType AgoraChat.Conversation.Type

The conversation type.

◆ IsThread

bool AgoraChat.Conversation.IsThread

Whether a conversation is a thread conversation:

  • true: Yes.
  • false: No.

◆ IsPinned

bool AgoraChat.Conversation.IsPinned

Whether a conversation is pinned:

  • true: Yes.
  • false: No.

◆ PinnedTime

long AgoraChat.Conversation.PinnedTime

The timestamp when the conversation is pinned. The unit is millisecond.

If isPinned is false, 0 is returned.

Property Documentation

◆ LastMessage

Message AgoraChat.Conversation.LastMessage
get

Gets the latest message in the conversation.

A call of this method has no impact on the unread message count of the conversation.

The SDK first retrieves the latest message from the memory. If no message is found, the SDK retrieves it from the local database and loads it.

Returns
The message instance.

◆ LastReceivedMessage

Message AgoraChat.Conversation.LastReceivedMessage
get

Gets the latest message received in the conversation.

Returns
The message instance.

◆ Ext

Dictionary<string, string> AgoraChat.Conversation.Ext
getset

Gets the extension information of the conversation.

Returns
The extension information of the conversation.

◆ UnReadCount

int AgoraChat.Conversation.UnReadCount
get

Gets the count of unread messages in the conversation.

Returns
The count of unread messages.