NIMConversationManager Protocol Reference

Conforms to NSObject
Declared in NIMConversationManagerProtocol.h

Overview

Conversation manager

– deleteMessage: required method

Delete a message

- (void)deleteMessage:(NIMMessage *)message

Parameters

message

message to be deleted

Discussion

Delete a message

Declared In

NIMConversationManagerProtocol.h

– deleteMessage:option: required method

Delete a message

- (void)deleteMessage:(NIMMessage *)message option:(nullable NIMDeleteMessageOption *)option

Parameters

message

message to be deleted

option

option for deleting a message

Discussion

Delete a message

Declared In

NIMConversationManagerProtocol.h

– deleteMessageFromServer:ext:completion: required method

Delete a local message, and server history, roaming message

- (void)deleteMessageFromServer:(NIMMessage *)message ext:(nullable NSString *)ext completion:(nullable NIMRemoveRemoteMessageBlock)block

Parameters

message

message to be deleted

ext

extension field

block

Completion callback

Discussion

Delete a local message, and server history, roaming message

Declared In

NIMConversationManagerProtocol.h

– deleteAllmessagesInSession:option: required method

Delete all messages in a session

- (void)deleteAllmessagesInSession:(NIMSession *)session option:(nullable NIMDeleteMessagesOption *)option

Parameters

session

session to be deleted

option

option for deleting a message

Discussion

Delete all messages in a session

Declared In

NIMConversationManagerProtocol.h

– deleteAllMessages: required method

Delete all messages

- (void)deleteAllMessages:(nullable NIMDeleteMessagesOption *)option

Parameters

option

option for deleting a message

Discussion

Delete all messages

calling this interface will only trigger allMessagesDeleted, other callbacks for a single recentSession will not be called.

Declared In

NIMConversationManagerProtocol.h

– deleteMessagesInSession:option:completion: required method

Delete messages within a specified range, such as a specified time range

- (void)deleteMessagesInSession:(NIMSession *)session option:(nullable NIMBatchDeleteMessagesOption *)option completion:(nullable NIMBatchDeleteMessagesBlock)block

Parameters

session

Target session

option

option for deleting a message

block

Completion callback

Discussion

Delete messages within a specified range, such as a specified time range

Declared In

NIMConversationManagerProtocol.h

– deleteAllRemoteMessagesInSession:options:completion: required method

Delete all messages in a session from the local storage and on the cloud. After all messages are deleted, the API for querying cloud message history will not be able to return these messages.

- (void)deleteAllRemoteMessagesInSession:(NIMSession *)session options:(NIMSessionDeleteAllRemoteMessagesOptions *)options completion:(NIMSessionDeleteAllRemoteMessagesCompletionBlock)completion

Parameters

session

Target session

options

options for clearing history messages

block

Completion callback

Discussion

Delete all messages in a session from the local storage and on the cloud. After all messages are deleted, the API for querying cloud message history will not be able to return these messages.

Declared In

NIMConversationManagerProtocol.h

– deleteRemoteMessages:exts:completion: required method

Delete multiple messages at a time. Messages stored on the server and local storage are deleted. All messages must belong to the same session.

- (void)deleteRemoteMessages:(NSArray<NIMMessage*> *)messages exts:(nullable NSDictionary<NSString*,NSString*> *)exts completion:(nullable NIMDeleteRemoteMessagesCompletionBlock)completion

Parameters

messages

messages in array

exts

key is the message ID and value is the extension information corresponding to the deleted message.

completion

Completion callback

Discussion

Delete multiple messages at a time. Messages stored on the server and local storage are deleted. All messages must belong to the same session.

Declared In

NIMConversationManagerProtocol.h

– addEmptyRecentSessionBySession: required method

Add a recent session

- (void)addEmptyRecentSessionBySession:(NIMSession *)session

Parameters

session

session to be added

Discussion

Add a recent session

asynchronous method call

