Skip to main content

Delete Messages

For one-to-one chat, group chat, and system conversation, RC supports app users to delete their historical messages through the client SDK. It supports deleting messages only from the local database, only from the RC server, or from both locations simultaneously.

The delete message operations in the SDK (APIs in the table below) refer to deleting one or a group of messages from the historical message records of the currently logged-in user, without affecting the historical message records of other users in the conversation.

FeatureLocal/ServerAPI
Delete specified messages (Message ID) locally onlyLocal onlydeleteMessages
Delete all historical messages of a conversation locallyLocal onlydeleteMessages
Delete specified messages (Message Object) in a conversationDelete from both local and serverdeleteRemoteMessage
Delete historical messages of a conversation (Timestamp)Optional: Delete locally only or from both local and serverclearHistoryMessages
Delete historical messages of a conversation (Timestamp) from server onlyServer onlyclearRemoteHistoryMessages
tip
  • By default, messages in one-to-one chat, group chat, and system conversation for app users are stored only in the local database, and can only be deleted locally. If the app (App Key/environment) has enabled Cloud Storage for One-to-One and Group Messages, the user's messages will also be stored on the RC server (default 6 months), and messages can be deleted from the remote historical message records.
  • For one-to-one chat and group chat, if any interface is used to delete remote messages by passing a timestamp, the server will not delete the corresponding offline message compensation by default (this mechanism only takes effect after the Multi-Device Message Synchronization switch is turned on). At this time, if you log in on another device or reinstall the app, you may still receive the deleted historical messages due to the message compensation mechanism. To completely delete message compensation, please submit a ticket to apply for enabling deleting offline message compensation for multi-device synchronization when deleting historical messages on the server. If remote messages are deleted by passing a message object, the server will definitely delete the corresponding messages in the message compensation.
  • For one-to-one chat and group chat, if an app administrator or a regular user wants to completely delete a message from the historical records of all participants in the conversation, the recall message function should be used. After the message is successfully recalled, the original message content will be deleted from the local and server historical message records of all users.
  • The client SDK does not provide an interface for deleting chatroom messages. The local chatroom messages of the current user will be automatically deleted when they exit the chatroom. After enabling the Chatroom Message Cloud Storage Service, if you need to clear the historical messages of all users in the chatroom, you can use the server API Delete Messages.

Delete Specified Messages (Message ID) Locally Only

App users can delete messages stored in the local database by message ID. The messages to be deleted can belong to different conversations.

If the app has enabled the Cloud Storage for One-to-One and Group Messages service, the historical message records of the user stored on the server will not be affected. If the user retrieves historical messages from the server, they may retrieve messages that have been deleted locally.

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

An array of message IDs to be deleted needs to be provided.

ParameterTypeDescription
messageIdsNSArray of NSNumberList of messageIds, elements need to be of NSNumber type. See the MessageId property in Message Introduction.

Delete All Historical Messages of a Conversation Locally

If an app user wants to locally clear their historical records of one-to-one chat, group chat, or system conversation, they can delete all messages of the specified conversation stored in the local database. If the app has enabled the Cloud Storage for One-to-One and Group Messages service, the historical message records of the user stored on the server will not be affected. If the user retrieves historical messages from the server, they may retrieve messages that have been deleted locally.

This interface allows deleting messages of only one specified conversation at a time. The conversation is specified by the conversation type and conversation ID parameters.

[[RCCoreClient sharedCoreClient] clearMessages:ConversationType_PRIVATE targetId:@"targetId" completion:^(BOOL ret) {
if (ret) {
// Deletion successful
} else {
// Deletion failed
}
}];
ParameterTypeDescription
conversationTypeRCConversationTypeConversation type, for one-to-one chat, pass ConversationType_PRIVATE
targetIdNSStringConversation ID

Delete Specified Messages (Message Object) in a Conversation

tip

If the app has enabled the Cloud Storage for One-to-One and Group Messages service, you can call the following interface to delete the historical message records of the app user on the RC server. This interface deletes messages from both local and server simultaneously.

If an app user wants to completely delete a message from their historical records of one-to-one chat, group chat, or system conversation, they can use deleteRemoteMessage to delete the message from both local and server. After successful deletion, the user cannot retrieve the message from the local database. If they retrieve historical messages from the server, they also cannot retrieve the deleted message.

This interface allows deleting one or a group of messages in a specified conversation at a time. Please ensure that all provided messages belong to the same conversation (specified by conversation type and conversation ID).

[[RCIMClient sharedRCIMClient]
deleteRemoteMessage:ConversationType_PRIVATE
targetId:@"targetId"
messages:messages
success:^{}
error:^(RCErrorCode status) {}];
ParameterTypeDescription
conversationTypeRCConversationTypeConversation type, for one-to-one chat, pass ConversationType_PRIVATE
targetIdNSStringConversation ID
messagesNSArray of RCMessageList of RCMessage objects to be deleted
successBlockBlockCallback for success
errorBlockBlockCallback for failure. The status parameter returns the error code RCErrorCode.

Delete Historical Messages of a Conversation (Timestamp)

tip

If the app has enabled the Cloud Storage for One-to-One and Group Messages service, you can call the following interface and specify through parameters to delete the historical message records of the app user on the RC server simultaneously.

If an app user wants to delete a segment of historical message records from their one-to-one chat, group chat, or system conversation, they can use clearHistoryMessages to delete messages in the conversation that are earlier than a certain point in time (recordTime). The clearRemote parameter controls whether to delete the corresponding historical messages on the server simultaneously.

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

If the clearRemote parameter is set to YES, it means that the corresponding messages on the server need to be deleted simultaneously. This interface will delete messages earlier than (recordTime) from both local and server. After the server messages are deleted, the user cannot retrieve the deleted messages from the server. This interface allows deleting messages of only one specified conversation at a time. The conversation is specified by the conversation type and conversation ID parameters.

ParameterTypeDescription
conversationTypeRCConversationTypeConversation type, for one-to-one chat, pass ConversationType_PRIVATE
targetIdNSStringConversation ID
recordTimelong longMessage timestamp. By default, messages less than or equal to recordTime are deleted. If 0 is passed, all messages are deleted.
clearRemoteBOOLWhether to delete messages on the server simultaneously
successBlockBlockCallback for success
errorBlockBlockCallback for failure. The status parameter returns the error code RCErrorCode.

Delete Historical Messages of a Conversation (Timestamp) from Server Only

tip
  • If the app has enabled the Cloud Storage for One-to-One and Group Messages service, you can call the following interface to delete the historical message records of the app user on the RC server. This interface deletes messages from the server only.
  • You can also directly delete server messages using the RC IM server API. For specific operations, please refer to the server documentation Delete Messages.

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

[[RCIMClient sharedRCIMClient]
clearRemoteHistoryMessages:ConversationType_PRIVATE
targetId:@"targetId"
recordTime:sentTime
success:^{}
error:^(RCErrorCode status) {}];
ParameterTypeDescription
conversationTypeRCConversationTypeConversation type, for one-to-one chat, pass ConversationType_PRIVATE
targetIdNSStringConversation ID
recordTimelong longMessage timestamp. By default, messages less than or equal to recordTime are deleted. If 0 is passed, all messages are deleted.
successBlockBlockCallback for successful deletion
errorBlockBlockCallback for failed deletion. The status parameter returns the error code RCErrorCode.