Chat SDK for Android v1.2.1
agora java chat SDK
|
Inherits io.agora.chat.EMBase< T >.
Classes | |
enum | ConversationType |
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) |
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 | 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) |
Static Public Member Functions | |
static ConversationType | msgType2ConversationType (String id, ChatMessage.ChatType type) |
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.
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
.
msg | The message instance. |
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.
void io.agora.chat.Conversation.clearAllMessages | ( | ) |
Deletes all the messages in the conversation from the memory and local database.
String io.agora.chat.Conversation.conversationId | ( | ) |
The conversation ID, which depends on the conversation type.
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.
int io.agora.chat.Conversation.getAllMsgCount | ( | ) |
Gets the number of all unread messages in the conversation in the local database.
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.
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.
ChatMessage io.agora.chat.Conversation.getLatestMessageFromOthers | ( | ) |
Gets the latest received message in the conversation.
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.
messageId | The message ID. |
markAsRead | Whether to mark the retrieved message as read.
|
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.
long io.agora.chat.Conversation.getPinnedTime | ( | ) |
Gets the time when the conversation is pinned.
0
when the conversation is not pinned. ConversationType io.agora.chat.Conversation.getType | ( | ) |
Gets the conversation type.
int io.agora.chat.Conversation.getUnreadMsgCount | ( | ) |
Gets the number of unread messages in the conversation.
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
.
msg | The message instance. |
boolean io.agora.chat.Conversation.isChatThread | ( | ) |
Checks whether the current conversation is a thread conversation.
true
: Yes.false
: No. boolean io.agora.chat.Conversation.isGroup | ( | ) |
Checks 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. boolean io.agora.chat.Conversation.isPinned | ( | ) |
Checks whether the conversation is pinned.
true
: Yes.false
: No. The conversation is unpinned. 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().
startMsgId | The 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. |
pageSize | The number of messages that you expect to get on each page. The value range is [1,400]. |
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.
startMsgId | The 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.
|
pageSize | The number of messages that you expect to get on each page. The value range is [1,400]. |
direction | The message search direction. See SearchDirection.
|
void io.agora.chat.Conversation.markAllMessagesAsRead | ( | ) |
Marks all unread messages as read.
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.
messageId | The message ID. |
|
static |
Converts a message type to a conversation type.
id | The message ID. |
type | The message type. |
void io.agora.chat.Conversation.removeMessage | ( | String | messageId | ) |
Deletes a message in the local database.
messageId | The ID of the message to delete. |
boolean io.agora.chat.Conversation.removeMessages | ( | long | startTime, |
long | endTime | ||
) |
Deletes messages sent or received in a certain period from the local database.
startTime | The starting Unix timestamp for message deletion. The unit is millisecond. |
endTime | The ending Unix timestamp for message deletion. The unit is millisecond. |
true
.false
. void io.agora.chat.Conversation.removeMessagesFromServer | ( | List< String > | msgIdList, |
CallBack | callBack | ||
) |
Deletes historical messages from the server unidirectionally by message ID.
msgIdList | The list of IDs of messages to be deleted from the server unidirectionally. |
callBack | The result callback which contains the error information if the method fails. See CallBack. |
void io.agora.chat.Conversation.removeMessagesFromServer | ( | long | beforeTimeStamp, |
CallBack | callBack | ||
) |
Deletes historical messages from the server unidirectionally by timestamp.
beforeTimeStamp | The 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. |
callBack | The result callback which contains the error information if the method fails. See CallBack. |
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.
keywords | The keywords for search. |
timeStamp | TThe 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. |
maxCount | The maximum number of messages to retrieve. The value range is [1,400]. |
from | The user ID of the message sender in one-to-one chat or group chat. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation. |
direction | The message search direction. See SearchDirection.
|
List< ChatMessage > io.agora.chat.Conversation.searchMsgFromDB | ( | ChatMessage.Type | type, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
SearchDirection | direction | ||
) |
Gets messages of certain types that a specified user sends in the conversation.
type | The message type. See Type. |
timeStamp | The 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. |
maxCount | The maximum number of messages to retrieve each time. The value range is [1,400]. |
from | The user ID of the message sender in one-to-one chat or group chat. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation. |
direction | The message search direction. See SearchDirection.
|
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.
startTimeStamp | The starting Unix timestamp in the message for query. The unit is millisecond. See ChatOptions#setSortMessageByServerTime. |
endTimeStamp | The ending Unix timestamp in the message for query. The unit is millisecond. See ChatOptions#setSortMessageByServerTime. |
maxCount | The maximum number of messages to retrieve each time. The value range is [1,400]. |
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.
timeStamp | The 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. |
maxCount | The maximum number of message to retrieve each time. The value range is [1,400]. |
direction | The message search direction. See SearchDirection.
|
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.
keywords | The keywords for query. |
timeStamp | The 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. |
maxCount | The maximum number of messages to retrieve each time. The value range is [1,400]. |
from | The user ID of the message sender in one-to-one chat or group chat. If this parameter is set to null or an empty string, the SDK searches for messages in the entire conversation. |
direction | The message search direction. See SearchDirection.
|
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.
ext | The extension field of the conversation. |
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
.
msg | The message to update. |