Skip to main content

Delete messages

The Chat UI channel screen implements long-press delete by default. If you need to delete messages from a custom screen, use the public APIs described below.

API overview

  • NCChatUI.deleteMessages(ChannelIdentifier, List<Message>, ErrorHandler)
    • Deletes messages for the current user (local and remote records) and triggers Chat UI refresh events.
  • NCChatUI.deleteLocalMessages(ChannelIdentifier, List<Message>, ErrorHandler)
    • Deletes local messages only and triggers Chat UI refresh events.
  • NCChatUI.deleteMessageForAll(ChannelIdentifier, Message, OperationHandler<Message>)
    • Deletes a message for everyone.

Delete messages (local and remote)

Interface

kotlin
NCChatUI.deleteMessages(identifier, messages, handler)

Example

kotlin
val identifier = ChannelIdentifier(ChannelType.DIRECT, "Channel ID")
val messages = listOf(message1, message2)

NCChatUI.deleteMessages(identifier, messages) { error ->
if (error == null) {
// Deletion successful
} else {
// Deletion failed
}
}

Delete local messages only

Interface

kotlin
NCChatUI.deleteLocalMessages(identifier, messages, handler)

Example

kotlin
val identifier = ChannelIdentifier(ChannelType.GROUP, "Group ID")
val messages = listOf(message1, message2)

NCChatUI.deleteLocalMessages(identifier, messages) { error ->
if (error == null) {
// Local deletion successful
}
}

Delete a message for everyone

Interface

kotlin
NCChatUI.deleteMessageForAll(identifier, message, handler)

Example

kotlin
val identifier = ChannelIdentifier(ChannelType.GROUP, "Group ID")

NCChatUI.deleteMessageForAll(identifier, message) { deletedMessage, error ->
if (error == null) {
// Delete for everyone successful
} else {
// Delete for everyone failed
}
}

Delete by timestamp (using BaseChannel)

NCChatUI does not provide a static wrapper for deleting messages by timestamp. To use this capability, obtain a channel object:

kotlin
val identifier = ChannelIdentifier(ChannelType.DIRECT, "Channel ID")
val channel = NCChatUI.createChannel(identifier)

val params = DeleteMessagesForMeByTimestampParams(
System.currentTimeMillis(),
MessageOperationPolicy.LOCAL_REMOTE // LOCAL for local only, LOCAL_REMOTE for local and remote
)

channel.deleteMessagesForMeByTimestamp(params) { error ->
if (error == null) {
// Deletion successful
}
}

Notes

  • The standalone remote deletion API mentioned in older documentation is no longer part of the public API.
  • Deletion methods trigger internal Chat UI events. Open channel screens refresh automatically.