logo
On this page

Delete messages


Overview

ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of message management, allowing you to send and receive one-to-one, group, in-room messages, query message history, delete messages, and more. With the message management feature, you can meet different requirements of various scenarios such as social entertainment, online shopping, online education, interactive live streaming, and more.

This document describes how to delete the specified messages in a specified session, or delete all the messages in a specified session.

Implementation process

The ZIM SDK supports deleting specific messages in a conversation or deleting all messages in a conversation. Deleting messages can be divided into "delete local message records" and "delete server message records". Developers can use the ZIMMessageDeleteConfig object to set advanced properties for deleting messages.

Taking the example of client A deleting certain messages or all messages with client B:

Delete the specified messages

The following process shows how Client A deletes the specified messages with Client B:

  1. Client A and Client B log in to the ZIM SDK to send and receive messages to and from each other.
  2. When Client A wants to delete the specified messages with Client B:
    1. Client A logs in to the ZIM SDK first.
    2. Client A calls the deleteMessagesmethod and pass the messageList and config parameters.
    3. Client A receives the results through the callback ZIMMessageDeleteConfig.
SampleCode
// Delete the specified message of the conversation

var deleteMessageList = [];
var conversationID = '';
var conversationType = 0;
var config = { isAlsoDeleteServerMessage: false };

zim.deleteMessages(deleteMessageList, conversationID, conversationType, config)
    .then(function ({ conversationID, conversationType }) {
        // Operation successful.
    })
    .catch(function (err) {
        // Operation failed.
    });
1
Copied!

Delete all messages of the specified session

The following process shows how Client A deletes all messages with Client B:

  1. Client A and Client B log in to the ZIM SDK to send and receive messages to and from each other.
  2. When Client A wants to delete all messages with Client B:
    1. Client A logs in to the ZIM SDK first.
    2. Client A calls the deleteAllMessage method and pass the conversationID, conversationType, and config parameters.
    3. Client A receives the results through the callback ZIMMessageDeletedResult.
SampleCode

// Delete all messages of the specified session.
var conversationID = '';
var conversationType = 0;
var config = { isAlsoDeleteServerMessage: true };

zim.deleteAllMessage(conversationID, conversationType, config)
    .then(function ({ conversationID, conversationType }) {
        // Operation successful.
    })
    .catch(function (err) {
        // Operation failed.
    });
1
Copied!

Delete all messages

After logging into the ZIM SDK, you can call the deleteAllConversationMessages method and pass the ZIMMessageDeleteConfig parameter to configure whether to delete messages stored on the server. This will delete all messages in one-on-one and group conversations.

After clearing all messages in all conversations:

Untitled
// Delete all messages in all conversations

// Set whether to delete messages stored on the server
const config = {
  isAlsoDeleteServerMessage: true
}

zim.deleteAllConversationMessages(config)
.then(function ({ conversationID, conversationType }) {
  // Operation successful.
})
.catch(function (err) {
// Operation failed.
1
Copied!

Previous

Get message history

Next

Insert local messages