Get message details
Get message details, retrieve content, and check if the message was deleted.
Get message details
getMessage()
fetches the Message
object from Message Persistence based on the message timetoken.
Method signature
This method takes the following parameters:
channel.getMessage(
timetoken: Timetoken
) async throws -> MessageImpl?
Input
Parameter | Description |
---|---|
timetoken *Type: Timetoken Default: n/a | Timetoken of the message you want to retrieve from Message Persistence. |
Output
Parameter | Description |
---|---|
MessageImpl | Returned Message 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.
Get the 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") {
// Timetoken for the message you're trying to get
let timetoken: Timetoken = 16200000000000001
// Get the message with the specified timetoken
if let message = try await channel.getMessage(timetoken: timetoken) {
debugPrint("Message fetched successfully: \(message.text)")
} else {
debugPrint("No message found with this timetoken.")
}
} else {
debugPrint("Channel not found")
}
}
Get historical details
If you have Message Persistence enabled on your keyset, PubNub stores all historical info about messages, their metadata, and reactions.
If you want to fetch historical details of a given message, use the getHistory()
method. By default, when you fetch historical messages, PubNub returns all message reactions and metadata attached to the retrieved messages.
Get message content
You can access the text
property of the Message
object to receive its text content.
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.
Get the content of the message with the 16200000000000000
timetoken.
// Assuming you have a reference of type "ChatImpl" named "chat"
Task {
if let channel = try await chat.getChannel(channelId: "support") {
// Timetoken for the message you're trying to get
let timetoken: Timetoken = 16200000000000000
// Get the message with the specified timetoken
if let message = try await channel.getMessage(timetoken: timetoken) {
// Accessing the 'text' property of the message
debugPrint("Message fetched successfully: \(message.text)")
} else {
debugPrint("No message found with this timetoken.")
}
} else {
debugPrint("Channel not found")
}
show all 16 linesCheck deletion status
You can access the deleted
property of the Message
object to check if it was deleted.
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.
Get the status of the message with the 16200000000000000
timetoken.
// Assuming you have a reference of type "ChatImpl" named "chat"
Task {
if let channel = try await chat.getChannel(channelId: "support") {
// Timetoken for the message you're trying to get
let timetoken: Timetoken = 16200000000000000
// Get the message with the specified timetoken
if let message = try await channel.getMessage(timetoken: timetoken) {
if message.deleted {
debugPrint("The message was deleted.")
} else {
debugPrint("Message fetched successfully: \(message.text)")
}
} else {
debugPrint("No message found with this timetoken.")
}
show all 19 lines