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,
completion: ((Swift.Result<MessageImpl?, Error>) -> Void)? = nil
)
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
timetoken | Timetoken | Yes | n/a | Timetoken of the message you want to retrieve from Message Persistence. |
Output
Type | Description |
---|---|
MessageImpl | Returned Message object. |
Basic usage
Get the message with the 16200000000000001
timetoken.
/// Assuming you have a "chat" instance available
chat?.getChannel(
channelId: "support"
) {
switch $0 {
case let .success(channel):
if let channel = channel {
debugPrint("Fetched channel metadata with ID: \(channel.id)")
/// Timetoken for the message you're trying to get
let timetoken: Timetoken = 16200000000000001
/// Get the message with the specified timetoken
channel.getMessage(timetoken: timetoken) {
switch $0 {
case let .success(message):
if let message = message {
show all 30 linesGet 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
Get the content of the message with the 16200000000000000
timetoken.
/// Assuming you have a "chat" instance available
chat?.getChannel(
channelId: "support"
) {
switch $0 {
case let .success(channel):
if let channel = channel {
debugPrint("Fetched channel metadata with ID: \(channel.id)")
/// Timetoken for the message you're trying to get
let timetoken: Timetoken = 16200000000000000
/// Get the message with the specified timetoken
channel.getMessage(timetoken: timetoken) {
switch $0 {
case let .success(message):
if let message = message {
show all 31 linesCheck deletion status
You can access the deleted
property of the Message
object to check if it was deleted.
Basic usage
Get the status of the message with the 16200000000000000
timetoken.
/// Assuming you have a "chat" instance available
chat?.getChannel(
channelId: "support"
) {
switch $0 {
case let .success(channel):
if let channel = channel {
debugPrint("Fetched channel metadata with ID: \(channel.id)")
/// Timetoken for the message you're trying to get
let timetoken: Timetoken = 16200000000000000
/// Get the status of the message with the specified timetoken
channel.getMessage(timetoken: timetoken) {
switch $0 {
case let .success(message):
if let message = message {
show all 34 lines