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

Hide or archive a group channel

Copy link

You can hide or archive a specific group channel from the channel list UI by following the code below.

// Hide or archive a group channel.
channel.hide(hidePreviousMessages:IS_HIDE_PREVIOUS_MESSAGES, allowAutoUnhide:IS_ALLOW_AUTO_UNHIDE) { error in
    guard error == nil else {
        // Handle error.
        return
    }

    // The channel is successfully hidden from the list.
    // The current user's channel view should be refreshed to reflect the change.
}

// Unhide a group channel.
channel.unhide { error in
    guard error == nil else {
        // Handle error.
        return
    }

    // The channel is successfully unhidden from the list.
    // The current user's channel view should be refreshed to reflect the change.
}

List of parameters

Copy link
Parameter nameTypeDescription

hidePreviousMessages

Bool

Determines whether to show the messages sent and received before hiding or archiving the channel on the channel list. If set to true, previous messages aren't displayed in the channel. (Default: false)

allowAutoUnhide

Bool

Determines the state and operating behavior of a channel. If set to true, the channel is hidden from the channel list, but when a new message arrives, the hidden channel will show up again on the channel list. If set to false, the channel is archived and stays hidden from the channel list unless the .unhide method is called.

You can check the channel state on the channel list by using the hiddenState property of a GroupChannel object.

if channel.hiddenState == .unhidden {
    // Show the channel in the list.
} else if channel.hiddenState == .hiddenAllowAutoUnhide {
    // Hide the channel from the list, and get it appeared back on condition.
} else if channel.hiddenState == .hiddenPreventAutoUnhide {
    // Archive the channel, and get it appeared back in the list only when the unhideChannel() is called.
}

You can also filter channels by their state by following the code below.

class CustomViewController: ViewController {
    var query: GroupChannelListQuery?

    func createQuery() {
        self.query = GroupChannel.createMyGroupChannelListQuery { params in
            // The filter options are .unhiddenOnly, .hiddenOnly, .hiddenAllowAutoUnhide, or .hiddenPreventAutoUnhide.
            // If set to .hiddenOnly, hidden and archived channels are returned.
            // The `params` object is the `GroupChannelListQueryParams` class.
            params.channelHiddenStateFilter = .hiddenPreventAutoUnhide
        }
    }

    func loadNextPage() {
        self.query?.loadNextPage { channels, error in
            guard error == nil else {
                // Handle error.
                return
            }

            // Only archived channels are returned in the result list
            // through the channels parameter of the callback method.
        }
    }
}