Chat SDK for Android v1.3.1
agora java chat SDK
Classes | Public Member Functions | Static Public Member Functions | List of all members
io.agora.chat.Conversation Class Reference

Inherits io.agora.chat.EMBase< T >.

Classes

enum  ChatMessageSearchScope
 
enum  ConversationType
 
enum  EMMarkType
 
enum  SearchDirection
 

Public Member Functions

Set< EMMarkTypemarks ()
 
String conversationId ()
 
ConversationType getType ()
 
int getUnreadMsgCount ()
 
void markAllMessagesAsRead ()
 
int getAllMsgCount ()
 
int getAllMsgCount (long startTimestamp, long endTimestamp)
 
boolean isChatThread ()
 
List< ChatMessageloadMoreMsgFromDB (String startMsgId, int pageSize)
 
List< ChatMessageloadMoreMsgFromDB (String startMsgId, int pageSize, SearchDirection direction)
 
List< ChatMessagesearchMsgFromDB (long timeStamp, int maxCount, SearchDirection direction)
 
List< ChatMessagesearchMsgFromDB (Type type, long timeStamp, int maxCount, String from, SearchDirection direction)
 
List< ChatMessagesearchMsgFromDB (Set< Type > types, long timeStamp, int maxCount, String from, SearchDirection direction)
 
List< ChatMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, SearchDirection direction)
 
List< ChatMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, SearchDirection direction, ChatMessageSearchScope searchScope)
 
List< ChatMessagesearchMsgFromDB (long startTimeStamp, long endTimeStamp, int maxCount)
 
List< ChatMessagesearchCustomMsgFromDB (String keywords, long timeStamp, int maxCount, String from, SearchDirection direction)
 
ChatMessage getMessage (String messageId, boolean markAsRead)
 
void markMessageAsRead (String messageId)
 
List< ChatMessagegetAllMessages ()
 
void removeMessage (String messageId)
 
ChatMessage getLastMessage ()
 
ChatMessage getLatestMessageFromOthers ()
 
void clear ()
 
void clearAllMessages ()
 
void setExtField (String ext)
 
String getExtField ()
 
boolean isPinned ()
 
long getPinnedTime ()
 
boolean isGroup ()
 
boolean insertMessage (ChatMessage msg)
 
boolean appendMessage (ChatMessage msg)
 
boolean updateMessage (ChatMessage msg)
 
String getMessageAttachmentPath ()
 
void removeMessagesFromServer (List< String > msgIdList, CallBack callBack)
 
void removeMessagesFromServer (long beforeTimeStamp, CallBack callBack)
 
boolean removeMessages (long startTime, long endTime)
 
List< ChatMessagepinnedMessages ()
 
PushManager.PushRemindType pushRemindType ()
 

Static Public Member Functions

static ConversationType msgType2ConversationType (String id, ChatMessage.ChatType type)
 

Detailed Description

The conversation class, which defines one-to-one conversations, group conversations, and chat room conversations.

Each type of conversation involves messages that are sent and received.

The following code shows how to get the number of the unread messages from the conversation.

// ConversationId can be the ID of the peer user, the group ID, or the chat room ID:
Conversation conversation = ChatClient.getInstance().chatManager().getConversation(conversationId);
int unread = conversation.getUnreadMsgCount();
String conversationId()
Definition: Conversation.java:174

Member Function Documentation

◆ appendMessage()

boolean io.agora.chat.Conversation.appendMessage ( ChatMessage  msg)

Inserts a message to the end of the 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.

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

Parameters
msgThe message instance.

◆ clear()

void io.agora.chat.Conversation.clear ( )

Deletes all the messages in the conversation.

This method only deletes all the messages in a conversation in the memory, but not the messages in the local database.

When exiting a conversation, you need to clear the memory to reduce the memory consumption.

◆ clearAllMessages()

void io.agora.chat.Conversation.clearAllMessages ( )

Deletes all the messages in the conversation from the memory and local database.

◆ conversationId()

String io.agora.chat.Conversation.conversationId ( )

