Archiving Channels

Channel members can archive a channel for themselves. This is a per-user setting that does not affect other members.

Archived channels function identically to regular channels via the API, but your UI can display them separately. When a channel is archived, the timestamp is recorded and returned as archived_at in the response.

When querying channels, filter by archived: true to retrieve only archived channels, or archived: false to exclude them.

Archive a Channel

// Controllers

// Archive the channel for the current user.
channelController.archive { error in
    if let error {
        // handle error
    }
}

// Query all the archived channels.
let channelListController = chatClient.channelListController(
    query: ChannelListQuery(
        filter: .and([
            .containMembers(userIds: [currentUserId]),
            .equal(.archived, to: true)
        ])
    )
)
channelListController.synchronize { error in
    if let error {
        // handle error
    } else {
        let archivedChannels = channelListController.channels
    }
}

// Unarchive the channel for the current user.
channelController.unarchive { error in
    if let error {
        // handle error
    }
}

// State layer (async-await)

// Archive the channel for the current user.
try await chat.archive()

// Query all the archived channels.
let channelList = chatClient.makeChannelList(
    with: ChannelListQuery(
        filter: .and([
            .containMembers(userIds: [currentUserId]),
            .equal(.archived, to: true)
        ])
    )
)
try await channelList.get()
let archivedChannels = channelList.state.channels

// Unarchive the channel for the current user.
try await chat.unarchive()

Global Archiving

To archive a channel for all users, use filter_tags to tag the channel as archived. This allows you to query for globally archived channels across your application.

// Archive globally by adding an "archived" tag
try await channel.update(filterTags: ["archived"])

// Query globally archived channels
let channelListController = chatClient.channelListController(
    query: .init(filter: .in(.filterTags, values: ["archived"]))
)
channelListController.synchronize { error in
    if let error {
        // handle error
    }
}