hyphenate_SDK4.0 4.6.0
hyphenate java IM SDK
| Public 成员函数 | 静态 Public 成员函数 | 所有成员列表
com.hyphenate.chat.EMConversation类 参考

继承自 com.hyphenate.chat.EMBase< T > .

enum  EMConversationType
 
enum  EMMarkType
 
enum  EMMessageSearchScope
 
enum  EMSearchDirection
 

Public 成员函数

Set< EMMarkTypemarks ()
 
String conversationId ()
 
EMConversationType getType ()
 
int getUnreadMsgCount ()
 
void markAllMessagesAsRead ()
 
int getAllMsgCount ()
 
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 (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 ()
 

静态 Public 成员函数

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

详细描述

会话类,用于定义单聊会话、群聊会话和聊天室会话。

每类会话中包含发送和接收的消息。

例如,从会话中获取未读消息数:

// conversationId 可以为聊天的另一方 ID,群组 ID 或者聊天室 ID。
EMConversation conversation = EMClient.getInstance().chatManager().getConversation(conversationId);
int unread = conversation.getUnreadMsgCount();
String conversationId()
Definition: EMConversation.java:258
版本
3.0

成员函数说明

◆ appendMessage()

boolean com.hyphenate.chat.EMConversation.appendMessage ( EMMessage  msg)

在本地数据库中会话的尾部插入一条消息。

消息的会话 ID 应与会话的 ID 一致。

消息插入后,SDK 会自动更新会话的 latestMessage 等属性。

参数
msg消息实例。

◆ clear()

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

清除会话中的所有消息。

只清除内存的,不清除本地数据库的消息。

在退出会话的时候清除内存缓存,减小内存消耗。

◆ clearAllMessages()

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

清除内存和数据库中指定会话中的消息。

◆ conversationId()

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

会话 ID,取决于会话类型。

  • 单聊/help desk:会话 ID 为对方的用户 ID。
  • 群聊:会话 ID 为群组 ID。
  • 聊天室:会话 ID 为聊天室的 ID。
返回
会话 ID。

◆ getAllMessages()

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

获取该会话当前内存中的所有消息。

如果内存中为空,SDK 再从本地数据库中加载最近一条消息。

返回
消息列表。

◆ getAllMsgCount()

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

获取 SDK 本地数据库中会话的全部消息数。

返回
会话的全部消息数量。

◆ getExtField()

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

获取会话的扩展字段。

扩展字段只在本地数据库中保存,不同步到服务器。

子区会话的扩展字段不在本地数据库中保存。

返回
会话的扩展字段。

◆ getLastMessage()

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

获取会话中的最新一条消息。

此操作不会改变未读消息计数。

SDK 首先在内存中查找消息,若在内存中未找到,SDK 会在本地数据库查询并加载。

返回
消息。

◆ getLatestMessageFromOthers()

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

获取会话中收到的最新一条消息。

返回
消息。

◆ getMessage()

EMMessage com.hyphenate.chat.EMConversation.getMessage ( String  messageId,
boolean  markAsRead 
)

根据消息 ID 获取已读的消息。

SDK 首先在内存中查找消息,若在内存中未找到,SDK 会在本地数据库查询并加载。

参数
messageId消息 ID。
markAsRead是否将获取的消息标为已读。
  • true:是。
  • false:否
返回
获取到的消息实例。

◆ getMessageAttachmentPath()

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

获取会话对应的附件的存储路径。

该方法适用于清理会话数据前,如果不确定该路径一定存在,请调用该方法前查询路径。如有必要,添加异常保护。

返回
附件存储路径。

◆ getPinnedTime()

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

获取会话置顶时间。

返回
会话置顶的 UNIX 时间戳,单位为毫秒。未置顶时值为 0

◆ getType()

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

获取会话类型。

返回
会话类型。

◆ getUnreadMsgCount()

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

获取会话中未读的消息数量。

返回
未读的消息数量。

◆ insertMessage()

boolean com.hyphenate.chat.EMConversation.insertMessage ( EMMessage  msg)

在本地数据库的会话中插入一条消息。

消息的会话 ID 应与会话的 ID 一致。

消息会根据消息里的 Unix 时间戳插入本地数据库,SDK 会更新会话的 latestMessage 等属性。

参数
msg消息实例。

◆ isChatThread()

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

查看当前会话是否是子区会话。

返回
返回是否是子区会话的结果。
  • true 表示是子区会话。
  • false 表示不是子区会话。

◆ isGroup()

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

获取是否是群组或者聊天室会话。

返回
群组和聊天室类型都会返回 true,其他类型返回 false

◆ isPinned()

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

获取会话的置顶状态。

返回
会话是否处于置顶状态:
  • true:会话处于置顶状态。
  • false:会话处于非置顶状态。

◆ loadMoreMsgFromDB() [1/2]

List< EMMessage > com.hyphenate.chat.EMConversation.loadMoreMsgFromDB ( String  startMsgId,
int  pageSize 
)

从 SDK 本地数据库中分页加载消息。

加载的消息会基于消息中的时间戳放入当前会话的缓存中,调用 getAllMessages() 时会返回所有加载的消息。

参数
startMsgId查询的起始消息 ID。SDK 从该消息 ID 开始按消息时间戳的逆序加载。如果传入消息的 ID 为空,SDK 从最新消息开始按消息时间戳的逆序获取。
pageSize每页期望加载的消息数。取值范围为 [1,400]。
返回
消息列表(不包含查询起始 ID 的消息)。

◆ loadMoreMsgFromDB() [2/2]

List< EMMessage > com.hyphenate.chat.EMConversation.loadMoreMsgFromDB ( String  startMsgId,
int  pageSize,
EMSearchDirection  direction 
)

从指定消息 ID 开始分页加载数据库中的消息。

加载到的消息会加入到当前会话的消息中。

参数
startMsgId查询的起始消息 ID。该参数设置后,SDK 从指定的消息 ID 开始按消息检索方向加载。 如果传入消息的 ID 为空,SDK 忽略该参数,按搜索方向查询消息:
  • directionUP,SDK 从最新消息开始,按消息时间戳的倒序获取;
  • directionDOWN,SDK 从最早消息开始,按消息时间戳的正序获取。
pageSize每页期望加载的消息数。取值范围为 [1,40]。
direction消息搜索方向。详见 EMSearchDirection
  • UP:按照消息中的时间戳的逆序查询;
    • DOWN:按照消息中的时间戳的正序查询;
返回
消息列表(不包含查询起始时间戳对应的消息)。

◆ markAllMessagesAsRead()

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

将所有未读消息设置为已读。

◆ markMessageAsRead()

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

设置指定消息为已读。

也可调用 EMMessage#setUnread(boolean) 将消息置为已读。

参数
messageId消息 ID。

◆ marks()

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

获取会话的所有标记。

返回
会话的所有标记。

◆ msgType2ConversationType()

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

将消息类型转化为会话类型。

参数
id消息 ID。
type消息类型。
返回
会话类型。

◆ pinnedMessages()

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

从本地获取会话中所有置顶的消息。

返回
该会话中所有置顶的消息

◆ removeMessage()

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

删除本地数据库中的一条指定消息。

参数
messageId待删除消息的 ID。

◆ removeMessages()

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

从本地数据库中删除指定时间段内的消息。

参数
startTime删除消息的起始时间。Unix 时间戳,单位为毫秒。
endTime删除消息的结束时间。Unix 时间戳,单位为毫秒。
返回
消息是否删除成功:
  • 若操作成功,返回 true
  • 若操作失败,返回 false

◆ removeMessagesFromServer() [1/2]

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

单向删除漫游消息(根据消息 ID 删除)。

参数
msgIdList要从服务器单向删除的消息 ID 列表。
callBack处理结果回调,详见 EMCallBack

◆ removeMessagesFromServer() [2/2]

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

单向删除漫游消息(根据时间删除)。

参数
beforeTimeStamp消息删除开始的 UNIX 时间戳,单位为毫秒。设置开始时间后,该方法删除服务器在该时间点之前接收到的消息。
callBack处理结果回调,详见 EMCallBack

◆ searchCustomMsgFromDB()

List< EMMessage > com.hyphenate.chat.EMConversation.searchCustomMsgFromDB ( String  keywords,
long  timeStamp,
int  maxCount,
String  from,
EMSearchDirection  direction 
)

从本地数据库获取会话中的指定用户发送的包含特定关键词的自定义消息。

参数
keywords搜索的关键词。
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从当前时间开始搜索。
maxCount每次获取的最大消息数。取值范围为 [1,400]。
from单聊或群聊中的消息发送方的用户 ID。若设置为 null 或空字符串,SDK 将在整个会话中搜索消息。
direction消息加载方向。详见 EMSearchDirection
返回
消息列表(不包含查询起始时间戳对应的消息)。

◆ searchMsgFromDB() [1/5]

List< EMMessage > com.hyphenate.chat.EMConversation.searchMsgFromDB ( long  startTimeStamp,
long  endTimeStamp,
int  maxCount 
)

从本地数据库中搜索指定时间段内发送或接收的一定数量的消息。

参数
startTimeStamp搜索的起始时间戳。单位为毫秒。详见 EMOptions#setSortMessageByServerTime
endTimeStamp搜索的结束时间戳。单位为毫秒。详见 EMOptions#setSortMessageByServerTime
maxCount每次获取的最大消息数量。取值范围为 [1,400]。
返回
消息列表(不包含搜索起始时间戳和结束时间戳对应的消息)。

◆ searchMsgFromDB() [2/5]

List< EMMessage > com.hyphenate.chat.EMConversation.searchMsgFromDB ( long  timeStamp,
int  maxCount,
EMSearchDirection  direction 
)

基于 Unix 时间戳搜索本地数据库中的消息。

参数
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从最新消息获取。
maxCount每次获取的最大消息数。取值范围为 [1,400]。
direction消息搜索方向。详见 EMSearchDirection
  • UP:按照消息中的时间戳的逆序查询;
    • DOWN:按照消息中的时间戳的正序查询。
返回
消息列表(不包含查询起始时间戳对应的消息)。

◆ searchMsgFromDB() [3/5]

List< EMMessage > com.hyphenate.chat.EMConversation.searchMsgFromDB ( String  keywords,
long  timeStamp,
int  maxCount,
String  from,
EMSearchDirection  direction 
)

从本地数据库获取会话中的指定用户发送的包含特定关键词的消息。

参数
keywords查询的关键字。
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从当前时间开始搜索。
maxCount每次获取的最大消息数。取值范围为 [1,400]。
from单聊或群聊中的消息发送方的用户 ID。若设置为 null 或空字符串,SDK 将在整个会话中搜索消息。
direction消息搜索方向。详见 EMSearchDirection
  • UP:按照消息中的时间戳的逆序查询;
    • DOWN:按照消息中的时间戳的正序查询。
返回
消息列表(不包含查询起始时间戳对应的消息)。

◆ searchMsgFromDB() [4/5]

List< EMMessage > com.hyphenate.chat.EMConversation.searchMsgFromDB ( String  keywords,
long  timeStamp,
int  maxCount,
String  from,
EMSearchDirection  direction,
EMMessageSearchScope  searchScope 
)

从本地数据库获取会话中的指定用户发送的包含特定关键词的消息。

参数
keywords查询的关键字。
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。 如果该参数设置为负数,SDK 从当前时间开始搜索。
maxCount每次获取的最大消息数。取值范围为 [1,400]。如果设为小于等于 0,SDK 会获取一条消息。
from单聊或群聊中的消息发送方的用户 ID。若设置为 null 或空字符串,SDK 将在整个会话中搜索消息。
direction消息搜索方向。详见 EMSearchDirection
  • UP:按照消息中的时间戳的逆序查询;
    • DOWN:按照消息中的时间戳的正序查询。
searchScope消息搜索范围。详见 EMMessageSearchScope
返回
消息列表(不包含查询起始时间戳对应的消息)。

◆ searchMsgFromDB() [5/5]

List< EMMessage > com.hyphenate.chat.EMConversation.searchMsgFromDB ( Type  type,
long  timeStamp,
int  maxCount,
String  from,
EMSearchDirection  direction 
)

从本地数据库获取指定会话的一定数量的特定类型的消息。

参数
type消息类型。详见 Type
timeStamp查询的起始消息 Unix 时间戳,单位为毫秒。该参数设置后,SDK 从指定时间戳的消息开始,按消息搜索方向获取。
maxCount每次获取的最大消息数。取值范围为 [1,400]。
from单聊或群聊中的消息发送方的用户 ID。若设置为 null 或空字符串,SDK 将在整个会话中搜索消息。
direction消息搜索方向。详见 EMSearchDirection
  • UP:按照消息中的时间戳的逆序查询;
    • DOWN:按照消息中的时间戳的正序查询。
返回
消息列表(不包含查询起始时间戳对应的消息)。

◆ setExtField()

void com.hyphenate.chat.EMConversation.setExtField ( String  ext)

设置会话的扩展字段。

扩展字段只在本地数据库中保存,不同步到服务器。

子区会话的扩展字段不在本地数据库中保存。

参数
ext会话的扩展字段。

◆ updateMessage()

boolean com.hyphenate.chat.EMConversation.updateMessage ( EMMessage  msg)

更新本地数据库的指定消息。

消息更新时,消息 ID 不会修改。

消息更新后,SDK 会自动更新会话的 latestMessage 等属性。

参数
msg要更新的消息。

该类的文档由以下文件生成: