Delete messages
Delete messages from your own view in a community subchannel.
Delete messages (for yourself only)
Remove messages from your own view only. Other participants still see the messages:
TypeScript
import { CommunitySubChannel, BaseChannel, Message } from '@nexconn/chat';
const channel = new CommunitySubChannel('<communityId>', '<subChannelId>');
// First retrieve the message objects you want to delete
const query = BaseChannel.createMessagesQuery({
channelIdentifier: channel.identifier,
startTime: Date.now(),
pageSize: 20,
isAscending: false,
});
const { code, data: page } = await query.loadNextPage();
if (code === 0 && page.data.length > 0) {
const { code: deleteCode } = await channel.deleteMessagesForMe([page.data[0]]);
if (deleteCode === 0) {
console.log('Message deleted for self');
}
}
Delete messages by timestamp
Delete all messages before a given timestamp from your own view only:
TypeScript
import { CommunitySubChannel } from '@nexconn/chat';
const channel = new CommunitySubChannel('<communityId>', '<subChannelId>');
const { code } = await channel.deleteMessagesForMeByTimestamp({ timestamp: Date.now() });
if (code === 0) {
console.log('Messages cleared');
}
warning
deleteMessagesForMeonly removes the message from the current user's view.deleteMessagesForMeByTimestampclears messages before the specified timestamp only for the current user.- To remove a specific message for all participants, use Delete a message (recall) instead.