Declared In

NIMConversationManagerProtocol.h

– addEmptyRecentSessionBySession:option: required method

Add a recent session

- (void)addEmptyRecentSessionBySession:(NIMSession *)session option:(NIMAddEmptyRecentSessionBySessionOption *)option

Parameters

session

session to be added

option

option

Discussion

Add a recent session

asynchronous method call

Declared In

NIMConversationManagerProtocol.h

– deleteRecentSession: required method

Delete a recent session

- (void)deleteRecentSession:(NIMRecentSession *)recentSession

Parameters

recentSession

Recent session to be deleted

Discussion

Delete a recent session

async method to delete a recent session but keep in-session messages

Declared In

NIMConversationManagerProtocol.h

– deleteRecentSession:option:completion: required method

Delete a recent session

- (void)deleteRecentSession:(NIMRecentSession *)recentSession option:(NIMDeleteRecentSessionOption *)option completion:(NIMRemoveRemoteSessionBlock)completion

Parameters

recentSession

Recent session to be deleted

option

Specify whether to delete roaming messages. The value of isDeleteRoamMessage is set to NO by default.

completion

Completion callback

Discussion

Delete a recent session

async method to delete a recent session but keep in-session messages

Declared In

NIMConversationManagerProtocol.h

– markAllMessagesRead required method

Mark all messages in a session as read

- (void)markAllMessagesRead

Discussion

Mark all messages in a session as read

async method. The message is marked with the set state. Does not trigger a callback for a single recentSession update, but - (void)allMessagesRead.

Declared In

NIMConversationManagerProtocol.h

– batchMarkMessagesReadInSessions: required method

Mark messages in multiple sessions read

- (void)batchMarkMessagesReadInSessions:(NSArray<NIMSession*> *)sessions

Discussion

Mark messages in multiple sessions read

async method call The method does not trigger a callback for updating a recent session, but - onBatchMarkMessagesReadInSessions:

Declared In

NIMConversationManagerProtocol.h

– batchMarkMessagesReadInSessions:completion: required method

Mark messages in multiple sessions read

- (void)batchMarkMessagesReadInSessions:(NSArray<NIMSession*> *)sessions completion:(NIMBatchSendACKSessionsBlock)completion

Parameters

completion

completion callback On partial success, failed sessions can be obtained from the sessions parameter of NIMBatchSendACKSessionsBlock

Discussion

Mark messages in multiple sessions read

async method call The method does not trigger a callback for updating a recent session, but - onBatchMarkMessagesReadInSessions:

Declared In

NIMConversationManagerProtocol.h

– markAllMessagesReadInSession: required method

Mark all messages in a session as read

- (void)markAllMessagesReadInSession:(NIMSession *)session

Parameters

session

target session

Discussion

Mark all messages in a session as read

async method. Messages will be marked with the set state

Declared In

NIMConversationManagerProtocol.h

– markAllMessagesReadInSession:completion: required method

Mark all messages in a session as read

- (void)markAllMessagesReadInSession:(NIMSession *)session completion:(NIMSendACKSessionsBlock)completion

Parameters

session

completion callback

Discussion

Mark all messages in a session as read

async method. Messages will be marked with the set state

Declared In

NIMConversationManagerProtocol.h

– updateMessage:forSession:completion: required method

Update locally stored message records

- (void)updateMessage:(NIMMessage *)message forSession:(NIMSession *)session completion:(nullable NIMUpdateMessageBlock)completion

Parameters

message

message to be updated

session

session to be updated

completion

Completion callback

Discussion

Update locally stored message records

To ensure the integrity of stored messages, the update interface provided to the upper layer only allows to update the following fields: the local extension field (LocalExt) of all messages and the message object (messageObject) of custom messages.

Declared In

NIMConversationManagerProtocol.h

– saveMessage:forSession:completion: required method

Write message data to storage

