Delete channels

Chat SDK lets you remove an existing channel (with or without deleting its historical data from the App Context storage) using one of these methods: delete() and deleteChannel().

Both of these methods give the same output. The only difference is that you call a given method either on the Chat (deleteChannel()) or the Channel (delete()) 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 delete or not because it's already known.

Requires App Context

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

Method signature

These methods take the following parameters:

  • delete()

    channel.delete(
    soft: Bool = false,
    completion: ((Swift.Result<ChannelImpl, Error>) -> Void)? = nil
    )
  • deleteChannel()

    chat.deleteChannel(
    id: String,
    soft: Bool = false,
    completion: ((Swift.Result<ChannelImpl, Error>) -> Void)? = nil
    )

Input

ParameterTypeRequired in delete()Required in deleteChannel()DefaultDescription
idStringNoYesfalseUnique channel identifier.
softBoolNoNofalseDefine if you want to permanently remove channel metadata. The channel metadata gets permanently deleted from the App Context storage by default. If you set this parameter to true, the Channel object gets the deleted status, and you can still restore/get its data.

Output

TypeDescription
ChannelImplFor hard delete, the method returns the last version of the ChannelImpl object before it was permanently deleted. For soft delete, it returns an updated channel instance with the status field set to deleted.

Basic usage

Permanently delete the support channel metadata.

  • delete()

    /// Reference the previously created "Channel" object
    ///
    /// ```
    /// chat.getChannel(channelId: "support") {
    /// switch $0 { [weak self] in
    /// case let .success(channel):
    /// self?.channel = channel
    /// case let .failure(error):
    /// debugPrint("Error while creating a channel: \(error)")
    /// }
    /// }
    /// ```

    var channel: ChannelImpl?

    show all 25 lines
  • deleteChannel()

    /// Ensure you have the `chat` object available
    /// By default, the "soft" parameter is set to "false" and can be skipped

    chat?.deleteChannel(id: "support") { result in
    switch result {
    case let .success(channel):
    debugPrint("Channel was deleted: \(channel.id)")
    case let .failure(error):
    debugPrint("Error while deleting a channel: \(error)")
    }
    }

Other examples

Archive (soft delete) the channel with the ID of support, keeping its data in the App Context storage.

  • delete()

    /// Reference the previously created "Channel" object
    ///
    /// ```
    /// chat.getChannel(channelId: "support") {
    /// switch $0 { [weak self] in
    /// case let .success(channel):
    /// self?.channel = channel
    /// case let .failure(error):
    /// debugPrint("Error while creating a channel: \(error)")
    /// }
    /// }
    /// ```

    var channel: ChannelImpl?

    show all 24 lines
  • deleteChannel()

    /// Ensure you have the `chat` object available
    /// By default, the "soft" parameter is set to "false" and can be skipped

    chat?.deleteChannel(id: "support", soft: false) { result in
    switch result {
    case let .success(channel):
    debugPrint("Channel was deleted: \(channel.id)")
    case let .failure(error):
    debugPrint("Error while deleting a channel: \(error)")
    }
    }
Last updated on