agora_chat_SDK 1.0.6
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  ConversationType
 
class  MessageCache
 
enum  SearchDirection
 

Public Member Functions

String conversationId ()
 
ConversationType getType ()
 
int getUnreadMsgCount ()
 
void markAllMessagesAsRead ()
 
int getAllMsgCount ()
 
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 (ChatMessage.Type type, long timeStamp, int maxCount, String from, SearchDirection direction)
 
List< ChatMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, SearchDirection direction)
 
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)
 
List< ChatMessageloadMessages (List< String > msgIds)
 
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 isGroup ()
 
boolean insertMessage (ChatMessage msg)
 
boolean appendMessage (ChatMessage msg)
 
boolean updateMessage (ChatMessage msg)
 
String getMessageAttachmentPath ()
 

Static Public Member Functions

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

Detailed Description

The conversation class, which represents a conversation with a user/group/chat room and contains the 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 other party id, the group id, or the chat room id
Conversation conversation = ChatClient.getInstance().chatManager().getConversation(conversationId);
int unread = conversation.getUnreadMsgCount();
String conversationId()
Definition: Conversation.java:162

Member Function Documentation

◆ appendMessage()

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

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

The conversationId of the message should be the same as the conversationId of the conversation in order to insert the message into the conversation correctly. And the latestMessage and other properties of the session should be updated.

Parameters
msgThe message instance.

◆ clear()

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

Deletes all the messages in this conversation.

NOTE: The call only deletes all the messages in the memory cache, but not the messages in the local database.

You can reduce the memory consumption by clearing the memory cache when exiting a conversation.

◆ clearAllMessages()

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

Deletes all the messages of the conversation from the memory cache and local database.

◆ conversationId()

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

The conversation ID.

For one-to-one chat,the conversation ID is the same with the other side's name. For group chat, the conversation ID is the group ID, different with group name. For chat room, the conversation ID is the chatroom ID, different with chat room name. For help desk, it is the same with one-to-one chat, the conversation ID is also the other chat user's name.

Returns
The conversation ID.

◆ getAllMessages()

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

Gets all messages in the local cache.

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

Returns
The message list.

◆ getAllMsgCount()

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

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

Returns
The count of all the messages in this conversation.

◆ getExtField()

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

Gets the extension of the conversation.

The extend field only stored in the local database, not updated to the server.

Returns
The extension content.

◆ getLastMessage()

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

Gets the last message from the conversation.

The operation does not change the unread message count.

Gets from the cache first, if no message is found, loads from the local database and then put it in the cache.

Returns
The message instance.

◆ getLatestMessageFromOthers()

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

Gets the latest message from the conversation.

Returns
The message instance.

◆ getMessage()

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

Gets the message with message ID.

If the message already loaded into the memory cache, the message will be directly returned, otherwise the message will be loaded from the local database, and be set into the cache.

Parameters
messageIdThe message ID.
markAsReadWhether to mark the message as read while getting it.
  • true: The SDK will mark the message as read and send a read receipt to the server;
  • false: Do not mark the message as read.
Returns
message Returns the message instance.

◆ getMessageAttachmentPath()

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

Returns the attachment path associated with the conversation.

The path can be used to erase the conversation related files from the local storage.

Not ensure the path exists, please handle IOException when deleting directory.

Returns
The attachment path in the sdcard.

◆ 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 of the conversation.

Returns
The unread message count of the conversation.

◆ insertMessage()

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

Inserts a message to a conversation in local database and SDK will update the last message automatically.

The conversation ID of the message should be the same as conversation ID of the conversation in order to insert the message into the conversation correctly. The inserting message will be inserted based on timestamp.

Parameters
msgThe message instance.

◆ isGroup()

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

To check whether it is a group or chat room conversation.

Returns
If the conversation type is group or chatroom chat, the SDK returns true. Otherwise, the SDK returns false.

◆ loadMessages()

List< ChatMessage > io.agora.chat.Conversation.loadMessages ( List< String >  msgIds)

Loads a list of messages. If those messages don't exists in the memory cache, the memory cache will load message from the local database.

Parameters
msgIdsThe message IDs to be loaded.
Returns
Returns the message list, if the messages are not found, the SDK will return null.

◆ loadMoreMsgFromDB() [1/2]

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

Loads more messages from the local database. Loads messages from the local database before the specified message. The messages will also be stored in to current conversation's memory cache. So when next time calling getAllMessages(), the result will contain those messages.

