Delete Messages
Ultra group conversation messages are stored on the server (with free storage for 7 days) and in users' local databases. You can use the IMLib SDK to delete your historical messages, supporting deletion from either the local database only, the RC server only, or both local and server simultaneously.
- Message deletion operations on the client side only remove messages from the current logged-in user's historical records, without affecting other users' message history in the conversation.
- If an App administrator or regular user wants to completely delete a message across all ultra group members' chat histories, they should use the recall message feature on either the client or server side. After successful recall, the original message content will be removed from all users' local and server-side historical records.
| Feature | Local/Server | API |
|---|---|---|
| Delete Messages from All Channels Locally (Timestamp) | Local Only | deleteUltraGroupMessagesForAllChannel |
| Delete Messages from Specified Channel Locally (Timestamp) | Local Only | deleteUltraGroupMessages |
| Delete Messages from Specified Channel on Server (Timestamp) | Server Only | deleteRemoteUltraGroupMessages |
| Delete Messages Locally and Remotely (Message Object) | Both Local and Server | deleteRemoteMessage |
Delete Messages from All Channels Locally (Timestamp)
Deletes historical messages before a specified Unix timestamp (in milliseconds) from all channels in the local database. Each operation applies to a single ultra group only; batch deletion across multiple ultra groups is not supported.
Use the deleteUltraGroupMessagesForAllChannel method to delete local historical messages before a specified timestamp across all channels in an ultra group conversation. The timestamp must be in Unix milliseconds format. Each operation targets a single ultra group; batch deletion across multiple ultra groups is not supported. Server-side message records for this user remain unaffected. If the user retrieves historical messages from the server, previously deleted local messages may reappear.
Method Signature
ChannelClient.getInstance().deleteUltraGroupMessagesForAllChannel(targetId, timestamp,callback);
Parameters
| Parameter | Type | Description |
|---|---|---|
| targetId | String | The targetId of the ultra group conversation. |
| timestamp | long | Timestamp in milliseconds. Messages before this timestamp will be deleted. Pass 0 to delete all local historical messages for this conversation. |
| callback | IRongCoreCallback.ResultCallback<Boolean> | Callback for deletion result. |
Example Code
String targetId = "Conversation ID";
String timestamp = 0;
ChannelClient.getInstance().deleteUltraGroupMessagesForAllChannel(targetId, timestamp,
new IRongCoreCallback.ResultCallback<Boolean>() {
/**
* Success callback
*/
@Override
public void onSuccess(Boolean bool) {
}
/**
* Failure callback
* @param errorCode Error code
*/
@Override
public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) {
}
});
Delete Messages from Specified Channel Locally (Timestamp)
Deletes local historical messages before a specified Unix timestamp (in milliseconds) from a designated channel in an ultra group conversation. Each operation applies to a single ultra group only. Server-side message records for this user remain unaffected.
Method
ChannelClient.getInstance().deleteUltraGroupMessages(targetId, channelId, timestamp,callback);
Parameters
| Parameter | Type | Description |
|---|---|---|
| targetId | String | The targetId of the ultra group conversation. |
| channelId | String | The channelId of the ultra group channel. |
| recordTime | long | Timestamp in milliseconds. Messages before this timestamp will be deleted. Pass 0 to delete all local historical messages for this channel. |
| callback | IRongCoreCallback.ResultCallback<Boolean> | Callback for deletion result. |
Example Code
String targetId = "Ultra Group ID";
String channelId = "Channel ID";
String recordTime = 0;
ChannelClient.getInstance().deleteUltraGroupMessages(targetId, channelId, timestamp,
new IRongCoreCallback.ResultCallback<Boolean>() {
/**
* Success callback
*/
@Override
public void onSuccess(Boolean bool) {
}
/**
* Failure callback
* @param errorCode Error code
*/
@Override
public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) {
}
});
Delete Messages from Specified Channel on Server (Timestamp)
Deletes server-side historical messages before a specified Unix timestamp (in milliseconds) from a designated channel in an ultra group conversation. Each operation applies to a single ultra group only. Local message records on the client remain unaffected.
After enabling ultra group services for your App in the RC Console, historical message storage (free for 7 days) is automatically activated.
Method
ChannelClient.getInstance().deleteRemoteUltraGroupMessages(targetId, channelId, timestamp,callback);
Parameters
| Parameter | Type | Description |
|---|---|---|
| targetId | String | The targetId of the ultra group conversation. |
| channelId | String | The channelId of the ultra group channel. |
| recordTime | long | Timestamp in milliseconds. Messages before this timestamp will be deleted. Pass 0 to delete all server-side historical messages for this channel. |
| callback | IRongCoreCallback.ResultCallback<Boolean> | Callback for deletion result. |
Example Code
String targetId = "Ultra Group ID";
String channelId = "Channel ID";
String timestamp = 0;
ChannelClient.getInstance().deleteRemoteUltraGroupMessages(targetId, channelId, timestamp,
new IRongCoreCallback.ResultCallback<Boolean>() {
/**
* Success callback
*/
@Override
public void onSuccess(Boolean bool) {
}
/**
* Failure callback
* @param errorCode Error code
*/
@Override
public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) {
}
});
Delete Messages from Local and Remote by Message Object in Specified Channel
If you want to permanently delete a set of messages from your ultra group conversation history, you can use the deleteRemoteMessages method by passing in the list of [Message] objects to be deleted.
After successful deletion, you cannot retrieve the messages from the local database. If you fetch historical messages from the server, the deleted messages will also be unavailable.
Interface
ChannelClient.getInstance().deleteRemoteMessages(conversationType, targetId, channelId, messages, callback);
#### Parameter Description
| Parameter | Type | Description |
|:-----------------:|:-----------------------------------------:|:---------------------------------------------------------------------------|
| conversationType | [ConversationType] | Conversation type. Chatrooms are not supported. |
| targetId | String | Conversation ID |
| channelId | String | Ultra group channel ID |
| messages | Message[] | Array of [Message] objects to be deleted. Ensure all messages belong to the same conversation. |
| callback | IRongCoreCallback.ResultCallback\<Boolean\> | Interface callback |
```java
ConversationType conversationType = ConversationType.ULTRA_GROUP;
String targetId = "Conversation ID";
Message[] messages = {message1, message2};
RongCoreClient.getInstance().deleteRemoteMessages(conversationType, targetId, messages, new IRongCoreCallback.OperationCallback() {
/**
* Success callback for message deletion
*/
@Override
public void onSuccess() {
}
/**
* Failure callback for message deletion
* @param errorCode Error code
*/
@Override
public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) {
}
});
[Message]: https://doc.rongcloud.cn/apidoc/imlibcore-android/latest/zh_CN/html/-android--i-m-lib-core--s-d-k/io.rong.imlib.model/-message/index.html