The conversation ID, which depends on the conversation type.

  • One-to-one chat/help desk: The conversation ID is the user ID of the peer user.
  • Group chat: The conversation ID is the group ID.
  • Chat room: The conversation ID is the chat room ID.
Returns
The conversation ID.

◆ getAllMessages()

List< ChatMessage > io.agora.chat.Conversation.getAllMessages ( )

Gets all messages of the conversation in the local memory.

If no message is found in the memory, the SDK will load the latest message from the local database.

Returns
The message list.

◆ getAllMsgCount() [1/2]

int io.agora.chat.Conversation.getAllMsgCount ( )

Gets the number of all messages in the conversation in the local database.

Returns
The number of all messages in the conversation.

◆ getAllMsgCount() [2/2]

int io.agora.chat.Conversation.getAllMsgCount ( long  startTimestamp,
long  endTimestamp 
)

Gets the number of all messages in the conversation in the local database within a specific time period.

Parameters
startTimestampThe start timestamp (inclusive) in milliseconds.
endTimestampThe end timestamp (inclusive) in milliseconds.
Returns
The number of all messages in the conversation within a specific time period.

◆ getExtField()

String io.agora.chat.Conversation.getExtField ( )

Gets the extension field of the conversation.

The extension field is only stored in the local database, but not synchronized to the server.

The extension field of a chat thread conversation is not saved in the local database.

Returns
The extension content.

◆ getLastMessage()

ChatMessage io.agora.chat.Conversation.getLastMessage ( )

Gets the latest message in the conversation.

A call to this method has no impact on the number of unread messages.

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

Returns
The message instance.

◆ getLatestMessageFromOthers()

ChatMessage io.agora.chat.Conversation.getLatestMessageFromOthers ( )

Gets the latest received message in the conversation.

Returns
The message instance.

◆ getMessage()

ChatMessage io.agora.chat.Conversation.getMessage ( String  messageId,
boolean  markAsRead 
)

Gets the message with message ID.

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

Parameters
messageIdThe message ID.
markAsReadWhether to mark the retrieved message as read.
  • true: Yes.
  • false: No.
Returns
message The retrieved message instance.

◆ getMessageAttachmentPath()

String io.agora.chat.Conversation.getMessageAttachmentPath ( )

Gets the path to save attachments in the conversation.

Before clearing conversation data, you can call this method to check the path to save attachments related to the conversation. If necessary, implement exception protection.

Returns
The path to save attachments in the conversation.

◆ getPinnedTime()

long io.agora.chat.Conversation.getPinnedTime ( )

Gets the time when the conversation is pinned.

Returns
The UNIX timestamp when the conversation is pinned. The unit is millisecond. This value is 0 when the conversation is not pinned.

◆ getType()

ConversationType io.agora.chat.Conversation.getType ( )

Gets the conversation type.

Returns
The conversation type.

◆ getUnreadMsgCount()

int io.agora.chat.Conversation.getUnreadMsgCount ( )

Gets the number of unread messages in the conversation.

Returns
The unread message count in the conversation.

◆ insertMessage()

boolean io.agora.chat.Conversation.insertMessage ( ChatMessage  msg)

Inserts a message to the 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
msgThe message instance.

◆ isChatThread()

boolean io.agora.chat.Conversation.isChatThread ( )

Checks whether the current conversation is a thread conversation.

Returns
Whether the conversation is a chat thread conversation.
  • true: Yes.
  • false: No.

◆ isGroup()

boolean io.agora.chat.Conversation.isGroup ( )

Checks whether it is a group conversation or a chat room conversation, or a conversation of another type.

Returns
Whether it is a group conversation or a chat room conversation, or a conversation of another type.
  • true: It is a group conversation or a chat room conversation.
  • false: It is not a group conversation or a chat room conversation.

◆ isPinned()

boolean io.agora.chat.Conversation.isPinned ( )

Checks whether the conversation is pinned.

Returns
Whether the conversation is pinned.
  • true: Yes.
  • false: No. The conversation is unpinned.

◆ loadMoreMsgFromDB() [1/2]

List< ChatMessage > io.agora.chat.Conversation.loadMoreMsgFromDB ( String  startMsgId,
int  pageSize 
)

