agora_chat_SDK  3.8.2
agorajavachatSDK
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 ()
 
List< ChatMessageloadMoreMsgFromDB (String startMsgId, int pageSize)
 
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 ()
 
void insertMessage (ChatMessage msg)
 
void appendMessage (ChatMessage msg)
 
boolean updateMessage (ChatMessage msg)
 
String getMessageAttachmentPath ()
 

Static Public Member Functions

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

Detailed Description

Conversation class, represent a conversation with a user/group/chat room and contains messages that are sent and received For example, Gets the number of 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();
Version
3.0

Member Function Documentation

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

Insert a message to the end of a conversation in local database ConversationId of the message should be the same as 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
msgMessage
void io.agora.chat.Conversation.clear ( )

Clear messages in this conversation Which clear only memory messages, but will not clear local database Reduce memory consumption by clearing the memory cache when exiting a conversation

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

Delete all messages of the conversation from memory cache and local database

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

Conversation ID For single chat,conversation ID is to chat user's name For group chat, conversation ID is group ID, different with group name For chat room, conversation ID is chatroom ID, different with chat room name For help desk, it is same with single chat, conversationID is also chat user's name

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

Get all message in local cache If empty, then get latest message from local database

Returns
Message list
int io.agora.chat.Conversation.getAllMsgCount ( )

Get all messages count in this conversation

Returns
ALl messages count in this conversation
String io.agora.chat.Conversation.getExtField ( )

Get conversation extension Extend field only stored in local database, not sync to network server

Returns
Extension string
ChatMessage io.agora.chat.Conversation.getLastMessage ( )

Get last message from conversation The operation does not change the unread message count Get from cache, if empty, will load from database and put it in the cache

Returns
Message instance
ChatMessage io.agora.chat.Conversation.getLatestMessageFromOthers ( )

Get received latest message from conversation

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

Get message by message ID, If the message already loaded into memory cache, will directly return the message, otherwise load message from database, and put it into cache

Parameters
messageIdMessage id
markAsReadWhether to mark the message as read while getting it, if true, will mark the message as read and send read ack to server
Returns
message Return the message instance
String io.agora.chat.Conversation.getMessageAttachmentPath ( )

Return conversation associated attachment path Which can be used to erase conversation related downloaded files from local storage. Not ensure the return path exists, please handle IOException when deleting directory

Returns
Attachment path
ConversationType io.agora.chat.Conversation.getType ( )

Get conversation type

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

Get unread message count

Returns
Unread message count
void io.agora.chat.Conversation.insertMessage ( ChatMessage  msg)

Insert a message to a conversation in local database ConversationId of the message should be the same as 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
msgInstance of Message
boolean io.agora.chat.Conversation.isGroup ( )

Gets whether it is a group or chat room conversation

Returns
Group chat and chatroom chat will both return true, otherwise return false
List<ChatMessage> io.agora.chat.Conversation.loadMessages ( List< String >  msgIds)

Load messages, If those message not exists in memory in cache, will load message from database

Parameters
msgIdsmessage ids to be loaded
Returns
Return message list, if not find will return null
List<ChatMessage> io.agora.chat.Conversation.loadMoreMsgFromDB ( String  startMsgId,
int  pageSize 
)

Load more messages from database Load message from database by passing in parameters, which message id starting from param startMsgId, messages will also store in to current conversation's memory cache, so next time calling getAllMessages(), result will contain those messages

Parameters
startMsgIdmessage storage time will before this ID, if startMsgId is "" or null, will load last messages in database
pageSizemessage count to be loaded
Returns
messages
void io.agora.chat.Conversation.markAllMessagesAsRead ( )

Mark all messages as read

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

Mark the message as read by specified messageId To make the message read, you can also use ChatMessage#setUnread(boolean)

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

Provide transformation from message type to conversation type

Parameters
idMessage Id, used to distinguish single chat and help desk, has no effect on other chat type
typeMessage type
Returns
Conversation type
void io.agora.chat.Conversation.removeMessage ( String  messageId)

Delete a message Note: Operates only on local data

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

Search custom messages from database based the parameters Note: 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
fromWho the message from, also can used to search in group
Returns
The list of searched messages
List<ChatMessage> io.agora.chat.Conversation.searchMsgFromDB ( long  timeStamp,
int  maxCount,
SearchDirection  direction 
)

Search message from database according the parameters Note: Cautious about memory usage when the maxCount is large

Parameters
timeStampThe timestamp for search
maxCountThe max number of message to search
Returns
The list of searched messages
List<ChatMessage> io.agora.chat.Conversation.searchMsgFromDB ( ChatMessage.Type  type,
long  timeStamp,
int  maxCount,
String  from,
SearchDirection  direction 
)

Search message from database according the parameters Note: Cautious about memory usage when the maxCount is large

Parameters
typeMessage type, TXT、VOICE、IMAGE and so on
timeStampThe timestamp for search
maxCountThe max number of message to search
fromWho the message from, also can used to search in group
Returns
The list of searched messages
List<ChatMessage> io.agora.chat.Conversation.searchMsgFromDB ( String  keywords,
long  timeStamp,
int  maxCount,
String  from,
SearchDirection  direction 
)

Search message from database based the parameters Note: 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
fromWho the message from, also can used to search in group
Returns
The list of searched messages
List<ChatMessage> io.agora.chat.Conversation.searchMsgFromDB ( long  startTimeStamp,
long  endTimeStamp,
int  maxCount 
)

Search message from database based the parameters Note: Cautious about memory usage when the maxCount is large

Parameters
startTimeStampStart timestamp for search in
endTimeStampEnd timestamp for search
maxCountThe max number of message to search
Returns
The list of searched messages
void io.agora.chat.Conversation.setExtField ( String  ext)

Set Conversation extension Extend field only stored in local database, not sync to network server

Parameters
extExtension string
boolean io.agora.chat.Conversation.updateMessage ( ChatMessage  msg)

Update a message in local database Message id of the message cannot be updated. Latest Message of the conversation and other properties will be updated accordingly.

Parameters
msgMessage

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