hyphenate_SDK3.0  3.0.1
hyphenatejavaIMSDK
Classes | Public Member Functions | Static Public Member Functions | List of all members
com.hyphenate.chat.EMConversation Class Reference

Classes

enum  EMConversationType
 
enum  EMSearchDirection
 
class  MessageCache
 

Public Member Functions

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)
 

Static Public Member Functions

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

Detailed Description

EMConversation represent a conversation chating with a user, containing chat messages.

Example illustrate how to get unread message count

EMConversation conversation = EMClient.getInstance().chatManager().getConversation("user1");
int unread = conversation.getUnreadMsgCount();
Version
3.0

Member Function Documentation

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

clear messages in this conversation's memory cache, but not clear database's message.

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

clear messages in this conversation's memory cache, also clear this conversation's message under database.

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

conversation ID>
For single chat,conversation ID is to chat user's name.
For group chat, conversation ID is groupID(), different with getGroupName()
For chat room, conversation ID is chatroom ID, different with chat room name()
For help desk, it is same with single chat, conversationID is also chat user's name

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

get all message in memory cache

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

get all messages count in this conversation

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

get conversation's extend field, extend field only stored in local database, not sync to network server.

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

get last message from conversation, this function will not mark the message as read

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

get message by message ID, if the message already loaded into memory cache, will directly return the message, otherwise load message from database, and put it into memory cache.

Parameters
messageId
markAsReadif set to be true, will mark the message as read, and send read ack to server
Returns
message
int com.hyphenate.chat.EMConversation.getMessagePosition ( EMMessage  message)

get the message position in memory cache

Parameters
message
Returns
if not not, return -1
EMConversationType com.hyphenate.chat.EMConversation.getType ( )

get conversation type

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

get unread message count

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

get the conversation ID, for single chat, it is user name, for group and chatroom, it is groupID or chatroomID, which different from group name or chatroom name.

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

insert mesasge into cache and local database

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

group chat and chatroom chat will both return true

Returns
group chat and chatroom chat will both return true, otherwise return false.
List<EMMessage> com.hyphenate.chat.EMConversation.loadMessages ( List< String >  msgIds)

load messages, if those message not exists in memory in cache, will load message from database.

Parameters
msgIdsmessages to be loaded.
Returns
List<EMMessage> com.hyphenate.chat.EMConversation.loadMoreMsgFromDB ( String  startMsgId,
int  pageSize 
)

load message from database, message id starting from param startMsgId, messages will also store in to memory cache so next time calling getAllMessages(), result will contain those messages

Parameters
startMsgIdmessage storage time will before this ID, if startMsgId is "" or null, will load last messages in database.
pageSizemessage count to be loaded.
Returns
messages
void com.hyphenate.chat.EMConversation.markMessageAsRead ( String  messageId)

mark the message as read, and send read as to server.

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

provide transformation from message type to conversation type.

Parameters
idmessage Id, used to distinguish single chat and help desk, has no effect on other chat type.
messagetype
Returns
conversation type
void com.hyphenate.chat.EMConversation.removeMessage ( String  messageId)

delete a message

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

search message from database according the parameter Note: please consider your memory when the maxCount is huge

Parameters
timeStampthe timestamp for search
maxCountthe max number of message to search
Returns
the list of searched messages
List<EMMessage> com.hyphenate.chat.EMConversation.searchMsgFromDB ( EMMessage.Type  type,
long  timeStamp,
int  maxCount,
String  from,
EMSearchDirection  direction 
)

search message from database according the parameter Note: please consider your memory when the maxCount is huge

Parameters
typemessage type, TXT、VOICE、IMAGE etc.
timeStampthe timestamp for search
maxCountthe max number of message to search
fromwho the message from, used to search in group
Returns
the list of searched messages
List<EMMessage> com.hyphenate.chat.EMConversation.searchMsgFromDB ( String  keywords,
long  timeStamp,
int  maxCount,
String  from,
EMSearchDirection  direction 
)

search message from database according the parameter Note: please consider your memory when the maxCount is huge

Parameters
keywordsthe keywords in message.
timeStampthe timestamp for search
maxCountthe max number of message to search
fromwho the message from, used to search in group
Returns
the list of searched messages
List<EMMessage> com.hyphenate.chat.EMConversation.searchMsgFromDB ( long  startTimeStamp,
long  endTimeStamp,
int  maxCount 
)

search message from database according the parameter Note: please consider your memory when the maxCount is huge

Parameters
startTimeStampstart timestamp for search in.
startTimeStampend timestamp for search
maxCountthe max number of message to search
Returns
the list of searched messages
void com.hyphenate.chat.EMConversation.setExtField ( String  ext)

set conversation's extend field, extend field only stored in local database, not sync to network server.


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