Open chat when joining a channel with guests

(and close it when leaving a channel again)
This commit is contained in:
Conrad Irwin 2024-01-12 15:08:14 -07:00
parent f0d490c671
commit 50f3bbbc8b
4 changed files with 35 additions and 11 deletions

View file

@ -143,17 +143,26 @@ impl ChatPanel {
));
this.subscriptions.push(cx.subscribe(
&ActiveCall::global(cx),
move |this: &mut Self, _, event: &room::Event, cx| match event {
room::Event::RoomJoined { channel_id, role } => {
move |this: &mut Self, call, event: &room::Event, cx| match event {
room::Event::RoomJoined { channel_id } => {
if let Some(channel_id) = channel_id {
this.select_channel(*channel_id, None, cx)
.detach_and_log_err(cx);
if *role == proto::ChannelRole::Guest {
if call
.read(cx)
.room()
.is_some_and(|room| room.read(cx).contains_guests())
{
cx.emit(PanelEvent::Activate)
}
}
}
room::Event::Left { channel_id } => {
if channel_id == &this.channel_id(cx) {
cx.emit(PanelEvent::Close)
}
}
_ => {}
},
));
@ -162,6 +171,12 @@ impl ChatPanel {
})
}
pub fn channel_id(&self, cx: &AppContext) -> Option<u64> {
self.active_chat
.as_ref()
.map(|(chat, _)| chat.read(cx).channel_id)
}
pub fn is_scrolled_to_bottom(&self) -> bool {
self.is_scrolled_to_bottom
}