- (void)saveMessage:(NIMMessage *)message forSession:(NIMSession *)session completion:(nullable NIMUpdateMessageBlock)completion

Parameters

message

message to be updated

session

session to be updated

completion

Completion callback

Discussion

Write message data to storage

When a message is saved successfully, it will receive the notification returned by onRecvMessages: in NIMChatManagerDelegate. Inserting an existing message is not allowed.

Declared In

NIMConversationManagerProtocol.h

– importRecentSessions:completion: required method

Import recent sessions

- (void)importRecentSessions:(NSArray<NIMImportedRecentSession*> *)importedRecentSession completion:(nullable NIMImportRecentSessionsBlock)completion

Parameters

importedRecentSession

recent sessions to be imported

completion

completion callback

Discussion

Import recent sessions

After recent sessions are imported, you will not receive a callback for recentSession changes in NIMChatManagerDelegate. You can handle it in the completion parameter. Inserting existing Recent sessions is not allowed..

Declared In

NIMConversationManagerProtocol.h

– messagesInSession:message:limit: required method

Load several messages before a message in a session from the local database.

- (nullable NSArray<NIMMessage*> *)messagesInSession:(NIMSession *)session message:(nullable NIMMessage *)message limit:(NSInteger)limit

Parameters

session

session to which the messages belong

message

The earliest message, if no messages exist, pass in nil.

limit

limit of returned messages

Return Value

messages sorted by time in ascending order

Discussion

Load several messages before a message in a session from the local database.

Declared In

NIMConversationManagerProtocol.h

– messagesInSession:message:limit:completion: required method

Load several messages before a message in a session from the local database.

- (void)messagesInSession:(NIMSession *)session message:(nullable NIMMessage *)message limit:(NSInteger)limit completion:(NIMFetchMessageHistoryBlock)completion

Parameters

session

session to which the messages belong

message

The earliest message, if no messages exist, pass in nil.

limit

limit of returned messages

completion

Completion callback

Discussion

Load several messages before a message in a session from the local database.

Declared In

NIMConversationManagerProtocol.h

– messagesInSession:messageIds: required method

Get messages by MessageId

- (nullable NSArray<NIMMessage*> *)messagesInSession:(NIMSession *)session messageIds:(NSArray<NSString*> *)messageIds

Parameters

session

session to which the messages belong

messageIds

message IDs

Return Value

messages sorted by time in ascending order

Discussion

Get messages by MessageId

Declared In

NIMConversationManagerProtocol.h

– allUnreadCount required method

Get the unread count

- (NSInteger)allUnreadCount

Return Value

unread count

Discussion

Get the unread count

the method can only be called on the main thread, including conversations that ignore alerts

Declared In

NIMConversationManagerProtocol.h

– allUnreadCount: required method

Get all unread counts of recent sessions with or without notification enabled

- (NSInteger)allUnreadCount:(BOOL)notify

Parameters

notify

enable or disable notifications

Return Value

unread count

Discussion

Get all unread counts of recent sessions with or without notification enabled

Only notify state != NIMTeamNotifyStateNone, notifications are not allowed for groups

Declared In

NIMConversationManagerProtocol.h

– allRecentSessions required method

Get all recent sessions

- (nullable NSArray<NIMRecentSession*> *)allRecentSessions

Return Value

list of all recent sessions

Discussion

Get all recent sessions

The SDK saves sessions in the form of map. When calling this method, sessions will be sorted. It will be time-consuming when the amount of data is large. By default, this method queries all sessions synchronously. When the amount of data is large, it will be time-consuming and the main thread may be stuck. In this case, you can set the asyncLoadRecentSessionEnabled property in NIMSDKConfig to be YES, then the interface can return first 100 recent sessions. When all sessions are loaded, didLoadAllRecentSessionCompletion is called, and then call this interface to return all sessions, you update the UI display in time for the didLoadAllRecentSessionCompletion callback.

Declared In

NIMConversationManagerProtocol.h

