agora_chat_SDK 1.0.6
agora java chat SDK
|
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< ChatMessage > | loadMoreMsgFromDB (String startMsgId, int pageSize) |
List< ChatMessage > | loadMoreMsgFromDB (String startMsgId, int pageSize, SearchDirection direction) |
List< ChatMessage > | searchMsgFromDB (long timeStamp, int maxCount, SearchDirection direction) |
List< ChatMessage > | searchMsgFromDB (ChatMessage.Type type, long timeStamp, int maxCount, String from, SearchDirection direction) |
List< ChatMessage > | searchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, SearchDirection direction) |
List< ChatMessage > | searchMsgFromDB (long startTimeStamp, long endTimeStamp, int maxCount) |
List< ChatMessage > | searchCustomMsgFromDB (String keywords, long timeStamp, int maxCount, String from, SearchDirection direction) |
ChatMessage | getMessage (String messageId, boolean markAsRead) |
List< ChatMessage > | loadMessages (List< String > msgIds) |
void | markMessageAsRead (String messageId) |
List< ChatMessage > | getAllMessages () |
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) |
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.
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.
msg | The message instance. |
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.
void io.agora.chat.Conversation.clearAllMessages | ( | ) |
Deletes all the messages of the conversation from the memory cache and local database.
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.
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.
int io.agora.chat.Conversation.getAllMsgCount | ( | ) |
Gets all messages count in this conversation in the local database.
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.
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.
ChatMessage io.agora.chat.Conversation.getLatestMessageFromOthers | ( | ) |
Gets the latest message from the conversation.
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.
messageId | The message ID. |
markAsRead | Whether to mark the message as read while getting it.
|
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.
ConversationType io.agora.chat.Conversation.getType | ( | ) |
Gets the conversation type.
int io.agora.chat.Conversation.getUnreadMsgCount | ( | ) |
Gets the number of unread messages of the conversation.
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.
msg | The message instance. |
boolean io.agora.chat.Conversation.isGroup | ( | ) |
To check whether it is a group or chat room conversation.
true
. Otherwise, the SDK returns false
. 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.
msgIds | The message IDs to be loaded. |
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.
startMsgId | The specified message ID. If the startMsgId is set as "" or null, the SDK will load latest messages in database. |
pageSize | The number of records in a page. |
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.
startMsgId | The specified message ID. If the startMsgId is set as "" or null, the SDK will load latest messages in database. |
pageSize | The number of records in a page. |
direction | The direction in which the message is loaded: ChatMessageSearchDirection.
|
void io.agora.chat.Conversation.markAllMessagesAsRead | ( | ) |
Marks all messages as read.
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).
messageId | The message ID. |
|
static |
Provides a transformation from a message type to a conversation type.
id | The message ID, used to distinguish one-to-one chat and the help desk chat, has no effect on other chat type. |
type | The message type. |
void io.agora.chat.Conversation.removeMessage | ( | String | messageId | ) |
Deletes a message in the local database.
Note: Operates only on the local database.
messageId | The message to be deleted. |
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.
keywords | The keywords in message. |
timeStamp | The Unix timestamp to search. |
maxCount | The max number of message to search. |
from | The message sender, the param can also be used to search in group chat. |
direction | The direction in which the message is loaded: ChatMessageSearchDirection.
|
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.
type | The message type, including TXT、VOICE、IMAGE and so on. |
timeStamp | The Unix timestamp for search. |
maxCount | The max number of message to search. |
from | The sender of the message. The param can also be used to search in group chat. |
direction | The direction in which the message is loaded: ChatMessageSearchDirection.
|
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.
startTimeStamp | The start Unix timestamp to search. |
endTimeStamp | The end Unix timestamp to search. |
maxCount | The max number of message to search. |
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.
timeStamp | The Unix timestamp when searching. |
maxCount | The max number of message to search. |
direction | The direction in which the message is loaded: ChatMessageSearchDirection.
|
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.
keywords | The keywords in message. |
timeStamp | The timestamp for search. |
maxCount | The max number of message to search. |
from | The message sender. The param can also be used to search in group chat. |
direction | The direction in which the message is loaded: ChatMessageSearchDirection.
|
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.
ext | The extension string. |
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.
msg | The message to be updated. |