Restore messages
If you delete a message, you can restore its content together with the attached files using the restore()
method.
This is possible, however, only if the message you want to restore was soft deleted (the soft
parameter was set to true when deleting it). Hard deleted messages cannot be restored as their data is no longer available in Message Persistence.
Requires Message Persistence configuration
To manage messages, you must enable Message Persistence for your app's keyset in the Admin Portal and mark the Enable Delete-From-History option.
Method signature
This method has the following signature:
message.restore() async throws -> MessageImpl
Input
This method doesn't take any parameters.
Output
Parameter | Description |
---|---|
MessageImpl | Object returning the restored MessageImpl object. |
Basic usage
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Restore a previously soft deleted message with the 16200000000000001
timetoken.
// Assuming you have a reference of type "ChatImpl" named "chat"
Task {
if let channel = try await chat.getChannel(channelId: "support") {
if let message = try await channel.getMessage(timetoken: timetoken) {
let updatedMessage = try await message.restore()
debugPrint("Updated message: \(updatedMessage)")
} else {
debugPrint("Message not found")
}
} else {
debugPrint("Channel not found")
}
}