hyphenate_SDK3.0  3.0.1
hyphenatejavaIMSDK
| Public 成员函数 | 静态 Public 成员函数 | 所有成员列表
com.hyphenate.chat.EMConversation类 参考

enum  EMConversationType
 
enum  EMSearchDirection
 
class  MessageCache
 

Public 成员函数

String conversationId ()
 
EMConversationType getType ()
 
int getUnreadMsgCount ()
 
void markAllMessagesAsRead ()
 
int getAllMsgCount ()
 
List< EMMessageloadMoreMsgFromDB (String startMsgId, int pageSize)
 
List< EMMessagesearchMsgFromDB (long timeStamp, int maxCount, EMSearchDirection direction)
 
List< EMMessagesearchMsgFromDB (EMMessage.Type type, long timeStamp, int maxCount, String from, EMSearchDirection direction)
 
List< EMMessagesearchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, EMSearchDirection direction)
 
List< EMMessagesearchMsgFromDB (long startTimeStamp, long endTimeStamp, int maxCount)
 
EMMessage getMessage (String messageId, boolean markAsRead)
 
List< EMMessageloadMessages (List< String > msgIds)
 
void markMessageAsRead (String messageId)
 
List< EMMessagegetAllMessages ()
 
int getMessagePosition (EMMessage message)
 
String getUserName ()
 
void removeMessage (String messageId)
 
EMMessage getLastMessage ()
 
void clear ()
 
void clearAllMessages ()
 
void setExtField (String ext)
 
String getExtField ()
 
boolean isGroup ()
 
void insertMessage (EMMessage msg)
 

静态 Public 成员函数

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

详细描述

EMConversation 代表和一个用户的对话,包含发送和接收的消息

下面的示例会取得对话中未读的消息数:

EMConversation conversation = EMChatManager.getInstance().getConversation("user1");
int unread = conversation.getUnreadMsgCount();
版本
3.0

成员函数说明

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

清除对话中的所有消息,只清除内存的,不清除db的消息

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

清除对话中的所有消息,同时清除内存和数据库中的消息

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


会话ID
对于单聊类型,会话ID同时也是对方用户的名称。
对于群聊类型,会话ID同时也是对方群组的ID,并不同于群组的名称。
对于聊天室类型,会话ID同时也是聊天室的ID,并不同于聊天室的名称。
对于HelpDesk类型,会话ID与单聊类型相同,是对方用户的名称。

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

获取此conversation当前内存所有的message

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

获取本地存储会话的全部消息数目

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

获取用户可以自行定义会话扩展字段 该字段只保存在本地,不进行网络同步

返回
会话对应扩展字段的内容
EMMessage com.hyphenate.chat.EMConversation.getLastMessage ( )

获取队列中的最后一条消息 (此操作不会改变未读消息计数)

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

根据msgid获取消息

参数
messageId需要获取的消息id
markAsRead是否获取消息的同时标记消息为已读
返回
获取到的message实例
int com.hyphenate.chat.EMConversation.getMessagePosition ( EMMessage  message)

获取message的position

参数
message
返回
如果没找到此message,返回-1
EMConversationType com.hyphenate.chat.EMConversation.getType ( )

获取会话类型

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

获取此对话中未读取的消息数目

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

获取此对话的用户名 或群组名

返回
user name
void com.hyphenate.chat.EMConversation.insertMessage ( EMMessage  msg)

向数据库和缓存中插入消息

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

群组和聊天室类型都会返回true

返回
群组和聊天室类型都会返回true, 其他类型返回false.
List<EMMessage> com.hyphenate.chat.EMConversation.loadMessages ( List< String >  msgIds)

加载一组消息,如果缓存不存在会去DB查询并加载

参数
msgIds一组消息ID
返回
返回一组消息如果找到,否者返回null
List<EMMessage> com.hyphenate.chat.EMConversation.loadMoreMsgFromDB ( String  startMsgId,
int  pageSize 
)

根据传入的参数从db加载startMsgId之前(存储顺序)指定数量的message, 加载到的messages会加入到当前conversation的messages里

参数
startMsgId加载这个id之前的message
pageSize加载多少条
返回
消息列表
void com.hyphenate.chat.EMConversation.markMessageAsRead ( String  messageId)

设置某条消息为已读

参数
messageId消息ID
static EMConversationType com.hyphenate.chat.EMConversation.msgType2ConversationType ( String  id,
EMMessage.ChatType  type 
)
static

从消息类型到会话类型的转化

参数
id消息Id,用来区分客服和单聊,对于其他类型,这个参数没有影响。
消息类型
返回
会话类型
void com.hyphenate.chat.EMConversation.removeMessage ( String  messageId)

删除一条指定的消息

参数
messageId待删除消息的ID
List<EMMessage> com.hyphenate.chat.EMConversation.searchMsgFromDB ( long  timeStamp,
int  maxCount,
EMSearchDirection  direction 
)

根据传入的参数从本地存储中搜索指定数量的message。 注意:当maxCount非常大时,需要考虑内存消耗

参数
timeStamp搜索消息的时间点
maxCount搜索结果的最大条数
返回
消息列表
List<EMMessage> com.hyphenate.chat.EMConversation.searchMsgFromDB ( EMMessage.Type  type,
long  timeStamp,
int  maxCount,
String  from,
EMSearchDirection  direction 
)

根据传入的参数从本地存储中搜索指定数量的message。 注意:当maxCount非常大时,需要考虑内存消耗

参数
type消息类型,文本、图片、语音等等
timeStamp搜索消息的时间点
maxCount搜索结果的最大条数
from搜索来自某人的消息,适用于搜索群组里的消息
返回
消息列表
List<EMMessage> com.hyphenate.chat.EMConversation.searchMsgFromDB ( String  keywords,
long  timeStamp,
int  maxCount,
String  from,
EMSearchDirection  direction 
)

根据传入的参数从本地存储中搜索指定数量的message。 注意:当maxCount非常大时,需要考虑内存消耗

参数
keywords搜索消息中的关键词
timeStamp搜索消息的时间点
maxCount搜索结果的最大条数
from搜索来自某人的消息,适用于搜索群组里的消息
返回
消息列表
List<EMMessage> com.hyphenate.chat.EMConversation.searchMsgFromDB ( long  startTimeStamp,
long  endTimeStamp,
int  maxCount 
)

根据传入的参数从本地存储中搜索指定数量的message。 注意:当maxCount非常大时,需要考虑内存消耗

参数
startTimeStamp搜索的起始时间
endTimeStamp搜索的结束时间
maxCount搜索结果的最大条数
返回
消息列表
void com.hyphenate.chat.EMConversation.setExtField ( String  ext)

用户可以自行定义会话扩展字段 该字段只保存在本地,不进行网络同步

参数
value会话对应扩展字段的内容

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