Parameters
startMsgIdThe specified message ID. If the startMsgId is set as "" or null, the SDK will load latest messages in database.
pageSizeThe number of records in a page.
Returns
The message list.

◆ loadMoreMsgFromDB() [2/2]

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

Loads messages starting from the specified message id from the local database. The messages will also be stored in to the memory cache. So the next time calling getAllMessages(), the result will contain those messages.

Parameters
startMsgIdThe specified message ID. If the startMsgId is set as "" or null, the SDK will load latest messages in database.
pageSizeThe number of records in a page.
directionThe direction in which the message is loaded: ChatMessageSearchDirection.
  • ChatMessageSearchDirectionUp: get aCount of messages before the timestamp of the specified message ID;
  • ChatMessageSearchDirectionDown: get aCount of messages after the timestamp of the specified message ID.
Returns
␈The message list.

◆ markAllMessagesAsRead()

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

Marks all messages as read.

◆ markMessageAsRead()

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

Marks a message as read.

To mark the message read, you can also call ChatMessage#setUnread(boolean).

Parameters
messageIdThe message ID.

◆ msgType2ConversationType()

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

Provides a transformation from a message type to a conversation type.

Parameters
idThe message ID, used to distinguish one-to-one chat and the help desk chat, has no effect on other chat type.
typeThe message type.
Returns
The conversation type.

◆ removeMessage()

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

Deletes a message in the local database.

Note: Operates only on the local database.

Parameters
messageIdThe message to be deleted.

◆ searchCustomMsgFromDB()

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

Searches specifying custom messages from the local database based the parameters.

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

Parameters
keywordsThe keywords in message.
timeStampThe Unix timestamp to search.
maxCountThe max number of message to search.
fromThe message sender, the param can also be used to search in group chat.
directionThe direction in which the message is loaded: ChatMessageSearchDirection.
  • ChatMessageSearchDirectionUp: get aCount of messages before the timestamp of the specified message ID;
  • ChatMessageSearchDirectionDown: get aCount of messages after the timestamp of the specified message ID.
Returns
The message list.

◆ searchMsgFromDB() [1/4]

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

Searches messages from the local database according the following parameters: the message type, the Unix timestamp, maxcount, sender.

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

Parameters
typeThe message type, including TXT、VOICE、IMAGE and so on.
timeStampThe Unix timestamp for search.
maxCountThe max number of message to search.
fromThe sender of the message. The param can also be used to search in group chat.
directionThe direction in which the message is loaded: ChatMessageSearchDirection.
  • ChatMessageSearchDirectionUp: get aCount of messages before the timestamp of the specified message ID;
  • ChatMessageSearchDirectionDown: get aCount of messages after the timestamp of the specified message ID.
Returns
The message list.

◆ searchMsgFromDB() [2/4]

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

Searches specifying messages from the local database by the following parameters. Note: Be␈ cautious about memory usage when the maxCount is large.

Parameters
startTimeStampThe start Unix timestamp to search.
endTimeStampThe end Unix timestamp to search.
maxCountThe max number of message to search.
Returns
The message list.

◆ searchMsgFromDB() [3/4]

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

Searches messages from the local database according the following parameters.

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

Parameters
timeStampThe Unix timestamp when searching.
maxCountThe max number of message to search.
Returns
The message list.
Parameters
directionThe direction in which the message is loaded: ChatMessageSearchDirection.
  • ChatMessageSearchDirectionUp: get aCount of messages before the timestamp of the specified message ID;
  • ChatMessageSearchDirectionDown: get aCount of messages after the timestamp of the specified message ID.

◆ searchMsgFromDB() [4/4]

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

Searches messages from the local database by the following parameters: keywords, timestamp, maxcount, sender, search direction.

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

Parameters
keywordsThe keywords in message.
timeStampThe timestamp for search.
maxCountThe max number of message to search.
fromThe message sender. The param can also be used to search in group chat.
directionThe direction in which the message is loaded: ChatMessageSearchDirection.
  • ChatMessageSearchDirectionUp: get aCount of messages before the timestamp of the specified message ID;
  • ChatMessageSearchDirectionDown: get aCount of messages after the timestamp of the specified message ID.
Returns
The list of searched messages.

◆ setExtField()

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

Sets the extension of the conversation.

The extend field only stored in local database, not updated to the server.

Parameters
extThe extension string.

◆ updateMessage()

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

Uses this method to update a message in local database. Changing properties will affect data in database.

The latestMessage of the conversation and other properties will be updated accordingly. The messageID of the message cannot be updated.

Parameters
msgThe message to be updated.

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