Updating a Channel

There are two ways to update a channel using the Stream API - a partial or full update. A partial update will retain any custom key-value data, whereas a complete update is going to remove any that are unspecified in the API request.

Partial Update

A partial update can be used to set and unset specific fields when it is necessary to retain additional custom data fields on the object. AKA a patch style update.

channelController.partialChannelUpdate(extraData: [pinnedKey: true]) { error in
  if let error = error {
   self.rootViewController.presentAlert(title: "Couldn't pin channel \(cid)", message: "\(error)")
  }
}

// let's change the source of this channel
channelController.partialChannelUpdate(unsetProperties: ["source_detail"])
        
// let's change the source of this channel
channelController.partialChannelUpdate(extraData:["source": "system"])

// since it's system generated we no longer need source_detail
channelController.partialChannelUpdate(unsetProperties: ["source_detail"])

// and finally update one of the nested fields in the channel_detail
channelController.partialChannelUpdate(extraData:["channel_detail.topic": "Nature"])

Full Update (overwrite)

The update function updates all of the channel data. Any data that is present on the channel and not included in a full update will be deleted.

import Stream Chat

let controller = chatClient.channelController(for: .init(type: .messaging, id: "general"))

controller.updateChannel(name: "My special channel", imageURL: nil, team: nil, extraData: .defaultValue) { error in
  if let error = error {
    // handle errors
    print(error)
  }
}

Request Params

NameTypeDescriptionOptional
channel dataobjectObject with the new channel information. One special field is “frozen”. Setting this field to true will freeze the channel. Read more about freezing channels in “Freezing Channels”
textobjectMessage object allowing you to show a system message in the Channel that something changed.Yes

Updating a channel using these methods cannot be used to add or remove members. For this, you must use specific methods for adding/removing members, more information can be found here.

© Getstream.io, Inc. All Rights Reserved.