hyphenate_SDK4.0 4.8.0
hyphenate java IM SDK
|
Inherits com.hyphenate.chat.EMBase< T >.
Classes | |
enum | EMConversationType |
enum | EMMarkType |
enum | EMMessageSearchScope |
enum | EMSearchDirection |
Public Member Functions | |
Set< EMMarkType > | marks () |
String | conversationId () |
EMConversationType | getType () |
int | getUnreadMsgCount () |
void | markAllMessagesAsRead () |
int | getAllMsgCount () |
int | getAllMsgCount (long startTimestamp, long endTimestamp) |
boolean | isChatThread () |
List< EMMessage > | loadMoreMsgFromDB (String startMsgId, int pageSize) |
List< EMMessage > | loadMoreMsgFromDB (String startMsgId, int pageSize, EMSearchDirection direction) |
List< EMMessage > | searchMsgFromDB (long timeStamp, int maxCount, EMSearchDirection direction) |
List< EMMessage > | searchMsgFromDB (Type type, long timeStamp, int maxCount, String from, EMSearchDirection direction) |
List< EMMessage > | searchMsgFromDB (Set< Type > types, long timeStamp, int maxCount, String from, EMSearchDirection direction) |
List< EMMessage > | searchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMSearchDirection direction) |
List< EMMessage > | searchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMSearchDirection direction, EMMessageSearchScope searchScope) |
List< EMMessage > | searchMsgFromDB (long startTimeStamp, long endTimeStamp, int maxCount) |
List< EMMessage > | searchCustomMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMSearchDirection direction) |
EMMessage | getMessage (String messageId, boolean markAsRead) |
void | markMessageAsRead (String messageId) |
List< EMMessage > | getAllMessages () |
void | removeMessage (String messageId) |
EMMessage | getLastMessage () |
EMMessage | getLatestMessageFromOthers () |
void | clear () |
void | clearAllMessages () |
void | setExtField (String ext) |
String | getExtField () |
boolean | isPinned () |
long | getPinnedTime () |
boolean | isGroup () |
boolean | insertMessage (EMMessage msg) |
boolean | appendMessage (EMMessage msg) |
boolean | updateMessage (EMMessage msg) |
String | getMessageAttachmentPath () |
void | removeMessagesFromServer (List< String > msgIdList, EMCallBack callBack) |
void | removeMessagesFromServer (long beforeTimeStamp, EMCallBack callBack) |
boolean | removeMessages (long startTime, long endTime) |
List< EMMessage > | pinnedMessages () |
EMPushManager.EMPushRemindType | pushRemindType () |
Static Public Member Functions | |
static EMConversationType | msgType2ConversationType (String id, EMMessage.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 com.hyphenate.chat.EMConversation.appendMessage | ( | EMMessage | 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 com.hyphenate.chat.EMConversation.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 com.hyphenate.chat.EMConversation.clearAllMessages | ( | ) |
Deletes all the messages in the conversation from the memory and local database.
String com.hyphenate.chat.EMConversation.conversationId | ( | ) |
The conversation ID, which depends on the conversation type.
List< EMMessage > com.hyphenate.chat.EMConversation.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 com.hyphenate.chat.EMConversation.getAllMsgCount | ( | ) |
Gets the number of all messages in the conversation in the local database.
int com.hyphenate.chat.EMConversation.getAllMsgCount | ( | long | startTimestamp, |
long | endTimestamp | ||
) |
Gets the number of all messages in the conversation in the local database within a specific time period.
startTimestamp | The start timestamp (inclusive) in milliseconds. |
endTimestamp | The end timestamp (inclusive) in milliseconds. |
String com.hyphenate.chat.EMConversation.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.
EMMessage com.hyphenate.chat.EMConversation.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.
EMMessage com.hyphenate.chat.EMConversation.getLatestMessageFromOthers | ( | ) |
Gets the latest received message in the conversation.
EMMessage com.hyphenate.chat.EMConversation.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 com.hyphenate.chat.EMConversation.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 com.hyphenate.chat.EMConversation.getPinnedTime | ( | ) |
Gets the time when the conversation is pinned.
0
when the conversation is not pinned. EMConversationType com.hyphenate.chat.EMConversation.getType | ( | ) |
Gets the conversation type.
int com.hyphenate.chat.EMConversation.getUnreadMsgCount | ( | ) |
Gets the number of unread messages in the conversation.
boolean com.hyphenate.chat.EMConversation.insertMessage | ( | EMMessage | 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 com.hyphenate.chat.EMConversation.isChatThread | ( | ) |
Checks whether the current conversation is a thread conversation.
true
: Yes.false
: No. boolean com.hyphenate.chat.EMConversation.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 com.hyphenate.chat.EMConversation.isPinned | ( | ) |
Checks whether the conversation is pinned.
true
: Yes.false
: No. The conversation is unpinned. List< EMMessage > com.hyphenate.chat.EMConversation.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< EMMessage > com.hyphenate.chat.EMConversation.loadMoreMsgFromDB | ( | String | startMsgId, |
int | pageSize, | ||
EMSearchDirection | 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 EMSearchDirection.
|
void com.hyphenate.chat.EMConversation.markAllMessagesAsRead | ( | ) |
Marks all unread messages as read.
void com.hyphenate.chat.EMConversation.markMessageAsRead | ( | String | messageId | ) |
Marks a message as read.
You can also call EMMessage#setUnread(boolean) to mark the message as read.
messageId | The message ID. |
Set< EMMarkType > com.hyphenate.chat.EMConversation.marks | ( | ) |
Gets all marks for the conversation.
|
static |
Converts a message type to a conversation type.
id | The message ID. |
type | The message type. |
List< EMMessage > com.hyphenate.chat.EMConversation.pinnedMessages | ( | ) |
Gets the list of pinned messages in a local conversation.
EMPushManager.EMPushRemindType com.hyphenate.chat.EMConversation.pushRemindType | ( | ) |
Gets the push reminder type of the conversation.
void com.hyphenate.chat.EMConversation.removeMessage | ( | String | messageId | ) |
Deletes a message in the local database.
messageId | The ID of the message to delete. |
boolean com.hyphenate.chat.EMConversation.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 com.hyphenate.chat.EMConversation.removeMessagesFromServer | ( | List< String > | msgIdList, |
EMCallBack | 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 EMCallBack. |
void com.hyphenate.chat.EMConversation.removeMessagesFromServer | ( | long | beforeTimeStamp, |
EMCallBack | 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 EMCallBack. |
List< EMMessage > com.hyphenate.chat.EMConversation.searchCustomMsgFromDB | ( | String | keywords, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
EMSearchDirection | 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. 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. |
direction | The message search direction. See EMSearchDirection.
|
List< EMMessage > com.hyphenate.chat.EMConversation.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 EMOptions#setSortMessageByServerTime. |
endTimeStamp | The ending Unix timestamp in the message for query. The unit is millisecond. See EMOptions#setSortMessageByServerTime. |
maxCount | The maximum number of messages to retrieve each time. The value range is [1,400]. |
List< EMMessage > com.hyphenate.chat.EMConversation.searchMsgFromDB | ( | long | timeStamp, |
int | maxCount, | ||
EMSearchDirection | 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 EMSearchDirection.
|
List< EMMessage > com.hyphenate.chat.EMConversation.searchMsgFromDB | ( | Set< Type > | types, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
EMSearchDirection | direction | ||
) |
Gets messages of multiple types that a specified user sends in the conversation.
types | The message types. 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. 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. |
direction | The message search direction. See EMSearchDirection.
|
List< EMMessage > com.hyphenate.chat.EMConversation.searchMsgFromDB | ( | String | keywords, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
EMSearchDirection | 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. 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. |
direction | The message search direction. See EMSearchDirection.
|
List< EMMessage > com.hyphenate.chat.EMConversation.searchMsgFromDB | ( | String | keywords, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
EMSearchDirection | direction, | ||
EMMessageSearchScope | searchScope | ||
) |
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]. If you set this parameter to 0 or less, the SDK gets one message from the local database. |
from | The 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. |
direction | The message search direction. See EMSearchDirection.
|
searchScope | The scope of search message. See EMMessageSearchScope. |
List< EMMessage > com.hyphenate.chat.EMConversation.searchMsgFromDB | ( | Type | type, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
EMSearchDirection | direction | ||
) |
Gets messages of a certain type 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. 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. |
direction | The message search direction. See EMSearchDirection.
|
void com.hyphenate.chat.EMConversation.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 com.hyphenate.chat.EMConversation.updateMessage | ( | EMMessage | 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. |