Open chat when joining a channel with guests
(and close it when leaving a channel again)
This commit is contained in:
parent
f0d490c671
commit
50f3bbbc8b
4 changed files with 35 additions and 11 deletions
|
@ -442,10 +442,8 @@ impl ActiveCall {
|
||||||
.location
|
.location
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|location| location.upgrade());
|
.and_then(|location| location.upgrade());
|
||||||
let (channel_id, role) = room.update(cx, |room, _| {
|
let channel_id = room.read(cx).channel_id();
|
||||||
(room.channel_id(), room.local_participant().role)
|
cx.emit(Event::RoomJoined { channel_id });
|
||||||
});
|
|
||||||
cx.emit(Event::RoomJoined { channel_id, role });
|
|
||||||
room.update(cx, |room, cx| room.set_location(location.as_ref(), cx))
|
room.update(cx, |room, cx| room.set_location(location.as_ref(), cx))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -28,7 +28,6 @@ pub const RECONNECT_TIMEOUT: Duration = Duration::from_secs(30);
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
RoomJoined {
|
RoomJoined {
|
||||||
channel_id: Option<u64>,
|
channel_id: Option<u64>,
|
||||||
role: proto::ChannelRole,
|
|
||||||
},
|
},
|
||||||
ParticipantLocationChanged {
|
ParticipantLocationChanged {
|
||||||
participant_id: proto::PeerId,
|
participant_id: proto::PeerId,
|
||||||
|
@ -53,7 +52,9 @@ pub enum Event {
|
||||||
RemoteProjectInvitationDiscarded {
|
RemoteProjectInvitationDiscarded {
|
||||||
project_id: u64,
|
project_id: u64,
|
||||||
},
|
},
|
||||||
Left,
|
Left {
|
||||||
|
channel_id: Option<u64>,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Room {
|
pub struct Room {
|
||||||
|
@ -361,7 +362,9 @@ impl Room {
|
||||||
|
|
||||||
pub(crate) fn leave(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
pub(crate) fn leave(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
cx.emit(Event::Left);
|
cx.emit(Event::Left {
|
||||||
|
channel_id: self.channel_id(),
|
||||||
|
});
|
||||||
self.leave_internal(cx)
|
self.leave_internal(cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,6 +605,14 @@ impl Room {
|
||||||
.map(|participant| participant.role)
|
.map(|participant| participant.role)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn contains_guests(&self) -> bool {
|
||||||
|
self.local_participant.role == proto::ChannelRole::Guest
|
||||||
|
|| self
|
||||||
|
.remote_participants
|
||||||
|
.values()
|
||||||
|
.any(|p| p.role == proto::ChannelRole::Guest)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn local_participant_is_admin(&self) -> bool {
|
pub fn local_participant_is_admin(&self) -> bool {
|
||||||
self.local_participant.role == proto::ChannelRole::Admin
|
self.local_participant.role == proto::ChannelRole::Admin
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,17 +143,26 @@ impl ChatPanel {
|
||||||
));
|
));
|
||||||
this.subscriptions.push(cx.subscribe(
|
this.subscriptions.push(cx.subscribe(
|
||||||
&ActiveCall::global(cx),
|
&ActiveCall::global(cx),
|
||||||
move |this: &mut Self, _, event: &room::Event, cx| match event {
|
move |this: &mut Self, call, event: &room::Event, cx| match event {
|
||||||
room::Event::RoomJoined { channel_id, role } => {
|
room::Event::RoomJoined { channel_id } => {
|
||||||
if let Some(channel_id) = channel_id {
|
if let Some(channel_id) = channel_id {
|
||||||
this.select_channel(*channel_id, None, cx)
|
this.select_channel(*channel_id, None, cx)
|
||||||
.detach_and_log_err(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)
|
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 {
|
pub fn is_scrolled_to_bottom(&self) -> bool {
|
||||||
self.is_scrolled_to_bottom
|
self.is_scrolled_to_bottom
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
room::Event::Left => {
|
room::Event::Left { .. } => {
|
||||||
for (_, windows) in notification_windows.drain() {
|
for (_, windows) in notification_windows.drain() {
|
||||||
for window in windows {
|
for window in windows {
|
||||||
window
|
window
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue