/ SDKs / iOS
SDKs
Chat SDKs iOS v4
Chat SDKs iOS
Chat SDKs
iOS
Version 4

Create a message thread

Copy link

When a user replies to a message in a channel, it creates a message thread, which refers to a collection of messages consisting of a parent message and its replies. Message threading lets users ask questions, give feedback, or add context to a specific message without disrupting the flow of conversation. It can have the following elements.

  • A message can have a thread of replies.

  • A message that has a thread of replies is a parent message.

  • A parent message and its threaded replies are collectively called a message thread.

  • Every message within a thread, whether it's parent or reply, is a threaded message.

  • A message that doesn't have any replies is an unthreaded message.

Message threading has the following limitations.

  • Only 1-depth threads are supported, meaning you can only add reply messages to non-reply messages. You can't add a reply to a reply message.
  • Message threading is limited to text and file messages. You can't send admin messages as replies or add replies to admin messages.

You can reply to a message in a channel through the sendUserMessage(params:completionHandler:) or sendFileMessage(params:completionHandler:) method. To do so, you should create a UserMessageCreateParams or a FileMessageCreateParams object and then specify the parentMessageId property of the object. Sending reply messages works the same way as sending regular messages to a channel except that replies have an additional parentMessageId property.


Reply with a text message

Copy link

When replying to a message through the sendUserMessage(params:completionHandler:) method, you should specify and pass a UserMessageCreateParamsobject to the method as a parameter. The UserMessageCreateParams class is derived from the BaseMessageCreateParams class and can access all the methods and properties of BaseMessageCreateParams.

// Create a UserMessageCreateParams object.
let params = UserMessageCreateParams(message: MESSAGE_TEXT)
params.parentMessageId = PARENT_MESSAGE_ID
params.translationTargetLanguages = TARGET_LANGUAGE
params.mentionedMessageTemplate = MESSAGE_TEMPLATE

channel.sendUserMessage(params: params) { message, error in
    guard error == nil else {
        // Handle error.
        return
    }

    // A reply to a specific message is successfully sent as a text message.
}

UserMessageCreateParams

Copy link

To see the comprehensive list of all available methods and properties, see UserMessageCreateParams.

Property nameTypeDescription

parentMessageId

Int64

Specifies the unique ID of a parent message which has a thread of replies. If the message sent through the sendUserMessage(params:completionHandler:) method is a parent message, the value of this property is set to 0. If the message is a reply to a parent message, the value is the message ID of the parent message.

message

String

Specifies the message to send.

translationTargetLanguages

String

Specifies the languages to translate the message into.

mentionedMessageTemplate

String

Specifies the template to use for a message with mentioned users.


Reply with a file message

Copy link

When replying with a file message through the sendFileMessage(params:completionHandler:) method, you should specify and pass a FileMessageCreateParams object to the method as a parameter. The FileMessageCreateParams class is derived from the BaseMessageCreateParams class and can access all the methods and properties of BaseMessageCreateParams.

// Create a FileMessageCreateParams object.
let params = FileMessageCreateParams(file: FILE)
params.parentMessageId = PARENT_MESSAGE_ID // This specifies the unique ID of a parent message which has a thread of replies. If the message sent through the `sendFileMessage(params:completionHandler:)` method is a parent message, the value of this property is 0.
params.fileName = FILE_NAME
params.mimeType = MIME_TYPE
params.fileSize = FILE_SIZE

channel.sendFileMessage(params: params) { message, error in
    guard error == nil else {
        // Handle error.
        return
    }

    // A reply to a specific message is successfully sent as a file message.
}

FileMessageCreateParams

Copy link

To see the comprehensive list of all available methods and properties, see FileMessageCreateParams.

Property nameTypeDescription

parentMessageId

Int64

Specifies the unique ID of a parent message which has a thread of replies. If the message sent through the sendFileMessage(params:completionHandler:) method is a parent message, the value of this property is set to 0. If the message is a reply to a parent message, the value is the message ID of the parent message.

file

Data

Specifies the binary file data. When the value of file is specified, the value of fileURL can't be specified.

fileName

String

Specifies the file name.

mimeType

String

Specifies the file MIME type.

fileSize

UInt

Specifies the file size.

When replying with more than two images or videos through the sendMultipleFilesMessage() method, you should specify and pass a MultipleFilesMessageCreateParams object to the method as a parameter. Just like FileMessageCreateParams, the MultipleFilesMessageCreateParams class is derived from the BaseMessageCreateParams class and can access all the methods and properties of BaseMessageCreateParams. To learn more about how to send a multiple file message, see the Send a message page.

FILEINFO_1.fileName = FILE_NAME_1
FILEINFO_1.mimeType = MIME_TYPE_1
FILEINFO_1.fileSize = FILE_SIZE_1

// Create a MultipleFilesMessageCreateParams object.
let params = MultipleFilesMessageCreateParams(uploadableFileInfoList: [FILEINFO_1, FILEINFO_2])
params.parentMessageId = PARENT_MESSAGE_ID // This specifies the unique ID of a parent message which has a thread of replies. If the message sent through the `sendMultipleFilesMessage(params:fileUploadHandler:completionHandler:)` method is a parent message, the value of this property is 0.  
channel.sendMultipleFilesMessage(params: params) { message, error in
    guard error == nil else {
        // Handle error.
        return
    }
    // A reply to a specific message is successfully sent as a multiple files message.
}

Event delegate for message threading

Copy link

When a reply is created in a channel, the channel(_:didReceive:) and channel(_:didUpdateThreadInfo:) methods of the channel event delegate in client apps are called. When a reply is deleted from a thread, the channel(_:didUpdateThreadInfo:) event delegate method is invoked. In both cases, channel(_:didUpdateThreadInfo:) takes a ThreadInfoUpdateEvent object as an argument that has the latest information about the thread. Apply the object to the parent message object through the message.apply() method.

func channel(_ channel: BaseChannel, didUpdateThreadInfo threadInfoUpdateEvent: ThreadInfoUpdateEvent) {
    // Look for a message that has threadInfoUpdateEvent.targetMessageId.
    // Apply the event to the message.
    message.apply(threadInfoUpdateEvent)
}

List of parameters

Copy link
Parameter nameTypeDescription

channel

BaseChannel

Specifies the channel that has the message thread.

threadInfoUpdateEvent

ThreadInfoUpdateEvent

Specifies a ThreadInfoUpdateEvent object that has the latest information about the thread.