Stream Announces $38 Million Series B Funding Learn More →

Deleting & Hiding a Channel

LAST EDIT Mar 04 2021

Deleting a Channel

Copied!

You can delete a Channel using the delete method. This marks the channel as deleted and hides all the content.

1
const destroy = await channel.delete();
1
$channel->delete();
1
await channel.delete();
1
2
3
4
5
6
7
8
9
val channelClient = client.channel("messaging", "general") 
 
channelClient.delete().enqueue { result -> 
    if (result.isSuccess) { 
        val channel = result.data() 
    } else { 
        // Handle result.error() 
    } 
}
1
2
3
4
5
6
7
8
9
10
import Stream Chat 
 
let controller = chatClient.channelController(for: .init(type: .messaging, id: "general")) 
 
controller.deleteChannel { error in 
    if let error = error { 
        // handle error 
        print(error) 
    } 
}
1
2
3
4
5
6
7
8
9
ChannelClient channelClient = client.channel("messaging", "general"); 
 
channelClient.delete().enqueue(result -> { 
    if (result.isSuccess()) { 
        Channel channel = result.data(); 
    } else { 
        // Handle result.error() 
    } 
});
If you recreate this channel, it will show up empty. Recovering old messages is not currently supported via the Stream Chat API.

Hiding a Channel

Copied!

Hiding a channel will remove it from query channel requests for that user until a new message is added. Please keep in mind that hiding a channel is only available to members of that channel.

Optionally you can also clear the entire message history of that channel for the user. This way, when a new message is received, it will be the only one present in the channel.

1
2
3
4
5
6
7
8
// hides the channel until a new message is added there 
await channel.hide(); 
 
// hides the channel until a new message is added there. This also clears the history for the user 
await channel.hide(null, true); 
 
// shows a previously hidden channel 
await channel.show();
1
2
3
4
5
// hides the channel until a new message is added there 
$channel->hide('elon'); 
 
// shows a previously hidden channel 
$channel->show('elon');
1
2
3
4
5
6
7
8
// hides the channel until a new message is added there 
await channel.hide(); 
 
// shows a previously hidden channel 
await channel.show(); 
 
// hide the channel and clear the message history 
await channel.hide(clearHistory: true);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Hides the channel until a new message is added there 
channelClient.hide().enqueue { result -> 
    if (result.isSuccess) { 
        // Channel is hidden 
    } else { 
        // Handle result.error() 
    } 
} 
 
// Shows a previously hidden channel 
channelClient.show().enqueue { result -> 
    if (result.isSuccess) { 
        // Channel is shown 
    } else { 
        // Handle result.error() 
    } 
} 
 
// Hide the channel and clear the message history 
channelClient.hide(clearHistory = true).enqueue { result -> 
    if (result.isSuccess) { 
        // Channel is hidden 
    } else { 
        // Handle result.error() 
    } 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Stream Chat 
 
let controller = chatClient.channelController(for: .init(type: .messaging, id: "general")) 
 
// hide channel 
controller.hideChannel { error in 
    if let error = error { 
        // handle error 
        print(error) 
    } 
} 
 
// show channel 
controller.showChannel { error in 
    if let error = error { 
        // handle error 
        print(error) 
    } 
} 
 
// hide channel and clear message history 
controller.hideChannel(clearHistory: true) { error in 
    if let error = error { 
        // handle error 
        print(error) 
    } 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Hides the channel until a new message is added there 
channelClient.hide(false).enqueue(result -> { 
    if (result.isSuccess()) { 
        // Channel is hidden 
    } else { 
        // Handle result.error() 
    } 
}); 
 
// Shows a previously hidden channel 
channelClient.show().enqueue(result -> { 
    if (result.isSuccess()) { 
        // Channel is shown 
    } else { 
        // Handle result.error() 
    } 
}); 
 
// Hide the channel and clear the message history 
channelClient.hide(true).enqueue(result -> { 
    if (result.isSuccess()) { 
        // Channel is hidden 
    } else { 
        // Handle result.error() 
    } 
});
You can still retrieve the list of hidden channels using the { "hidden" : true } query parameter.

Truncating a Channel

Copied!

Messages from a channel can be truncated. This will remove all of the messages but not affects the channel data or members.

This action can be performed client-side or server-side.

1
const trunc = await conversation.truncate();