Thread

The ChatThreadVC is very similar with the ChatChannelVC, the difference is that instead of displaying messages, it displays the replies of a message thread. Just like the ChatChannelVC it also contains the ComposerVC component to create new replies.

The following diagram shows the components hierarchy of ChatThreadVC:

Digraph

Overview

  • ChatThreadHeaderView is responsible to display the thread information in the navigationItem.titleView.
  • ChatMessageListVC is the component that handles the rendering of the replies.
  • ComposerVC is the component that handles the creation of new replies.

Usage

By default, the ChatThreadVC is created when you click to see the replies of a message in the ChatMessageListVC component. But in case you want to create it programmatically, you can use the following code:

let cid = "channel-id"
let messageId = "message-id"
let threadVC = ChatThreadVC()
threadVC.channelController = ChatClient.shared.channelController(for: cid)
threadVC.messageController = ChatClient.shared.messageController(
    cid: cid,
    messageId: messageId
)

navigationController?.show(threadVC, sender: self)

In this section we are going to use ChatClient as a singleton, you can find more information about that here

UI Customization

You can customize how the ChatThreadVC looks by subclassing it and swap the component in Components configuration:

Components.default.threadVC = CustomChatThreadVC.self

You can find more information on how the components configuration works here.

Just like the ChatChannelVC, the ChatThreadVC is only responsible for composing the ChatThreadHeaderView, ChatMessageListVC and ChatMessageComposerVC components together. In case you want to customize the rendering of the replies, you should read the Message documentation.

Properties

content

public var content: (
        channelController: ChatChannelController,
        messageController: ChatMessageController
    ) 

channelController

Controller for observing data changes within the channel

open var channelController: ChatChannelController!

messageController

Controller for observing data changes within the parent thread message.

open var messageController: ChatMessageController!

client

public var client: ChatClient 

keyboardHandler

Component responsible for setting the correct offset when keyboard frame is changed

open lazy var keyboardHandler: KeyboardHandler 

userSuggestionSearchController

User search controller passed directly to the composer

open lazy var userSuggestionSearchController: ChatUserSearchController 

messageListVC

The message list component responsible to render the messages.

open lazy var messageListVC: ChatMessageListVC 

messageComposerVC

Controller that handles the composer view

open private(set) lazy var messageComposerVC 

headerView

The header view of the thread that by default is the titleView of the navigation bar.

open lazy var headerView: ChatThreadHeaderView = components
        .threadHeaderView.init()
        .withoutAutoresizingMaskConstraints

replies

open var replies: [ChatMessage] 

Methods

setUp()

override open func setUp() 

setUpLayout()

override open func setUpLayout() 

viewDidAppear(_:)

override open func viewDidAppear(_ animated: Bool) 

viewDidDisappear(_:)

override open func viewDidDisappear(_ animated: Bool) 

channel(for:)

open func channel(for vc: ChatMessageListVC) -> ChatChannel? 

numberOfMessages(in:)

open func numberOfMessages(in vc: ChatMessageListVC) -> Int 

chatMessageListVC(_:messageAt:)

open func chatMessageListVC(_ vc: ChatMessageListVC, messageAt indexPath: IndexPath) -> ChatMessage? 

chatMessageListVC(_:messageLayoutOptionsAt:)

open func chatMessageListVC(
        _ vc: ChatMessageListVC,
        messageLayoutOptionsAt indexPath: IndexPath
    ) -> ChatMessageLayoutOptions 

chatMessageListVC(_:willDisplayMessageAt:)

open func chatMessageListVC(
        _ vc: ChatMessageListVC,
        willDisplayMessageAt indexPath: IndexPath
    ) 

chatMessageListVC(_:didTapOnAction:for:)

open func chatMessageListVC(
        _ vc: ChatMessageListVC,
        didTapOnAction actionItem: ChatMessageActionItem,
        for message: ChatMessage
    ) 

chatMessageListVC(_:scrollViewDidScroll:)

open func chatMessageListVC(
        _ vc: ChatMessageListVC,
        scrollViewDidScroll scrollView: UIScrollView
    ) 

messageController(_:didChangeMessage:)

open func messageController(
        _ controller: ChatMessageController,
        didChangeMessage change: EntityChange<ChatMessage>
    ) 

messageController(_:didChangeReplies:)

open func messageController(
        _ controller: ChatMessageController,
        didChangeReplies changes: [ListChange<ChatMessage>]
    )

© Getstream.io, Inc. All Rights Reserved.