Manage channel updates

Update channel details and receive events whenever someone updates them.

Requires App Context

To store data about channels, you must enable App Context for your app's keyset in the Admin Portal.

Update channel details

You can edit the metadata of an existing channel with update() and updateChannel().

Both of them give the same output. The only difference is that you call a given method either on the Chat (updateChannel()) or the Channel (update()) object. Depending on the object, these methods take a different set of input parameters - you either have to specify the channel ID you want to update or not because it's already known.

Method signature

These methods take the following parameters:

  • update() (on the Channel object)

    channel.update(
    name: String? = nil,
    custom: [String: JSONCodableScalar]? = nil,
    description: String? = nil,
    status: String? = nil,
    type: ChannelType? = nil
    ) async throws -> ChannelImpl
  • updateChannel() (on the Chat object)

    chat.updateChannel(
    name: String? = nil,
    custom: [String: JSONCodableScalar]? = nil,
    description: String? = nil,
    status: String? = nil,
    type: ChannelType? = nil
    ) async throws -> ChannelImpl

Input

ParameterRequired in update()Required in updateChannel()Description
id
Type: String
Default:
n/a
No
Yes
Unique channel identifier.
name
Type: String
Default:
n/a
No
No
Display name for the channel.
custom
Type: [String: JSONCodableScalar]
Default:
n/a
No
No
JSON providing custom data about the channel. Values must be scalar only; arrays or objects are not supported. App Context filtering language doesn’t support filtering by custom properties.
description
Type: String
Default:
n/a
No
No
Additional details about the channel.
status
Type: String
Default:
n/a
No
No
Tag that categorizes a channel by its state, like archived.
type
Type: ChannelType
Default:
n/a
No
No
Tag that categorizes a channel by its function, like offtopic.
API limits

To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.

Output

ParameterDescription
ChannelImpl
Object containing the updated channel with its metadata.

Basic usage

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Update the description of the support channel.

  • update()
// Assuming you have a reference of type "ChatImpl" named "chat"
Task {
if let channel = try await chat.getChannel(channelId: "support") {
let updatedChannel = try await channel.update(name: "This is the updated description for the support channel")
debugPrint("Updated channel: \(channel)")
} else {
debugPrint("Stopped typing indicator on the 'support' channel")
}
}

Get channel updates

You can receive updates when specific Channel object(s) are edited or removed on other clients using the following methods:

  • streamUpdates() checks updates on a single Channel object and it's tied to an instance of the Channel class.
  • streamUpdatesOn() checks updates on a Channel object list and it's tied to the Channel class.

Both methods return an asynchronous stream which produces a new value whenever someone adds, changes, or removes channel metadata.

Underneath, these methods subscribe the current user to a channel and add an objects event listener to receive all objects events of type channel. These methods also return the unsubscribe function you can invoke to stop receiving objects events and unsubscribe from the channel.

Method signature

These methods take the following parameters:

  • streamUpdates()

    channel.streamUpdates() -> AsyncStream<ChannelImpl?> 
  • streamUpdatesOn() (static)

    ChannelImpl.streamUpdatesOn(
    channels: [ChannelImpl]
    ) -> AsyncStream<[ChannelImpl]>

Input

ParameterRequired in streamUpdates()Required in streamUpdatesOn()Description
channels
Type: [ChannelImpl]
Default:
n/a
No
Yes
A collection of ChannelImpl objects for which you want to get updates.

Output

An asynchronous stream that produces updates when the underlying channel(s) change.

Basic usage

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

  • streamUpdates()

    Get updates on the support channel.

    // Assuming you have a reference of type "ChatImpl" named "chat"
    Task {
    if let channel = try await chat.getChannel(channelId: "support") {
    for await updatedChannel in channel.streamUpdates() {
    debugPrint("Updated channel: \(String(describing: updatedChannel))")
    }
    } else {
    debugPrint("Channel 'support' not found")
    }
    }
  • streamUpdatesOn()

    Get updates on the support and incident-management channels.

    // Assuming you have a reference of type "ChatImpl" named "chat"
    Task {
    if let channel = try await chat.getChannel(channelId: "support") {
    for await updatedChannel in ChannelImpl.streamUpdatesOn(channels: [channel]) {
    debugPrint("Updated channel: \(String(describing: updatedChannel))")
    }
    } else {
    debugPrint("Channel 'support' not found")
    }
    }
Last updated on