Loads messages from the local database.

The loaded messages will be put in the conversation in the memory according to the timestamp in them and will be returned when you call getAllMessages().

Parameters
startMsgIdThe starting message ID for query. The SDK loads messages, starting from the specified one, in the descending order of the timestamp included in them. If this parameter is set as null or an empty string, the SDK retrieves messages, from the latest one, according to the descending order of the timestamp included in them.
pageSizeThe number of messages that you expect to get on each page. The value range is [1,400].
Returns
The list of retrieved messages (excluding the one with the starting ID).

◆ loadMoreMsgFromDB() [2/2]

List< ChatMessage > io.agora.chat.Conversation.loadMoreMsgFromDB ( String  startMsgId,
int  pageSize,
SearchDirection  direction 
)

Loads the messages from the local database, starting from a specific message ID.

The loaded messages will be put in the conversation in the memory according to the timestamp included in them.

Parameters
startMsgIdThe starting message ID for query. After this parameter is set, the SDK retrieves messages, from the specified one, according to the message search direction. If this parameter is set as nil, the SDK retrieves messages according to the search direction while ignoring this parameter.
  • If direction is set as UP, the SDK retrieves messages, starting from the latest one, in the descending order of the timestamp included in them.
  • If direction is set as DOWN, the SDK retrieves messages, starting from the oldest one, in the ascending order of the timestamp included in them.
pageSizeThe number of messages that you expect to get on each page. The value range is [1,400].
directionThe message search direction. See SearchDirection.
  • 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 ID).

◆ markAllMessagesAsRead()

void io.agora.chat.Conversation.markAllMessagesAsRead ( )

Marks all unread messages as read.

◆ markMessageAsRead()

void io.agora.chat.Conversation.markMessageAsRead ( String  messageId)

Marks a message as read.

You can also call ChatMessage#setUnread(boolean) to mark the message as read.

Parameters
messageIdThe message ID.

◆ marks()

Set< EMMarkType > io.agora.chat.Conversation.marks ( )

Gets all marks for the conversation.

Returns
All marks for the conversation.

◆ msgType2ConversationType()

static ConversationType io.agora.chat.Conversation.msgType2ConversationType ( String  id,
ChatMessage.ChatType  type 
)
static

Converts a message type to a conversation type.

Parameters
idThe message ID.
typeThe message type.
Returns
The conversation type.

◆ pinnedMessages()

List< ChatMessage > io.agora.chat.Conversation.pinnedMessages ( )

Gets the list of pinned messages in a local conversation.

Returns
All pinned messages in the conversation.

◆ pushRemindType()

PushManager.PushRemindType io.agora.chat.Conversation.pushRemindType ( )

Gets the push reminder type of the conversation.

Returns
The push reminder type of the conversation.

◆ removeMessage()

void io.agora.chat.Conversation.removeMessage ( String  messageId)

Deletes a message in the local database.

Parameters
messageIdThe ID of the message to delete.

◆ removeMessages()

boolean io.agora.chat.Conversation.removeMessages ( 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 deletion succeeds:
  • If the operation succeeds, the SDK returns true.
  • If the operation fails, the SDK returns false.

◆ removeMessagesFromServer() [1/2]

void io.agora.chat.Conversation.removeMessagesFromServer ( List< String >  msgIdList,
CallBack  callBack 
)

Deletes historical messages from the server unidirectionally by message ID.

Parameters
msgIdListThe list of IDs of messages to be deleted from the server unidirectionally.
callBackThe result callback which contains the error information if the method fails. See CallBack.

◆ removeMessagesFromServer() [2/2]

void io.agora.chat.Conversation.removeMessagesFromServer ( long  beforeTimeStamp,
CallBack  callBack 
)

Deletes historical messages from the server unidirectionally by timestamp.

Parameters
beforeTimeStampThe starting UNIX timestamp for unidirectional message deletion. The unit is millisecond. After the timestamp is set, this method deletes messages that are received by the server before the specified timestamp.
callBackThe result callback which contains the error information if the method fails. See CallBack.

◆ searchCustomMsgFromDB()

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

Gets custom messages with keywords that the specified user sends in the conversation.

Note: Be cautious about memory usage when the maxCount is large.

Parameters
keywordsThe keywords for search.
timeStampTThe 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 this parameter is set as a negative value, the SDK retrieves from the current time.
maxCountThe maximum number of messages to retrieve. The value range is [1,400].
fromThe user ID of the message sender. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation, with no restriction on the message sender.
directionThe message search direction. See SearchDirection.
  • 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).