– allRecentSessionsWithOption: required method

Get all recent sessions

- (nullable NSArray<NIMRecentSession*> *)allRecentSessionsWithOption:(NIMRecentSessionOption *)option

Return Value

list of all recent sessions

Discussion

Get all recent sessions

The SDK saves sessions in the form of map. When calling this method, sessions will be sorted. It will be time-consuming when the amount of data is large. Different from the result returned by allRecentSessions, the recent sessions returned by this interface are new object created based on allRecentSessions. You must manage on your own, and all callbacks do not return any session queried by this interface.

Declared In

NIMConversationManagerProtocol.h

– recentSessionBySession: required method

Return the corresponding recent session information based on the current session

- (nullable NIMRecentSession *)recentSessionBySession:(NIMSession *)session

Parameters

session

session

Return Value

recent session info, or nil if not found

Discussion

Return the corresponding recent session information based on the current session

Declared In

NIMConversationManagerProtocol.h

– fetchServerSessions:completion: required method

Get paginated history messages from the server.

- (void)fetchServerSessions:(nullable NIMFetchServerSessionOption *)option completion:(nullable NIMFetchRecentSessionsHistoryBlock)completion

Parameters

option

pagination option. Optional, If unspecified, all history messages are obtained.

completion

Completion callback

Discussion

Get paginated history messages from the server.

Declared In

NIMConversationManagerProtocol.h

– fetchServerSessionBySession:completion: required method

Get messages from the server.

- (void)fetchServerSessionBySession:(NIMSession *)session completion:(nullable NIMFetchRecentSessionHistoryBlock)completion

Parameters

session

Target session

completion

Completion callback

Discussion

Get messages from the server.

Declared In

NIMConversationManagerProtocol.h

– updateServerSessionExt:session:completion: required method

Update messages from the server

- (void)updateServerSessionExt:(NSString *)ext session:(NIMSession *)session completion:(nullable NIMRemoteRecentSessionBlock)completion

Parameters

ext

extension

session

Target recent session

completion

Completion callback

Discussion

Update messages from the server

Declared In

NIMConversationManagerProtocol.h

– deleteServerSessions:completion: required method

Delete sessions from the server

- (void)deleteServerSessions:(NSArray<NIMSession*> *)sessions completion:(nullable NIMRemoteRecentSessionBlock)completion

Parameters

sessions

Target sessions

completion

Completion callback

Discussion

Delete sessions from the server

Declared In

NIMConversationManagerProtocol.h

– fetchMessageHistory:option:result: required method

Get several messages before a message in a session from the server.

- (void)fetchMessageHistory:(NIMSession *)session option:(NIMHistoryMessageSearchOption *)option result:(nullable NIMFetchMessageHistoryBlock)result

Parameters

session

session to which the messages belong

option

search option

result

list of loaded messages

Discussion

Get several messages before a message in a session from the server.

This interface does not support querying chat room messages. For information about querying chat room messages, see NIMChatroomManagerProtocol.

Declared In

NIMConversationManagerProtocol.h

– retrieveServerMessages:option:result: required method

Retrieve messages from the server based on keywords

- (void)retrieveServerMessages:(NIMSession *)session option:(NIMMessageServerRetrieveOption *)option result:(nullable NIMRetrieveServerMessagesBlock)result

Parameters

session

session to which the messages belong

option

query option

result

list of loaded messages

Discussion

Retrieve messages from the server based on keywords

The queried content is case insensitive. The coninterface does not support querying chat room messages. For information about querying chat room messages, see NIMChatroomManagerProtocol.

Declared In

NIMConversationManagerProtocol.h

– retrieveServerMessages:result: required method

Retrieve messages from the server based on keywords

- (void)retrieveServerMessages:(NIMMessageFullKeywordSearchOption *)option result:(nullable NIMRetrieveServerMessagesBlock)result

Parameters

option

query option

result

