// Retrieve ChannelClient
val channelClient = client.channel("messaging", "example")
// Archive the channel
channelClient.archive().enqueue { /* ... */ }
// Query for channels that are archived
val query = QueryChannelsRequest(
filter = Filters.eq("archived", true),
offset = 0,
limit = 10,
)
client.queryChannels(query).enqueue { /* ... */ }
// Unarchive the channel
channelClient.unarchive().enqueue { /* ... */ }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
// Get a channel
const channel = client.channel("messaging", "example");
// Archive the channel
await channel.archive();
// Query for channels that are not archived
const resp = await client.queryChannels({ archived: false });
// Unarchive the channel
await channel.unarchive();// Archive the channel
await channel.archive();
// Query for channels that are not archived
final channels = await client.queryChannelsOnline(filter: Filter.equal('archived', false));
// Unarchive the channel
await channel.unarchive();// Get a channel
channel := client.Chat().Channel("messaging", "general")
// Archive the channel for user amy
userID := "amy"
channel.UpdateMemberPartial(ctx, &getstream.UpdateMemberPartialRequest{
UserID: getstream.PtrTo(userID),
Set: map[string]any{"archived": true},
})
// Query for channels that are archived
client.Chat().QueryChannels(ctx, &getstream.QueryChannelsRequest{
UserID: getstream.PtrTo(userID),
FilterConditions: map[string]any{"archived": true},
})
// Unarchive the channel
channel.UpdateMemberPartial(ctx, &getstream.UpdateMemberPartialRequest{
UserID: getstream.PtrTo(userID),
Unset: []string{"archived"},
})use GetStream\ChatClient;
use GetStream\GeneratedModels as Models;
$client = new ChatClient("{{ api_key }}", "{{ api_secret }}");
// Archive the channel for user amy
$userId = "amy";
$client->updateMemberPartial("messaging", "general", $userId, new Models\UpdateMemberPartialRequest(
set: (object)["archived" => true],
));
// Query for channels that are archived
$response = $client->queryChannels(new Models\QueryChannelsRequest(
filterConditions: (object)["archived" => true],
userID: $userId,
));
// Unarchive the channel
$client->updateMemberPartial("messaging", "general", $userId, new Models\UpdateMemberPartialRequest(
set: (object)["archived" => false],
));# Get a channel
channel = client.chat.channel("messaging", "general")
# Archive the channel for user amy
user_id = "amy"
response = channel.update_member_partial(user_id=user_id, set={"archived": True})
# Query for channels that are archived
response = client.chat.query_channels(filter_conditions={"archived": True}, user_id=user_id)
# Unarchive the channel
response = channel.update_member_partial(user_id=user_id, unset=["archived"])require 'getstream_ruby'
Models = GetStream::Generated::Models
# Archive the channel for user amy
user_id = "amy"
response = client.chat.update_member_partial("messaging", "general", Models::UpdateMemberPartialRequest.new(
set: { 'archived' => true }
), user_id)
# Query for channels that are archived
response = client.chat.query_channels(Models::QueryChannelsRequest.new(
filter_conditions: { 'archived' => true },
user_id: user_id
))
# Unarchive the channel
response = client.chat.update_member_partial("messaging", "general", Models::UpdateMemberPartialRequest.new(
unset: ['archived']
), user_id)// Archive the channel for user amy.
chat.updateMemberPartial(channel.getType(), channel.getId(),
UpdateMemberPartialRequest.builder()
.UserID("amy")
.set(Map.of("archived", true))
.build()).execute();
// Query for amy's channels that are archived.
chat.queryChannels(QueryChannelsRequest.builder()
.userID("amy")
.filterConditions(Map.of(
"members", Map.of("$in", List.of("amy")),
"archived", true))
.build()).execute();
// Unarchive
chat.updateMemberPartial(channel.getType(), channel.getId(),
UpdateMemberPartialRequest.builder()
.UserID("amy")
.unset(List.of("archived"))
.build()).execute();// 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()using GetStream;
using GetStream.Models;
var client = new StreamClient("{{ api_key }}", "{{ api_secret }}");
var chat = new ChatClient(client);
var channelId = "channel-id";
var memberId = "user-id";
// Archive the channel for user
// user_id must be passed as a query param
await client.MakeRequestAsync<UpdateMemberPartialRequest, UpdateMemberPartialResponse>(
"PATCH",
"/api/v2/chat/channels/{type}/{id}/member",
new Dictionary<string, string> { ["user_id"] = memberId },
new UpdateMemberPartialRequest
{
Set = new Dictionary<string, object> { ["archived"] = true }
},
new Dictionary<string, string> { ["type"] = "messaging", ["id"] = channelId });
// Unarchive the channel for user
await client.MakeRequestAsync<UpdateMemberPartialRequest, UpdateMemberPartialResponse>(
"PATCH",
"/api/v2/chat/channels/{type}/{id}/member",
new Dictionary<string, string> { ["user_id"] = memberId },
new UpdateMemberPartialRequest
{
Set = new Dictionary<string, object> { ["archived"] = false }
},
new Dictionary<string, string> { ["type"] = "messaging", ["id"] = channelId });Global Archiving
Channels are archived for a specific member. If the channel should instead be archived for all users, this can be stored as custom data in the channel itself. The value cannot collide with existing fields, so use a value such as globally_archived: true.