Skip to main content

Delete Messages

For one-to-one chats, group chats, and system conversations, you can use the IMLib SDK to delete your historical messages. This supports deleting messages only from the local database, only from RC server-side historical messages, or simultaneously from both local and server-side storage.

All delete operations in the IMLib SDK (APIs listed in the table below) refer to deleting one or a set of messages from the current logged-in user's message history, without affecting other participants' message records in the conversation.

FeatureLocal/ServerAPI
[Delete specific messages locally (by messageId)]Local onlydeleteMessages
[Delete all local conversation history]Local onlydeleteMessages
[Delete specific messages in conversation (by message object)]Both local and serverdeleteRemoteMessage
[Delete conversation history (by timestamp)]Optional local-only or both local/server deletionclearHistoryMessages
[Delete server-side conversation history only (by timestamp)]Server onlyclearRemoteHistoryMessages
tip
  • By default, messages in one-to-one chats, group chats, and system conversations are stored in both the local database and on RC servers (default 6 months). The Cloud Storage for One-to-One and Group Messages service is enabled by default, so messages can be deleted from both local and remote history.
  • For one-to-one chats, group chats, and system conversations: When deleting remote messages via any interface using timestamp parameters, the server will not delete corresponding offline message compensation by default (this mechanism only activates when Multi-Device Message Synchronization is enabled). If users log in from another device or reinstall the app, they may still receive deleted messages through the message compensation mechanism. To completely remove compensated messages, [submit a ticket] to enable deleting offline message compensation when removing server-side history. When deleting remote messages by message object, the server will always delete corresponding compensated messages.
  • For one-to-one chats, group chats, and system conversations: If an admin or regular user wants to permanently delete a message from all participants' history, they should use the message recall feature. After successful recall, the original message content will be removed from all users' local and server-side history.
  • IMLib SDK doesn't provide interfaces for deleting chatroom messages. Local chatroom messages are automatically deleted when users exit. After enabling Chatroom Message Cloud Storage, use the server API Delete Messages to clear all users' remote chatroom history.
  • IMlib SDK provides APIs for deleting ultra group conversation history - see Delete Messages under Ultra Group Management.

Delete Specific Messages Locally (by messageId)

Delete messages stored in the local database by their messageId.

The Cloud Storage for One-to-One and Group Messages service is enabled by default. Server-side records of the deleting user won't be affected. The user may retrieve locally deleted messages when fetching history from the server.

Method Signature

- (void)deleteMessages:(NSArray<NSNumber *> *)messageIds
completion:(nullable void(^)(BOOL ret))completion;

Parameters

ParameterTypeDescription
messageIdsNSArray of NSNumberList of messageIds (must be NSNumber type). See MessageId property in Message Introduction.

Example

[[RCCoreClient sharedCoreClient] deleteMessages:@[@(message.messageId)] completion:^(BOOL ret) {
if (ret) {
// Success
} else {
// Failure
}
}];

Delete All Local Conversation History

Clear all local history messages for a specified one-to-one chat, group chat, or system conversation.

If Cloud Storage for One-to-One and Group Messages is enabled, server-side records remain unaffected. Users may retrieve locally deleted messages from server history.

Method Signature

- (void)clearMessages:(RCConversationType)conversationType
targetId:(NSString *)targetId
completion:(nullable void(^)(BOOL ret))completion;

Parameters

ParameterTypeDescription
conversationTypeRCConversationTypeConversation type (use ConversationType_PRIVATE for one-to-one)
targetIdNSStringConversation ID

Example

[[RCCoreClient sharedCoreClient] clearMessages:ConversationType_PRIVATE targetId:@"targetId" completion:^(BOOL ret) {
if (ret) {
// Success
} else {
// Failure
}
}];

Delete Specific Messages in Conversation (by Message Object)

tip
  • Requires Cloud Storage for One-to-One and Group Messages service. Deletes messages from both local and server.

Permanently delete messages from a user's one-to-one chat, group chat, or system conversation history. After deletion, messages become inaccessible both locally and from server history.

Method Signature

- (void)deleteRemoteMessage:(RCConversationType)conversationType
targetId:(NSString *)targetId
messages:(NSArray<RCMessage *> *)messages
success:(nullable void (^)(void))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;

Parameters

ParameterTypeDescription
conversationTypeRCConversationTypeConversation type (use ConversationType_PRIVATE for one-to-one)
targetIdNSStringConversation ID
messagesNSArray of RCMessageList of RCMessage objects to delete
successBlockBlockSuccess callback
errorBlockBlockFailure callback (returns RCErrorCode)

Example

[[RCCoreClient sharedCoreClient] 
deleteRemoteMessage:ConversationType_PRIVATE
targetId:@"targetId"
messages:messages
success:^{}
error:^(RCErrorCode status) {}];

Delete Conversation History (by Timestamp)

tip

Can clear both server and local messages. Server deletion requires Cloud Storage for One-to-One and Group Messages service.

Delete historical messages before a specified timestamp (recordTime) from a conversation. When clearRemote is YES, messages are deleted from both local and server storage.

Method Signature

- (void)clearHistoryMessages:(RCConversationType)conversationType
targetId:(NSString *)targetId
recordTime:(long long)recordTime
clearRemote:(BOOL)clearRemote
success:(nullable void (^)(void))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;

Parameters

ParameterTypeDescription
conversationTypeRCConversationTypeConversation type (use ConversationType_PRIVATE for one-to-one)
targetIdNSStringConversation ID
recordTimelong longTimestamp (deletes messages ≤ this value. Use 0 to delete all)
clearRemoteBOOLWhether to delete server messages
successBlockBlockSuccess callback
errorBlockBlockFailure callback (returns RCErrorCode)

Sample Code

[[RCCoreClient sharedCoreClient]
clearHistoryMessages:ConversationType_PRIVATE
targetId:@"targetId"
recordTime:recordTime
clearRemote:YES
success:^{}
error:^(RCErrorCode status) {}];

Delete Only Server-side Conversation History Messages (by Timestamp)

tip
  • This feature requires enabling the Cloud Storage for One-to-One and Group Messages service. This API only deletes messages from the server.
  • You can also directly delete server messages using the RCIM server API. For details, refer to the server documentation Message Deletion.

You can delete only the historical messages of a specified conversation stored on the server. This API provides a timestamp parameter (recordTime) to support deleting messages older than the specified time. If recordTime is set to 0, all historical messages of the conversation stored on the server will be deleted.

API Description



- (void)clearRemoteHistoryMessages:(RCConversationType)conversationType
targetId:(NSString *)targetId
recordTime:(long long)recordTime
success:(nullable void (^)(void))successBlock
error:(nullable void (^)(RCErrorCode status))errorBlock;

Parameter Description

ParameterTypeDescription
conversationTypeRCConversationTypeConversation type. For one-to-one chat, use ConversationType_PRIVATE
targetIdNSStringConversation ID
recordTimelong longMessage timestamp. By default, messages less than or equal to recordTime are deleted. If 0 is passed, all messages will be deleted.
successBlockBlockSuccess callback
errorBlockBlockFailure callback. The status parameter returns the error code RCErrorCode.

Sample Code

[[RCCoreClient sharedCoreClient]
clearRemoteHistoryMessages:ConversationType_PRIVATE
targetId:@"targetId"
recordTime:sentTime
success:^{}
error:^(RCErrorCode status) {}];