list of loaded messages

Discussion

Retrieve messages from the server based on keywords

The retrieved messages. The interface supports P2P and group messages, not chat room and supergroup messages.

Declared In

NIMConversationManagerProtocol.h

– retrieveServerMessagesOrderByTime:result: required method

Global search for history messages on the cloud by time not session group

- (void)retrieveServerMessagesOrderByTime:(NIMMessageFullKeywordSearchOrderByTimeOption *)option result:(nullable NIMRetrieveServerMessagesBlock)result

Parameters

option

query option. sessionLimit is an invalid variable

result

retrieved messages

Discussion

Global search for history messages on the cloud by time not session group

retrieved messages

Declared In

NIMConversationManagerProtocol.h

– searchMessages:option:result: required method

Search local in-session messages

- (void)searchMessages:(NIMSession *)session option:(NIMMessageSearchOption *)option result:(nullable NIMSearchMessageBlock)result

Parameters

session

session to which the messages belong

option

search option

result

list of loaded messages

Discussion

Search local in-session messages

Declared In

NIMConversationManagerProtocol.h

– searchAllMessages:result: required method

Global search for local messages

- (void)searchAllMessages:(NIMMessageSearchOption *)option result:(nullable NIMGlobalSearchMessageBlock)result

Parameters

option

search option

result

retrieved messages

Discussion

Global search for local messages

Declared In

NIMConversationManagerProtocol.h

– deleteRemoteSessions:completion: required method

Delete recent sessions from the server

- (void)deleteRemoteSessions:(NSArray<NIMSession*> *)sessions completion:(nullable NIMRemoveRemoteSessionBlock)completion

Parameters

sessions

List of sessions to be deleted, only NIMSession internally

completion

Callback for completing the update

Discussion

Delete recent sessions from the server

After calling this interface successfully, messages before the current session will not roam to other devices

Declared In

NIMConversationManagerProtocol.h

– deleteSelfRemoteSession:option:completion: required method

Clear P2P messages of a specified session on the server

- (void)deleteSelfRemoteSession:(NIMSession *)session option:(nullable NIMClearMessagesOption *)option completion:(nullable NIMRemoveRemoteSessionBlock)completion

Parameters

session

Target session

option

option

completion

Completion callback

Discussion

Clear P2P messages of a specified session on the server

only supports P2P sessions. Clearing the user’s server messages will not affect the peer. If the option is not set, the server will clear the roaming messages at the same time by default.

Declared In

NIMConversationManagerProtocol.h

– updateRecentLocalExt:recentSession: required method

Update local extension for recent sessions

- (void)updateRecentLocalExt:(nullable NSDictionary *)ext recentSession:(NIMRecentSession *)recentSession

Parameters

ext

extension

recentSession

Recent session to be updated

Discussion

Update local extension for recent sessions

This extension will not be synced with other clients. tThe upper layer must ensure that NSDictionary can be converted to JSON.

Declared In

NIMConversationManagerProtocol.h

– exportMeessageInfosWithDelegate:progress:completion: required method

Export history messages to local storage

- (void)exportMeessageInfosWithDelegate:(id<NIMExportMessageDelegate>)delegate progress:(NIMExportMessageProgress)progress completion:(NIMExportMessageComletion)completion

Parameters

delegate

custom message processing delegate

progress

callback for export progress

completion

completion callback

Discussion

Export history messages to local storage

Declared In

NIMConversationManagerProtocol.h

– importMessageInfosAtPath:delegate:progress:completion: required method

Import history messages

- (void)importMessageInfosAtPath:(NSString *)infoFilePath delegate:(id<NIMImportMessageDelegate>)delegate progress:(NIMImportMessageProgress)progress completion:(NIMImportMessageCompletion)completion

Parameters

infoFilePath

file path of decoded and serialized local history messages

delegate

custom message processing delegate

progress

callback for import progress

completion

completion callback

Discussion