◆ searchMsgFromDB() [1/6]

List< ChatMessage > io.agora.chat.Conversation.searchMsgFromDB ( long  startTimeStamp,
long  endTimeStamp,
int  maxCount 
)

Gets a certain quantity of messages sent or received in a certain period from the local database.

Parameters
startTimeStampThe starting Unix timestamp in the message for query. The unit is millisecond. See ChatOptions#setSortMessageByServerTime.
endTimeStampThe ending Unix timestamp in the message for query. The unit is millisecond. See ChatOptions#setSortMessageByServerTime.
maxCountThe maximum number of messages to retrieve each time. The value range is [1,400].
Returns
The list of retrieved messages (excluding the ones with the starting timestamp and ending timestamp).

◆ searchMsgFromDB() [2/6]

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

Retrieves messages in the local database based on the Unix timestamp included in them.

Parameters
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 message to retrieve each time. The value range is [1,400].
directionThe message search direction. See SearchDirection.
  • 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).

◆ searchMsgFromDB() [3/6]

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

Gets messages of multiple types that a specified user sends in the conversation.

Parameters
typesThe message types. 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 this parameter is set as a negative value, the SDK retrieves from the latest message.
maxCountThe maximum number of messages to retrieve each time. The value range is [1,400].
fromThe user ID of the message sender. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation, with no restriction on the message sender.
directionThe message search direction. See SearchDirection.
  • 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).

◆ searchMsgFromDB() [4/6]

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

Gets messages with keywords that the specified user sends in the conversation.

Parameters
keywordsThe keywords for query.
timeStampThe starting Unix timestamp for search. The unit is millisecond. If this parameter is set as a negative value, the SDK retrieves from the current time.
maxCountThe maximum number of messages to retrieve each time. The value range is [1,400].
fromThe user ID of the message sender. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation, with no restriction on the message sender.
directionThe message search direction. See SearchDirection.
  • 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).

◆ searchMsgFromDB() [5/6]

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

Gets messages with keywords that the specified user sends in the conversation.

Parameters
keywordsThe keywords for query.
timeStampThe starting Unix timestamp for search. The unit is millisecond. If this parameter is set as a negative value, the SDK retrieves from the current time.
maxCountThe maximum number of messages to retrieve each time. The value range is [1,400]. If you set this parameter to 0 or less, the SDK gets one message from the local database.
fromThe user ID of the message sender. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation, with no restriction on the message sender.
directionThe message search direction. See SearchDirection.
  • 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.
searchScopeThe scope of search message. See ChatMessageSearchScope.
Returns
The list of retrieved messages (excluding the one with the starting timestamp).

◆ searchMsgFromDB() [6/6]

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

Gets messages of a certain type that a specified user sends in the conversation.

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 this parameter is set as a negative value, the SDK retrieves from the latest message.
maxCountThe maximum number of messages to retrieve each time. The value range is [1,400].
fromThe user ID of the message sender. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation, with no restriction on the message sender.
directionThe message search direction. See SearchDirection.
  • 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).

◆ setExtField()

void io.agora.chat.Conversation.setExtField ( String  ext)

Sets the extension field of the conversation.

The extension field is only stored in the local database, but not synchronized to the server.

The extension field of a chat thread conversation is not saved in the local database.

Parameters
extThe extension field of the conversation.

◆ updateMessage()

boolean io.agora.chat.Conversation.updateMessage ( ChatMessage  msg)

Updates a message in the local database.

After you update a message, the message ID remains unchanged and the SDK automatically updates attributes of the conversation, like latestMessage.

Parameters
msgThe message to update.

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