// Here's a channel with some custom field data that might be useful
val channelClient = client.channel(channelType = "messaging", channelId = "general")
channelClient.create(
memberIds = listOf("thierry", "tomasso"),
extraData = mapOf(
"source" to "user",
"source_detail" to mapOf("user_id" to 123),
"channel_detail" to mapOf(
"topic" to "Plants and Animals",
"rating" to "pg"
)
)
).execute()
// let's change the source of this channel
channelClient.updatePartial(set = mapOf("source" to "system")).execute()
// since it's system generated we no longer need source_detail
channelClient.updatePartial(unset = listOf("source_detail")).execute()
// and finally update one of the nested fields in the channel_detail
channelClient.updatePartial(set = mapOf("channel_detail.topic" to "Nature")).execute()
// and maybe we decide we no longer need a rating
channelClient.updatePartial(unset = listOf("channel_detail.rating")).execute()Updating a Channel
There are two ways to update a channel with the Stream API: partial updates and full updates. A partial update preserves existing custom key–value data, while a full update replaces the entire channel object and removes any fields not included in the request.
Partial Update
A partial update lets you set or unset specific fields without affecting the rest of the channel’s custom data — essentially a patch-style update.
using GetStream;
using GetStream.Models;
var client = new StreamClient("{{ api_key }}", "{{ api_secret }}");
var chat = new ChatClient(client);
// Create a channel with some custom data
var channelResp = await chat.GetOrCreateChannelAsync("messaging", "general",
new ChannelGetOrCreateRequest
{
Data = new ChannelInput
{
CreatedByID = createdByUserId,
Custom = new Dictionary<string, object>
{
["source"] = "user",
["source_detail"] = new Dictionary<string, object> { ["user_id"] = 123 },
["channel_detail"] = new Dictionary<string, object>
{
["topic"] = "Plants and Animals",
["rating"] = "pg"
}
}
}
});
// let's change the source of this channel
await chat.UpdateChannelPartialAsync("messaging", "general",
new UpdateChannelPartialRequest
{
Set = new Dictionary<string, object> { ["source"] = "system" }
});
// since it's system generated we no longer need source_detail
await chat.UpdateChannelPartialAsync("messaging", "general",
new UpdateChannelPartialRequest
{
Unset = new List<string> { "source_detail" }
});
// and finally update one of the nested fields in the channel_detail
await chat.UpdateChannelPartialAsync("messaging", "general",
new UpdateChannelPartialRequest
{
Set = new Dictionary<string, object> { ["channel_detail.topic"] = "Nature" }
});
// and maybe we decide we no longer need a rating
await chat.UpdateChannelPartialAsync("messaging", "general",
new UpdateChannelPartialRequest
{
Unset = new List<string> { "channel_detail.rating" }
});Full Update
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.
var resp = await chat.UpdateChannelAsync("messaging", channelId,
new UpdateChannelRequest
{
Data = new ChannelInputRequest
{
Custom = new Dictionary<string, object>
{
["name"] = "myspecialchannel",
["color"] = "green"
}
}
});Request Params
| Name | Type | Description | Optional |
|---|---|---|---|
| channel data | object | Object 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" | |
| text | object | Message 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.