hyphenate_SDK4.0 4.8.0
hyphenate java IM SDK
Classes | Public Member Functions | Static Public Member Functions | List of all members
com.hyphenate.chat.EMConversation Class Reference

Inherits com.hyphenate.chat.EMBase< T >.

Classes

enum  EMConversationType
 
enum  EMMarkType
 
enum  EMMessageSearchScope
 
enum  EMSearchDirection
 

Public Member Functions

Set< EMMarkTypemarks ()
 
String conversationId ()
 
EMConversationType getType ()
 
int getUnreadMsgCount ()
 
void markAllMessagesAsRead ()
 
int getAllMsgCount ()
 
int getAllMsgCount (long startTimestamp, long endTimestamp)
 
boolean isChatThread ()
 
List< EMMessageloadMoreMsgFromDB (String startMsgId, int pageSize)
 
List< EMMessageloadMoreMsgFromDB (String startMsgId, int pageSize, EMSearchDirection direction)
 
List< EMMessagesearchMsgFromDB (long timeStamp, int maxCount, EMSearchDirection direction)
 
List< EMMessagesearchMsgFromDB (Type type, long timeStamp, int maxCount, String from, EMSearchDirection direction)
 
List< EMMessagesearchMsgFromDB (Set< Type > types, long timeStamp, int maxCount, String from, EMSearchDirection direction)
 
List< EMMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMSearchDirection direction)
 
List< EMMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMSearchDirection direction, EMMessageSearchScope searchScope)
 
List< EMMessagesearchMsgFromDB (long startTimeStamp, long endTimeStamp, int maxCount)
 
List< EMMessagesearchCustomMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMSearchDirection direction)
 
EMMessage getMessage (String messageId, boolean markAsRead)
 
void markMessageAsRead (String messageId)
 
List< EMMessagegetAllMessages ()
 
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< EMMessagepinnedMessages ()
 
EMPushManager.EMPushRemindType pushRemindType ()
 

Static Public Member Functions

static EMConversationType msgType2ConversationType (String id, EMMessage.ChatType type)
 

Detailed Description

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.

// ConversationId can be the ID of the peer user, the group ID, or the chat room ID:
EMConversation conversation = EMClient.getInstance().chatManager().getConversation(conversationId);
int unread = conversation.getUnreadMsgCount();
String conversationId()
Definition: EMConversation.java:259

Member Function Documentation

◆ appendMessage()

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.

Parameters
msgThe message instance.

◆ clear()

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.

◆ clearAllMessages()

void com.hyphenate.chat.EMConversation.clearAllMessages ( )

Deletes all the messages in the conversation from the memory and local database.

◆ conversationId()

String com.hyphenate.chat.EMConversation.conversationId ( )

The conversation ID, which depends on the conversation type.

  • One-to-one chat/help desk: The conversation ID is the user ID of the peer user.
  • Group chat: The conversation ID is the group ID.
  • Chat room: The conversation ID is the chat room ID.
Returns
The conversation ID.

◆ getAllMessages()

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.

Returns
The message list.

◆ getAllMsgCount() [1/2]

int com.hyphenate.chat.EMConversation.getAllMsgCount ( )

Gets the number of all messages in the conversation in the local database.

Returns
The number of all messages in the conversation.

◆ getAllMsgCount() [2/2]

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.

Parameters
startTimestampThe start timestamp (inclusive) in milliseconds.
endTimestampThe end timestamp (inclusive) in milliseconds.
Returns
The number of all messages in the conversation within a specific time period.

◆ getExtField()

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.

Returns
The extension content.

◆ getLastMessage()

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.

Returns
The message instance.

◆ getLatestMessageFromOthers()

EMMessage com.hyphenate.chat.EMConversation.getLatestMessageFromOthers ( )

Gets the latest received message in the conversation.

Returns
The message instance.

◆ getMessage()

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.

Parameters
messageIdThe message ID.
markAsReadWhether to mark the retrieved message as read.
  • true: Yes.
  • false: No.
Returns
message The retrieved message instance.

◆ getMessageAttachmentPath()

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.

Returns
The path to save attachments in the conversation.

◆ getPinnedTime()

long com.hyphenate.chat.EMConversation.getPinnedTime ( )

