Skip to content
Open
13 changes: 7 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use std::collections::HashMap;
use makepad_widgets::{makepad_micro_serde::*, *};
use matrix_sdk::ruma::{OwnedRoomId, RoomId};
use matrix_sdk::{RoomDisplayName, ruma::{OwnedRoomId, RoomId}};
use crate::{
avatar_cache::clear_avatar_cache, home::{
main_desktop_ui::MainDesktopUiAction, new_message_context_menu::NewMessageContextMenuWidgetRefExt, room_screen::{clear_timeline_states, MessageAction}, rooms_list::{clear_all_invited_rooms, enqueue_rooms_list_update, RoomsListAction, RoomsListRef, RoomsListUpdate}
Expand All @@ -20,6 +20,7 @@ use crate::{
}, sliding_sync::current_user_id, utils::{
room_name_or_id,
OwnedRoomIdRon,
RoomName,
}, verification::VerificationAction, verification_modal::{
VerificationModalAction,
VerificationModalWidgetRefExt,
Expand Down Expand Up @@ -579,7 +580,7 @@ impl App {
// Select and scroll to the destination room in the rooms list.
let new_selected_room = SelectedRoom::JoinedRoom {
room_id: destination_room.room_id.clone().into(),
room_name: destination_room.room_name.clone(),
room_name: destination_room.room_name.clone().into(),
};
enqueue_rooms_list_update(RoomsListUpdate::ScrollToRoom(destination_room.room_id.clone()));
cx.widget_action(
Expand Down Expand Up @@ -627,11 +628,11 @@ pub struct SavedDockState {
pub enum SelectedRoom {
JoinedRoom {
room_id: OwnedRoomIdRon,
room_name: Option<String>,
room_name: RoomName,
},
InvitedRoom {
room_id: OwnedRoomIdRon,
room_name: Option<String>,
room_name: RoomName,
},
}

Expand All @@ -643,7 +644,7 @@ impl SelectedRoom {
}
}

pub fn room_name(&self) -> Option<&String> {
pub fn room_name(&self) -> &RoomDisplayName {
match self {
SelectedRoom::JoinedRoom { room_name, .. } => room_name.as_ref(),
SelectedRoom::InvitedRoom { room_name, .. } => room_name.as_ref(),
Expand All @@ -659,7 +660,7 @@ impl SelectedRoom {
pub fn upgrade_invite_to_joined(&mut self, room_id: &RoomId) -> bool {
match self {
SelectedRoom::InvitedRoom { room_id: id, room_name } if id.0 == room_id => {
let name = room_name.take();
let name = room_name.clone();
*self = SelectedRoom::JoinedRoom {
room_id: id.clone(),
room_name: name,
Expand Down
37 changes: 23 additions & 14 deletions src/home/invite_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use std::ops::Deref;
use makepad_widgets::*;
use matrix_sdk::ruma::OwnedRoomId;
use matrix_sdk::{RoomDisplayName, ruma::OwnedRoomId};

use crate::{app::AppStateAction, home::rooms_list::RoomsListRef, join_leave_room_modal::{JoinLeaveModalKind, JoinLeaveRoomModalAction}, room::{BasicRoomDetails, FetchedRoomAvatar}, shared::{avatar::AvatarWidgetRefExt, popup_list::{enqueue_popup_notification, PopupItem, PopupKind}, restore_status_view::RestoreStatusViewWidgetExt}, sliding_sync::{submit_async_request, MatrixRequest}, utils::{self, room_name_or_id}};
use crate::{app::AppStateAction, home::rooms_list::RoomsListRef, join_leave_room_modal::{JoinLeaveModalKind, JoinLeaveRoomModalAction}, room::{BasicRoomDetails, FetchedRoomAvatar}, shared::{avatar::AvatarWidgetRefExt, popup_list::{enqueue_popup_notification, PopupItem, PopupKind}, restore_status_view::RestoreStatusViewWidgetExt}, sliding_sync::{submit_async_request, MatrixRequest}, utils::{self, room_name_or_id, RoomName}};

use super::rooms_list::{InviteState, InviterInfo};

Expand Down Expand Up @@ -268,7 +268,7 @@ pub struct InviteScreen {
/// The ID of the room that has been invited.
/// This is used to wait for RoomsPanel
#[rust] room_id: Option<OwnedRoomId>,
#[rust] room_name: String,
#[rust(RoomDisplayName::Empty)] room_name: RoomDisplayName,
#[rust] is_loaded: bool,
#[rust] all_rooms_loaded: bool,
}
Expand Down Expand Up @@ -351,7 +351,8 @@ impl Widget for InviteScreen {
Some(JoinRoomResultAction::Failed { room_id, error }) if room_id == &info.room_id => {
self.invite_state = InviteState::WaitingOnUserInput;
if !self.has_shown_confirmation {
let msg = utils::stringify_join_leave_error(error, info.room_name.as_deref(), true, true);
let room_label = room_name_or_id(&info.room_name, &info.room_id);
let msg = utils::stringify_join_leave_error(error, Some(&room_label), true, true);
enqueue_popup_notification(PopupItem { message: msg, kind: PopupKind::Error, auto_dismissal_duration: None });
}
continue;
Expand Down Expand Up @@ -397,7 +398,8 @@ impl Widget for InviteScreen {
fn draw_walk(&mut self, cx: &mut Cx2d, scope: &mut Scope, walk: Walk) -> DrawStep {
if !self.is_loaded {
let mut restore_status_view = self.view.restore_status_view(ids!(restore_status_view));
restore_status_view.set_content(cx, self.all_rooms_loaded, &self.room_name);
let room_id = self.room_id.as_ref().map(|id| id.as_ref());
restore_status_view.set_content(cx, self.all_rooms_loaded, self.room_name.clone().into(), room_id);
return restore_status_view.draw(cx, scope);
}
let Some(info) = self.info.as_ref() else {
Expand Down Expand Up @@ -467,10 +469,8 @@ impl Widget for InviteScreen {
);
}
}
room_view.label(ids!(room_name)).set_text(
cx,
info.room_name.as_deref().unwrap_or_else(|| info.room_id.as_str()),
);
let invite_room_label = room_name_or_id(&info.room_name, &info.room_id);
room_view.label(ids!(room_name)).set_text(cx, &invite_room_label);

// Third, set the buttons' text based on the invite state.
let cancel_button = self.view.button(ids!(cancel_button));
Expand Down Expand Up @@ -516,10 +516,9 @@ impl Widget for InviteScreen {

impl InviteScreen {
/// Sets the ID of the invited room that will be displayed by this screen.
pub fn set_displayed_invite<S: Into<Option<String>>>(&mut self, cx: &mut Cx, room_id: OwnedRoomId, room_name: S) {
pub fn set_displayed_invite(&mut self, cx: &mut Cx, room_id: OwnedRoomId, room_name: RoomDisplayName) {
self.room_id = Some(room_id.clone());
self.room_name = room_name_or_id(room_name.into(), &room_id);

self.room_name = room_name;
if let Some(invite) = super::rooms_list::get_invited_rooms(cx)
.borrow()
.get(&room_id)
Expand All @@ -538,13 +537,23 @@ impl InviteScreen {
self.all_rooms_loaded = true;
self.redraw(cx);
}
self.view.restore_status_view(ids!(restore_status_view)).set_visible(cx, !self.is_loaded);
self.view
.restore_status_view(ids!(restore_status_view))
.set_content(
cx,
self.all_rooms_loaded,
RoomName::from(self.room_name.clone()),
Some(room_id.as_ref()),
);
self.view
.restore_status_view(ids!(restore_status_view))
.set_visible(cx, !self.is_loaded);
}
}

impl InviteScreenRef {
/// See [`InviteScreen::set_displayed_invite()`].
pub fn set_displayed_invite<S: Into<Option<String>>>(&self, cx: &mut Cx, room_id: OwnedRoomId, room_name: S) {
pub fn set_displayed_invite(&self, cx: &mut Cx, room_id: OwnedRoomId, room_name: RoomDisplayName) {
if let Some(mut inner) = self.borrow_mut() {
inner.set_displayed_invite(cx, room_id, room_name);
}
Expand Down
28 changes: 13 additions & 15 deletions src/home/main_desktop_ui.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use makepad_widgets::*;
use matrix_sdk::ruma::OwnedRoomId;
use matrix_sdk::{RoomDisplayName, ruma::OwnedRoomId};
use tokio::sync::Notify;
use std::{collections::HashMap, sync::Arc};

Expand Down Expand Up @@ -132,11 +132,11 @@ impl MainDesktopUI {
let (kind, name) = match &room {
SelectedRoom::JoinedRoom { room_id, room_name } => (
id!(room_screen),
room_name_or_id(room_name.as_ref(), room_id),
room_name_or_id(room_name.clone().into_inner(), room_id),
),
SelectedRoom::InvitedRoom { room_id, room_name } => (
id!(invite_screen),
room_name_or_id(room_name.as_ref(), room_id),
room_name_or_id(room_name.clone().into_inner(), room_id),
),
};
let new_tab_widget = dock.create_and_select_tab(
Expand All @@ -154,18 +154,18 @@ impl MainDesktopUI {
if let Some(new_widget) = new_tab_widget {
self.room_order.push(room.clone());
match &room {
SelectedRoom::JoinedRoom { room_id, .. } => {
SelectedRoom::JoinedRoom { room_id, room_name } => {
new_widget.as_room_screen().set_displayed_room(
cx,
room_id.clone().into(),
room.room_name().cloned(),
room_name.as_ref().clone(),
);
}
SelectedRoom::InvitedRoom { room_id, room_name: _ } => {
new_widget.as_invite_screen().set_displayed_invite(
cx,
room_id.clone().into(),
room.room_name().cloned()
room.room_name().clone()
);
}
}
Expand Down Expand Up @@ -234,14 +234,14 @@ impl MainDesktopUI {
cx: &mut Cx,
_scope: &mut Scope,
room_id: OwnedRoomId,
room_name: Option<String>,
room_name: RoomDisplayName,
) {
let dock = self.view.dock(ids!(dock));
let Some((new_widget, true)) = dock.replace_tab(
cx,
LiveId::from_str(room_id.as_str()),
id!(room_screen),
Some(room_name_or_id(room_name.as_ref(), &room_id)),
Some(room_name_or_id(&room_name, &room_id)),
false,
) else {
// Nothing we can really do here except log an error.
Expand All @@ -250,11 +250,9 @@ impl MainDesktopUI {
};

// Set the info to be displayed in the newly-replaced RoomScreen..
new_widget.as_room_screen().set_displayed_room(
cx,
room_id.clone(),
room_name.clone(),
);
new_widget
.as_room_screen()
.set_displayed_room(cx, room_id.clone(), room_name.clone());

// Go through all existing `SelectedRoom` instances and replace the
// `SelectedRoom::InvitedRoom`s with `SelectedRoom::JoinedRoom`s.
Expand Down Expand Up @@ -366,14 +364,14 @@ impl WidgetMatchEvent for MainDesktopUI {
widget.as_room_screen().set_displayed_room(
cx,
room_id.clone().into(),
room_name.clone(),
room_name.as_ref().clone(),
);
}
Some(SelectedRoom::InvitedRoom { room_id, room_name }) => {
widget.as_invite_screen().set_displayed_invite(
cx,
room_id.clone().into(),
room_name.clone(),
room_name.as_ref().clone(),
);
}
_ => { }
Expand Down
4 changes: 2 additions & 2 deletions src/home/main_mobile_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ impl Widget for MainMobileUI {
// Get a reference to the `RoomScreen` widget and tell it which room's data to show.
self.view
.room_screen(ids!(room_screen))
.set_displayed_room(cx, room_id.clone().into(), room_name.clone());
.set_displayed_room(cx, room_id.clone().into(), room_name.as_ref().clone());
}
Some(SelectedRoom::InvitedRoom { room_id, room_name }) => {
show_welcome = false;
show_room = false;
show_invite = true;
self.view
.invite_screen(ids!(invite_screen))
.set_displayed_invite(cx, room_id.clone().into(), room_name.clone());
.set_displayed_invite(cx, room_id.clone().into(), room_name.clone().into());
}
None => {
show_welcome = true;
Expand Down
Loading
Loading