agora_chat_SDK
3.8.2
agorajavachatSDK
|
Public Member Functions | |
void | sendMessage (final ChatMessage msg) |
void | ackConversationRead (String conversationId) throws ChatException |
void | ackMessageRead (String to, String messageId) throws ChatException |
void | ackGroupMessageRead (String to, String messageId, String ext) throws ChatException |
void | recallMessage (ChatMessage message) throws ChatException |
void | aysncRecallMessage (final ChatMessage message, final CallBack callback) |
ChatMessage | getMessage (String messageId) |
Conversation | getConversation (String id) |
Conversation | getConversation (String id, ConversationType type) |
Conversation | getConversation (String username, ConversationType type, boolean createIfNotExists) |
void | markAllConversationsAsRead () |
int | getUnreadMsgsCount () |
int | getUnreadMessageCount () |
void | saveMessage (ChatMessage message) |
boolean | updateMessage (ChatMessage message) |
void | downloadAttachment (final ChatMessage msg) |
void | downloadThumbnail (final ChatMessage msg) |
synchronized void | importMessages (List< ChatMessage > msgs) |
List< Conversation > | getConversationsByType (ConversationType type) |
void | downloadFile (final String remoteUrl, final String localFilePath, final Map< String, String > headers, final CallBack callback) |
Map< String, Conversation > | getAllConversations () |
Map< String, Conversation > | fetchConversationsFromServer () throws ChatException |
void | asyncFetchConversationsFromServer (final ValueCallBack< Map< String, Conversation >> callBack) |
void | loadAllConversations () |
boolean | deleteConversation (String username, boolean deleteMessages) |
void | addMessageListener (MessageListener listener) |
void | removeMessageListener (MessageListener listener) |
void | addConversationListener (ConversationListener listener) |
void | removeConversationListener (ConversationListener listener) |
void | setMessageListened (ChatMessage message) |
void | setVoiceMessageListened (ChatMessage message) |
boolean | updateParticipant (String from, String changeTo) |
CursorResult< GroupReadAck > | fetchGroupReadAcks (String msgId, int pageSize, String startAckId) throws ChatException |
void | asyncFetchGroupReadAcks (final String msgId, final int pageSize, final String startAckId, final ValueCallBack< CursorResult< GroupReadAck >> callBack) |
CursorResult< ChatMessage > | fetchHistoryMessages (String conversationId, ConversationType type, int pageSize, String startMsgId) throws ChatException |
void | asyncFetchHistoryMessage (final String conversationId, final ConversationType type, final int pageSize, final String startMsgId, final ValueCallBack< CursorResult< ChatMessage >> callBack) |
List< ChatMessage > | searchMsgFromDB (ChatMessage.Type type, long timeStamp, int maxCount, String from, Conversation.SearchDirection direction) |
List< ChatMessage > | searchMsgFromDB (String keywords, long timeStamp, int maxCount, String from, Conversation.SearchDirection direction) |
Protected Member Functions | |
ChatManager (ChatClient client, EMAChatManager manager) | |
Chat manager, responsible for managing conversations (such as: load, delete), sending messages, downloading attachments and so on Such as, send a text message:
ChatMessage message = ChatMessage.createTxtSendMessage(content, toChatUsername); ChatClient.getInstance().chatManager().sendMessage(message);
void io.agora.chat.ChatManager.ackConversationRead | ( | String | conversationId | ) | throws ChatException |
Send read conversation ack to server, only for single chat conversation Send it will inform the sever set the conversation reading to 0, and conversationist (with multiple devices) will receive a callback method ConversationListener#onConversationRead(String, String)
Send group message ack to sever, see ackGroupMessageRead(String, String, String)
Suggestion: the method can be called when enter the chat page, other session can call the method of ackMessageRead(String, String) , can reduce the number of call to ackMessageRead(String, String) when there are a large number of unread messages
conversationId | Conversation id |
ChatException | Maybe throws exception Error#USER_NOT_LOGIN, Error#SERVER_NOT_REACHABLE, Error#MESSAGE_INVALID and so on, see Error |
void io.agora.chat.ChatManager.ackGroupMessageRead | ( | String | to, |
String | messageId, | ||
String | ext | ||
) | throws ChatException |
Send group message ack to server Precondition: set ChatOptions#setRequireAck(boolean) and ChatMessage#setIsNeedGroupAck(boolean)
Send single chat message ack to server, see ackMessageRead(String, String); Send conversation ack to server, see ackConversationRead(String)
void io.agora.chat.ChatManager.ackMessageRead | ( | String | to, |
String | messageId | ||
) | throws ChatException |
Send read ack to server, only for single chat Precondition: set ChatOptions#setRequireAck(boolean)
Send group message ack to sever, see ackGroupMessageRead(String, String, String)
Suggestion: calls ackConversationRead(String) on entering a chat page, then calls the current method in other scenarios, can reduce the times this method is called.
to | the recipient id |
messageId | message id |
ChatException |
void io.agora.chat.ChatManager.addConversationListener | ( | ConversationListener | listener | ) |
Add conversation listener
listener | The conversation listener will to be set, see ConversationListener |
void io.agora.chat.ChatManager.addMessageListener | ( | MessageListener | listener | ) |
Add message listener Receives new messages and so on can set the method to listen, see MessageListener
listener | The message listener which is used to listen the incoming messages, see MessageListener |
void io.agora.chat.ChatManager.asyncFetchConversationsFromServer | ( | final ValueCallBack< Map< String, Conversation >> | callBack | ) |
Fetch conversations from server Default maximum return is 100.
Asynchronously method
void io.agora.chat.ChatManager.asyncFetchGroupReadAcks | ( | final String | msgId, |
final int | pageSize, | ||
final String | startAckId, | ||
final ValueCallBack< CursorResult< GroupReadAck >> | callBack | ||
) |
Fetch ack details for group messages from server Fetch by page Send group ack, see ackConversationRead(String)
Asynchronously method
msgId | The message id which need fetch receipt |
pageSize | The page size per time fetch group message receipt |
startAckId | The start id for fetch acks, can be null, if null start from the server lastest ack. |
callBack | Result callback, success execute the method ValueCallBack#onSuccess(Object), failure execute the method ValueCallBack#onError(int, String) |
void io.agora.chat.ChatManager.asyncFetchHistoryMessage | ( | final String | conversationId, |
final ConversationType | type, | ||
final int | pageSize, | ||
final String | startMsgId, | ||
final ValueCallBack< CursorResult< ChatMessage >> | callBack | ||
) |
Fetch conversation roam messages from server Fetch by page
Asynchronously method
conversationId | The conversation id which select to fetch roam message. |
type | The conversation type which select to fetch roam message. |
pageSize | Number fetched per time |
startMsgId | The start search roam message, if empty start from the server lastest message. |
callBack | Result callback, success execute the method ValueCallBack#onSuccess(Object), return messages from server and cursor for next fetch action; failue execute the method ValueCallBack#onError(int, String) |
void io.agora.chat.ChatManager.aysncRecallMessage | ( | final ChatMessage | message, |
final CallBack | callback | ||
) |
Recall the sent message
Asynchronously method
message | Message object |
callback | Send callback, see CallBack |
boolean io.agora.chat.ChatManager.deleteConversation | ( | String | username, |
boolean | deleteMessages | ||
) |
Delete conversation and messages from local database If set true for deleteMessages, delete the local chat history when delete the conversation
username | Conversation ID |
deleteMessages | Whether delete chat history when delete conversation |
void io.agora.chat.ChatManager.downloadAttachment | ( | final ChatMessage | msg | ) |
Download the message attachment Call the method if the attachment download fails
msg | Message to be download the attachment |
void io.agora.chat.ChatManager.downloadFile | ( | final String | remoteUrl, |
final String | localFilePath, | ||
final Map< String, String > | headers, | ||
final CallBack | callback | ||
) |
Download the file from server
remoteUrl | The remote file url |
localFilePath | The local file path |
headers | Http Request Headers |
callback | Download status callback, see CallBack |
void io.agora.chat.ChatManager.downloadThumbnail | ( | final ChatMessage | msg | ) |
Download the thumbnail if not downloaded before or downloaded failed
msg | The message to be downloaded thumbnail |
Map<String, Conversation> io.agora.chat.ChatManager.fetchConversationsFromServer | ( | ) | throws ChatException |
Fetch conversations from server, Default maximum return is 100.
Synchronization method will block the current thread
CursorResult<GroupReadAck> io.agora.chat.ChatManager.fetchGroupReadAcks | ( | String | msgId, |
int | pageSize, | ||
String | startAckId | ||
) | throws ChatException |
Fetch ack details for group messages from server. Fetch by page Send group ack, see ackConversationRead(String)
Synchronization method will block the current thread
msgId | The message id which need fetch receipt |
pageSize | The page size per time fetch group message receipt |
startAckId | The start id for fetch acks, can be null, if null start from the server lastest ack. |
CursorResult<ChatMessage> io.agora.chat.ChatManager.fetchHistoryMessages | ( | String | conversationId, |
ConversationType | type, | ||
int | pageSize, | ||
String | startMsgId | ||
) | throws ChatException |
Fetch conversation roam messages from server Fetch by page
Synchronization method will block the current thread
conversationId | The conversation id which select to fetch roam message |
type | The conversation type which select to fetch roam message, see ConversationType |
pageSize | Number fetched per time |
startMsgId | The start search roam message, if empty start from the server lastest message. |
Map<String, Conversation> io.agora.chat.ChatManager.getAllConversations | ( | ) |
Get all conversations from local Load from memory first, if not then load from local database
Conversation io.agora.chat.ChatManager.getConversation | ( | String | id | ) |
Get conversation object by the specified ID Return null if not find
id | Conversation ID |
Conversation io.agora.chat.ChatManager.getConversation | ( | String | id, |
ConversationType | type | ||
) |
Get conversation by conversation id and conversation type Return null if not find
id | Conversation ID |
type | The conversation type, see ConversationType |
Conversation io.agora.chat.ChatManager.getConversation | ( | String | username, |
ConversationType | type, | ||
boolean | createIfNotExists | ||
) |
Get conversation object by conversation id and conversation type If not find, either a new object or an empty object is returned based on the value of CreateIFNotExists
username | Conversation ID |
type | The conversation type, see ConversationType |
createIfNotExists | Whether Create conversation by the value if not find |
List<Conversation> io.agora.chat.ChatManager.getConversationsByType | ( | ConversationType | type | ) |
Get list of conversations by conversation type
type | The conversation type, see ConversationType |
ChatMessage io.agora.chat.ChatManager.getMessage | ( | String | messageId | ) |
get message through message id
messageId | message id |
int io.agora.chat.ChatManager.getUnreadMessageCount | ( | ) |
Get unread message count
int io.agora.chat.ChatManager.getUnreadMsgsCount | ( | ) |
Get unread message count
synchronized void io.agora.chat.ChatManager.importMessages | ( | List< ChatMessage > | msgs | ) |
Import messages to local database. Make sure the message's sender or receiver is current user Recommend import up to 1000 messages per operation
msgs | The message list of be imported |
void io.agora.chat.ChatManager.loadAllConversations | ( | ) |
Load all conversations from local database into memory Generally used after a successful login to speed up the loading of the conversation list
void io.agora.chat.ChatManager.markAllConversationsAsRead | ( | ) |
mark all messages as read For local conversations
void io.agora.chat.ChatManager.recallMessage | ( | ChatMessage | message | ) | throws ChatException |
Recall the sent message
Synchronization method block the current thread
message | Message object |
ChatException | See Error |
void io.agora.chat.ChatManager.removeConversationListener | ( | ConversationListener | listener | ) |
Remove the conversation listener After set addConversationListener(ConversationListener) need to remove the listener by calls this method
listener | the conversation listener set before |
void io.agora.chat.ChatManager.removeMessageListener | ( | MessageListener | listener | ) |
Remove the message listener After set addMessageListener(MessageListener) should calls this method
listener | The message listener set before need to remove |
void io.agora.chat.ChatManager.saveMessage | ( | ChatMessage | message | ) |
Save the message to memory and local database CMD type message not be stored in database
message | The emssage to store |
List<ChatMessage> io.agora.chat.ChatManager.searchMsgFromDB | ( | ChatMessage.Type | type, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
Conversation.SearchDirection | direction | ||
) |
Search message from database according the parameters Note: Cautious about memory usage when the maxCount is large, currently the limited number of search data is 400 at a time
type | Message type, TXT、VOICE、IMAGE and so on, see ChatMessage.Type |
timeStamp | The timestamp for search |
maxCount | The max number of message to search |
from | A user id or a group id searches for messages, usually refers to the conversation ID |
List<ChatMessage> io.agora.chat.ChatManager.searchMsgFromDB | ( | String | keywords, |
long | timeStamp, | ||
int | maxCount, | ||
String | from, | ||
Conversation.SearchDirection | direction | ||
) |
Search message from database based the parameters Note: Cautious about memory usage when the maxCount is large, currently the limited number of search data is 400 at a time
keywords | The keywords in message. |
timeStamp | The timestamp for search |
maxCount | The max number of message to search |
from | A user id or a group id searches for messages, usually refers to the conversation ID |
void io.agora.chat.ChatManager.sendMessage | ( | final ChatMessage | msg | ) |
Send message If is voice, picture and other message with attachment, SDK will automatically upload the attachment Can set whether upload to chat sever by ChatOptions#setAutoTransferMessageAttachments(boolean), the default value is true The send message status, can set listener by ChatMessage#setMessageStatusCallback(CallBack), we should set it before the method of sendMessage(), otherwise the listener may be recycled by the system
msg | Message object to be sent, not be null |
void io.agora.chat.ChatManager.setMessageListened | ( | ChatMessage | message | ) |
Set message to listened, used for voice message
message | The message object to set |
void io.agora.chat.ChatManager.setVoiceMessageListened | ( | ChatMessage | message | ) |
Set message to listened, used for voice message
message | The message object to set |
boolean io.agora.chat.ChatManager.updateMessage | ( | ChatMessage | message | ) |
Update the local message Update the memory and local database
message | The message objec to update |
boolean io.agora.chat.ChatManager.updateParticipant | ( | String | from, |
String | changeTo | ||
) |
Update database records, change username 'from' to 'changeTo', take effect on message table, conversation table, contacts, blacklist table Note: this operation does not update data stored in memory cache.
from | The userId before replace |
changeTo | The userId after replace |