Gets the time when the conversation is pinned.

Returns
The UNIX timestamp when the conversation is pinned. The unit is millisecond. This value is 0 when the conversation is not pinned.

◆ getType()

EMConversationType com.hyphenate.chat.EMConversation.getType ( )

Gets the conversation type.

Returns
The conversation type.

◆ getUnreadMsgCount()

int com.hyphenate.chat.EMConversation.getUnreadMsgCount ( )

Gets the number of unread messages in the conversation.

Returns
The unread message count in the conversation.

◆ insertMessage()

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.

Parameters
msgThe message instance.

◆ isChatThread()

boolean com.hyphenate.chat.EMConversation.isChatThread ( )

Checks whether the current conversation is a thread conversation.

Returns
Whether the conversation is a chat thread conversation.
  • true: Yes.
  • false: No.

◆ isGroup()

boolean com.hyphenate.chat.EMConversation.isGroup ( )

Checks whether it is a group conversation or a chat room conversation, or a conversation of another type.

Returns
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.

◆ isPinned()

boolean com.hyphenate.chat.EMConversation.isPinned ( )

Checks whether the conversation is pinned.

Returns
Whether the conversation is pinned.
  • true: Yes.
  • false: No. The conversation is unpinned.

◆ loadMoreMsgFromDB() [1/2]

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().

Parameters
startMsgIdThe 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.
pageSizeThe number of messages that you expect to get on each page. The value range is [1,400].
Returns
The list of retrieved messages (excluding the one with the starting ID).

◆ loadMoreMsgFromDB() [2/2]

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.

Parameters
startMsgIdThe 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.
  • If direction is set as UP, the SDK retrieves messages, starting from the latest one, in the descending order of the timestamp included in them.
  • If direction is set as DOWN, the SDK retrieves messages, starting from the oldest one, in the ascending order of the timestamp included in them.
pageSizeThe number of messages that you expect to get on each page. The value range is [1,400].
directionThe message search direction. See EMSearchDirection.
  • UP: The SDK retrieves messages in the descending order of the timestamp included in them.
    • DOWN: The SDK retrieves messages in the ascending order of the timestamp included in them.
Returns
The list of retrieved messages (excluding the one with the starting ID).

◆ markAllMessagesAsRead()

void com.hyphenate.chat.EMConversation.markAllMessagesAsRead ( )

Marks all unread messages as read.

◆ markMessageAsRead()

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.

Parameters
messageIdThe message ID.

◆ marks()

Set< EMMarkType > com.hyphenate.chat.EMConversation.marks ( )

Gets all marks for the conversation.

Returns
All marks for the conversation.

◆ msgType2ConversationType()

static EMConversationType com.hyphenate.chat.EMConversation.msgType2ConversationType ( String  id,
EMMessage.ChatType  type 
)
static

Converts a message type to a conversation type.

Parameters
idThe message ID.
typeThe message type.
Returns
The conversation type.

◆ pinnedMessages()

List< EMMessage > com.hyphenate.chat.EMConversation.pinnedMessages ( )

Gets the list of pinned messages in a local conversation.

Returns
All pinned messages in the conversation.

◆ pushRemindType()

EMPushManager.EMPushRemindType com.hyphenate.chat.EMConversation.pushRemindType ( )

Gets the push reminder type of the conversation.

Returns
The push reminder type of the conversation.

◆ removeMessage()

void com.hyphenate.chat.EMConversation.removeMessage ( String  messageId)

Deletes a message in the local database.

Parameters
messageIdThe ID of the message to delete.

◆ removeMessages()

boolean com.hyphenate.chat.EMConversation.removeMessages ( long  startTime,
long  endTime 
)

Deletes messages sent or received in a certain period from the local database.

Parameters
startTimeThe starting Unix timestamp for message deletion. The unit is millisecond.
endTimeThe ending Unix timestamp for message deletion. The unit is millisecond.
Returns
Whether the message deletion succeeds:
  • If the operation succeeds, the SDK returns true.
  • If the operation fails, the SDK returns false.

◆ removeMessagesFromServer() [1/2]

void com.hyphenate.chat.EMConversation.removeMessagesFromServer ( List< String >  msgIdList,
EMCallBack  callBack 
)