Import history messages

Declared In

NIMConversationManagerProtocol.h

– cancelMigrateMessages required method

Cancel importing or exporting history messages

- (void)cancelMigrateMessages

Discussion

Cancel importing or exporting history messages

Declared In

NIMConversationManagerProtocol.h

– updateMigrateMessageInfoWithURL:key:completion: required method

Update history message backup

- (void)updateMigrateMessageInfoWithURL:(NSString *)URL key:(NSString *)key completion:(NIMUpdateMigrateMessageCompletion)completion

Parameters

URL

URL of a history message backup

key

encryption key for history message backup

completion

completion callback

Discussion

Update history message backup

Declared In

NIMConversationManagerProtocol.h

– fetchMigrateMessageInfo: required method

Get the information about a history message backup

- (void)fetchMigrateMessageInfo:(NIMFetchMigrateMessageCompletion)completion

Parameters

completion

completion callback

Discussion

Get the information about a history message backup

Declared In

NIMConversationManagerProtocol.h

– decodeMessageFromData: required method

Unserialize message data

- (NIMMessage *)decodeMessageFromData:(NSData *)encodeData

Parameters

encodeData

serialized data

Return Value

Message object

Discussion

Unserialize message data

The interface is used to unserialize message data and works together with encodeMessageToData. The interface can serialize local messages

Declared In

NIMConversationManagerProtocol.h

– encodeMessageToData: required method

Serialized messages

- (NSData *)encodeMessageToData:(NIMMessage *)message

Parameters

message

mesage object

Return Value

serialized data

Discussion

Serialized messages

The interface is used to serialize messages and works together with decodeMessageFromData. The interface can serialize local messages

Declared In

NIMConversationManagerProtocol.h

– incompleteSessionInfoBySession:completion: required method

Query incomplete session info fo roaming messages

- (void)incompleteSessionInfoBySession:(NIMSession *)session completion:(nullable NIMIncompleteSessionsBlock)completion

Parameters

session

Target session

completion

The callback when the query is complete.

Discussion

Query incomplete session info fo roaming messages

Declared In

NIMConversationManagerProtocol.h

– allIncompleteSessionInfos: required method

Query all incomplete session info

- (void)allIncompleteSessionInfos:(NIMIncompleteSessionsBlock)completion

Parameters

completion

The callback when the query is complete.

Discussion

Query all incomplete session info

Declared In

NIMConversationManagerProtocol.h

– updateIncompleteSessions:completion: required method

Update all incomplete sessions

- (void)updateIncompleteSessions:(NSArray<NIMMessage*> *)messages completion:(nullable NIMUpdateIncompleteSessionsBlock)completion

Parameters

messages

message object, update the session, severId, timestamp, and from fields of NIMMessage.

completion

The callback when the query is complete.

Discussion

Update all incomplete sessions

Declared In

NIMConversationManagerProtocol.h

– removeIncompleteSessionInfoBySession: required method

Remove an incomplete session info by session

- (void)removeIncompleteSessionInfoBySession:(NIMSession *)session

Parameters

session

Target session

Discussion

Remove an incomplete session info by session

Declared In

NIMConversationManagerProtocol.h

– removeAllIncompleteSessionInfos required method

Remove all incomplete sessions info by session

- (void)removeAllIncompleteSessionInfos

Discussion

Remove all incomplete sessions info by session

Declared In

NIMConversationManagerProtocol.h

– addDelegate: required method

Add a notification object

- (void)addDelegate:(id<NIMConversationManagerDelegate>)delegate

Parameters

delegate

notification object

Discussion

Add a notification object

Declared In

NIMConversationManagerProtocol.h

– removeDelegate: required method

Delete a notification object

- (void)removeDelegate:(id<NIMConversationManagerDelegate>)delegate

Parameters

delegate

notification object

Discussion

Delete a notification object

Declared In

NIMConversationManagerProtocol.h