Deletes historical messages from the server unidirectionally by message ID.

Parameters
msgIdListThe list of IDs of messages to be deleted from the server unidirectionally.
callBackThe result callback which contains the error information if the method fails. See EMCallBack.

◆ removeMessagesFromServer() [2/2]

void com.hyphenate.chat.EMConversation.removeMessagesFromServer ( long  beforeTimeStamp,
EMCallBack  callBack 
)

Deletes historical messages from the server unidirectionally by timestamp.

Parameters
beforeTimeStampThe 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.
callBackThe result callback which contains the error information if the method fails. See EMCallBack.

◆ searchCustomMsgFromDB()

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.

Parameters
keywordsThe keywords for search.
timeStampTThe 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.
maxCountThe maximum number of messages to retrieve. The value range is [1,400].
fromThe 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.
directionThe message search direction. See EMSearchDirection.
  • UP: The SDK retrieves messages in the descending order of the timestamp included in them.
    • DOWN: The SDK retrieves messages in the ascending order of the timestamp included in them.
Returns
The list of retrieved messages (excluding the one with the starting timestamp).

◆ searchMsgFromDB() [1/6]

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.

Parameters
startTimeStampThe starting Unix timestamp in the message for query. The unit is millisecond. See EMOptions#setSortMessageByServerTime.
endTimeStampThe ending Unix timestamp in the message for query. The unit is millisecond. See EMOptions#setSortMessageByServerTime.
maxCountThe maximum number of messages to retrieve each time. The value range is [1,400].
Returns
The list of retrieved messages (excluding the ones with the starting timestamp and ending timestamp).

◆ searchMsgFromDB() [2/6]

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.

Parameters
timeStampThe 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.
maxCountThe maximum number of message to retrieve each time. The value range is [1,400].
directionThe message search direction. See EMSearchDirection.
  • UP: The SDK retrieves messages in the descending order of the timestamp included in them.
    • DOWN: The SDK retrieves messages in the ascending order of the timestamp included in them.
Returns
The list of retrieved messages (excluding the one with the starting timestamp).

◆ searchMsgFromDB() [3/6]

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.

Parameters
typesThe message types. See Type.
timeStampThe 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.
maxCountThe maximum number of messages to retrieve each time. The value range is [1,400].
fromThe 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.
directionThe message search direction. See EMSearchDirection.
  • UP: The SDK retrieves messages in the descending order of the timestamp included in them.
    • DOWN: The SDK retrieves messages in the ascending order of the timestamp included in them.
Returns
The list of retrieved messages (excluding the one with the starting timestamp).

◆ searchMsgFromDB() [4/6]

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.

Parameters
keywordsThe keywords for query.
timeStampThe 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.
maxCountThe maximum number of messages to retrieve each time. The value range is [1,400].
fromThe 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.
directionThe message search direction. See EMSearchDirection.
  • UP: The SDK retrieves messages in the descending order of the timestamp included in them.
    • DOWN: The SDK retrieves messages in the ascending order of the timestamp included in them.
Returns
The list of retrieved messages (excluding the one with the starting timestamp).

◆ searchMsgFromDB() [5/6]

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.

Parameters
keywordsThe keywords for query.
timeStampThe 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.
maxCountThe 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.
fromThe 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.
directionThe message search direction. See EMSearchDirection.
  • UP: The SDK retrieves messages in the descending order of the timestamp included in them.
    • DOWN: The SDK retrieves messages in the ascending order of the timestamp included in them.
searchScopeThe scope of search message. See EMMessageSearchScope.
Returns
The list of retrieved messages (excluding the one with the starting timestamp).

◆ searchMsgFromDB() [6/6]

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.

Parameters
typeThe message type. See Type.
timeStampThe 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.
maxCountThe maximum number of messages to retrieve each time. The value range is [1,400].
fromThe 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.
directionThe message search direction. See EMSearchDirection.
  • UP: The SDK retrieves messages in the descending order of the timestamp included in them.
    • DOWN: The SDK retrieves messages in the ascending order of the timestamp included in them.
Returns
The list of retrieved messages (excluding the one with the starting timestamp).

◆ setExtField()

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.

Parameters
extThe extension field of the conversation.

◆ updateMessage()

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.

Parameters
msgThe message to update.

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