Skip to content

Commit 0e23051

Browse files
committed
cargo fmt
1 parent 59b3c1d commit 0e23051

File tree

6 files changed

+73
-36
lines changed

6 files changed

+73
-36
lines changed

src/app.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ use matrix_sdk::ruma::{OwnedRoomId, RoomId};
66
use crate::{
77
home::{main_desktop_ui::MainDesktopUiAction, new_message_context_menu::NewMessageContextMenuWidgetRefExt, room_screen::MessageAction, rooms_list::RoomsListAction}, login::login_screen::LoginAction, persistent_state::{save_room_panel, save_window_state}, shared::{callout_tooltip::{CalloutTooltipOptions, CalloutTooltipWidgetRefExt, TooltipAction}, popup_list::PopupNotificationAction}, sliding_sync::current_user_id, utils::room_name_or_id, verification::VerificationAction, verification_modal::{VerificationModalAction, VerificationModalWidgetRefExt}
88
};
9-
use serde::{de::{self, MapAccess, SeqAccess, Visitor}, ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
9+
use serde::{
10+
de::{self, MapAccess, SeqAccess, Visitor},
11+
ser::SerializeStruct,
12+
Deserialize, Deserializer, Serialize, Serializer,
13+
};
1014
use serde;
1115
use makepad_micro_serde::*;
1216
live_design! {
@@ -239,7 +243,7 @@ impl MatchEvent for App {
239243
let window = self.ui.window(id!(main_window));
240244
window.resize(cx, window_state.inner_size);
241245
window.reposition(cx, window_state.position);
242-
if window_state.is_fullscreen {
246+
if window_state.is_fullscreen {
243247
if let Some(mut window) = window.borrow_mut() {
244248
window.set_fullscreen(cx);
245249
}
@@ -349,15 +353,15 @@ impl AppMain for App {
349353
let window = self.ui.window(id!(main_window));
350354
let inner_size = window.get_inner_size(cx);
351355
let position = window.get_position(cx);
352-
let window_geom = WindowGeomState{
356+
let window_geom = WindowGeomState {
353357
inner_size,
354358
position,
355359
is_fullscreen: window.is_fullscreen(cx),
356360
};
357361
if let Err(e) = save_window_state(window_geom) {
358362
error!("Bug! Failed to save window_state: {}", e);
359363
}
360-
if let Some(user_id) = current_user_id(){
364+
if let Some(user_id) = current_user_id() {
361365
let rooms_panel = self.app_state.saved_dock_state.clone();
362366
let user_id = user_id.clone();
363367
if let Err(e) = save_room_panel(rooms_panel, user_id) {
@@ -468,7 +472,6 @@ impl SerRon for SelectedRoom {
468472

469473
// Serialize room_id field
470474
s.field(d + 1, "room_id"); // ` room_id: `
471-
//room_id.ser_ron(d + 1, s); // Serialize the OwnedRoomId value
472475
room_id.to_string().ser_ron(d + 1, s);
473476
s.conl(); // `,\n`
474477

@@ -485,7 +488,6 @@ impl SerRon for SelectedRoom {
485488

486489
// Serialize room_id field
487490
s.field(d + 1, "room_id"); // ` room_id: `
488-
//room_id.ser_ron(d + 1, s);
489491
room_id.to_string().ser_ron(d + 1, s);
490492
s.conl(); // `,\n`
491493

@@ -688,7 +690,7 @@ pub struct WindowGeomState {
688690
/// A tuple containing the window's x and y position.
689691
pub position: DVec2,
690692
/// Maximise fullscreen if true.
691-
pub is_fullscreen: bool
693+
pub is_fullscreen: bool,
692694
}
693695

694696
impl Serialize for WindowGeomState {
@@ -808,4 +810,4 @@ impl<'de> Deserialize<'de> for WindowGeomState {
808810
const FIELDS: &[&str] = &["inner_size", "position", "is_fullscreen"];
809811
deserializer.deserialize_struct("WindowGeomState", FIELDS, WindowGeomStateVisitor)
810812
}
811-
}
813+
}

src/home/main_desktop_ui.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ impl Widget for MainDesktopUI {
9797
if !self.drawn_previously {
9898
let app_state = scope.data.get_mut::<AppState>().unwrap();
9999
if !app_state.saved_dock_state.open_rooms.is_empty() {
100-
cx.action(RoomsPanelRestoreAction::Restore(app_state.saved_dock_state.clone()));
100+
cx.action(RoomsPanelRestoreAction::Restore(
101+
app_state.saved_dock_state.clone(),
102+
));
101103
}
102104
self.drawn_previously = true;
103105
}
@@ -362,14 +364,18 @@ impl WidgetMatchEvent for MainDesktopUI {
362364
room_name.clone(),
363365
);
364366
}
365-
Some(SelectedRoom::InvitedRoom { room_id, room_name: _ }) => {
366-
widget.as_invite_screen().set_displayed_invite(cx, room_id.clone());
367+
Some(SelectedRoom::InvitedRoom {
368+
room_id,
369+
room_name: _,
370+
}) => {
371+
widget
372+
.as_invite_screen()
373+
.set_displayed_invite(cx, room_id.clone());
367374
}
368-
_ => { }
375+
_ => {}
369376
}
370377
}
371-
}
372-
else {
378+
} else {
373379
error!("BUG: failed to load dock state upon DockLoad action.");
374380
continue;
375381
}

src/home/room_screen.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ impl Widget for RoomScreen {
953953
for action in actions {
954954
// Handle actions related to restoring the previously-saved state of rooms.
955955
if let Some(RoomsPanelRestoreAction::Success(room_id)) = action.downcast_ref() {
956-
if self.room_id.as_ref().is_some_and(|r| r == room_id) {
956+
if self.room_id.as_ref().is_some_and(|r| r == room_id) {
957957
// Reset room_id before displaying room.
958958
self.room_id = None;
959959
self.set_displayed_room(cx, room_id.clone(), self.room_name.clone());
@@ -962,7 +962,9 @@ impl Widget for RoomScreen {
962962
}
963963
}
964964
// Handle the highlight animation.
965-
let Some(tl) = self.tl_state.as_mut() else { continue };
965+
let Some(tl) = self.tl_state.as_mut() else {
966+
continue;
967+
};
966968
if let MessageHighlightAnimationState::Pending { item_id } = tl.message_highlight_animation_state {
967969
if portal_list.smooth_scroll_reached(actions) {
968970
cx.widget_action(

src/home/rooms_list.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,15 @@ impl RoomsList {
331331
/// Returns `true` if the number of rooms in `all_joined_rooms` and `invited_rooms` equals or exceeds
332332
/// `max_known_rooms`, or `false` if `max_known_rooms` is `None`.
333333
pub fn all_known_rooms_loaded(&self) -> bool {
334-
self.max_known_rooms.is_some_and(|max_rooms| self.all_joined_rooms.len() + self.invited_rooms.borrow().len() >= max_rooms as usize)
334+
self.max_known_rooms.is_some_and(|max_rooms| {
335+
self.all_joined_rooms.len() + self.invited_rooms.borrow().len() >= max_rooms as usize
336+
})
335337
}
336338
/// Returns `true` if the given `room_id` is already in the `all_joined_rooms` and `invited_rooms` lists.
337339
/// and `false` if it is not.
338340
pub fn is_room_loaded(&self, room_id: &OwnedRoomId) -> bool {
339-
self.all_joined_rooms.contains_key(room_id) || self.invited_rooms.borrow().contains_key(room_id)
341+
self.all_joined_rooms.contains_key(room_id)
342+
|| self.invited_rooms.borrow().contains_key(room_id)
340343
}
341344
/// Handle all pending updates to the list of all rooms.
342345
fn handle_rooms_list_updates(&mut self, cx: &mut Cx, _event: &Event, scope: &mut Scope) {
@@ -774,15 +777,17 @@ impl Widget for RoomsList {
774777

775778
impl RoomsListRef {
776779
/// See [`RoomsList::all_known_rooms_loaded()`].
777-
pub fn all_known_rooms_loaded(
778-
&self,
779-
) -> bool {
780-
let Some(inner) = self.borrow() else { return false };
780+
pub fn all_known_rooms_loaded(&self) -> bool {
781+
let Some(inner) = self.borrow() else {
782+
return false;
783+
};
781784
inner.all_known_rooms_loaded()
782785
}
783786
/// See [`RoomsList::is_room_loaded()`].
784787
pub fn is_room_loaded(&self, room_id: &OwnedRoomId) -> bool {
785-
let Some(inner) = self.borrow() else { return false };
788+
let Some(inner) = self.borrow() else {
789+
return false;
790+
};
786791
inner.is_room_loaded(room_id)
787792
}
788793
}

src/persistent_state.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
use std::path::PathBuf;
33
use anyhow::{anyhow, bail};
44
use makepad_widgets::{
5-
log, makepad_micro_serde::{DeRon, SerRon}, Cx
5+
log,
6+
makepad_micro_serde::{DeRon, SerRon},
7+
Cx,
68
};
79
use matrix_sdk::{
810
authentication::matrix::MatrixSession,
@@ -13,7 +15,11 @@ use matrix_sdk::{
1315
use serde::{Deserialize, Serialize};
1416
use tokio::{fs, io::{self, AsyncReadExt}};
1517

16-
use crate::{app::{SavedDockState, SelectedRoom, WindowGeomState}, app_data_dir, login::login_screen::LoginAction};
18+
use crate::{
19+
app::{SavedDockState, SelectedRoom, WindowGeomState},
20+
app_data_dir,
21+
login::login_screen::LoginAction,
22+
};
1723

1824
/// The data needed to re-build a client.
1925
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -150,7 +156,6 @@ pub async fn restore_session(
150156
Ok((client, sync_token))
151157
}
152158

153-
154159
/// Persist a logged-in client session to the filesystem for later use.
155160
///
156161
/// TODO: This is not very secure, for simplicity. We should use robius-keychain
@@ -202,8 +207,13 @@ pub fn save_room_panel(
202207
)?;
203208
for (tab_id, room) in &rooms_panel_state.open_rooms {
204209
match room {
205-
SelectedRoom::JoinedRoom { room_id, .. } | SelectedRoom::InvitedRoom { room_id, .. } => {
206-
assert!(rooms_panel_state.dock_items.contains_key(tab_id), "Open room id: {} not found in dock state", room_id);
210+
SelectedRoom::JoinedRoom { room_id, .. }
211+
| SelectedRoom::InvitedRoom { room_id, .. } => {
212+
assert!(
213+
rooms_panel_state.dock_items.contains_key(tab_id),
214+
"Open room id: {} not found in dock state",
215+
room_id
216+
);
207217
}
208218
}
209219
}
@@ -233,8 +243,8 @@ pub async fn load_rooms_panel_state(user_id: &UserId) -> anyhow::Result<SavedDoc
233243
let mut contents = String::with_capacity(file.metadata().await?.len() as usize);
234244
file.read_to_string(&mut contents).await?;
235245
let dock_state: SavedDockState =
236-
SavedDockState::deserialize_ron(&contents).map_err(|er| anyhow::Error::msg(er.msg))?;
237-
246+
SavedDockState::deserialize_ron(&contents).map_err(|er| anyhow::Error::msg(er.msg))?;
247+
238248
Ok(dock_state)
239249
}
240250

src/sliding_sync.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ fn handle_ignore_user_list_subscriber(client: Client) {
19511951
}
19521952

19531953
/// Asynchronously loads and restores the rooms panel state from persistent storage for the given user.
1954-
///
1954+
///
19551955
/// If the loaded state contains open rooms and dock state, it logs a message and posts an action
19561956
/// to restore the rooms panel state in the UI. If loading fails, it enqueues a notification
19571957
/// with the error message.
@@ -1974,7 +1974,7 @@ fn handle_load_rooms_panel_state(user_id: OwnedUserId) {
19741974
}
19751975

19761976
/// Asynchronously loads and restores the window geometry state from persistent storage.
1977-
///
1977+
///
19781978
/// If the loaded state is different from the default, it posts an action to restore
19791979
/// the window's geometry in the UI. If loading fails, it enqueues a notification
19801980
/// with the error message.
@@ -2010,18 +2010,30 @@ fn handle_sync_service_state_subscriber(mut subscriber: Subscriber<sync_service:
20102010
});
20112011
}
20122012

2013-
2013+
/// Handles room list loading state updates from the room list service.
2014+
///
2015+
/// Posts `RoomsListUpdate` actions to the UI to update the rooms list based on the received state.
2016+
///
2017+
/// If the state is `NotLoaded`, it posts a `NotLoaded` update to the UI. If the state is
2018+
/// `Loaded { maximum_number_of_rooms }`, it posts a `LoadedRooms { max_rooms }` update to the UI.
20142019
fn handle_room_list_service_loading_state(mut loading_state: Subscriber<RoomListLoadingState>) {
2015-
log!("Initial room list loading state is {:?}", loading_state.get());
2020+
log!(
2021+
"Initial room list loading state is {:?}",
2022+
loading_state.get()
2023+
);
20162024
Handle::current().spawn(async move {
20172025
while let Some(state) = loading_state.next().await {
20182026
log!("Received a room list loading state update: {state:?}");
20192027
match state {
20202028
RoomListLoadingState::NotLoaded => {
20212029
enqueue_rooms_list_update(RoomsListUpdate::NotLoaded);
20222030
}
2023-
RoomListLoadingState::Loaded { maximum_number_of_rooms } => {
2024-
enqueue_rooms_list_update(RoomsListUpdate::LoadedRooms { max_rooms: maximum_number_of_rooms });
2031+
RoomListLoadingState::Loaded {
2032+
maximum_number_of_rooms,
2033+
} => {
2034+
enqueue_rooms_list_update(RoomsListUpdate::LoadedRooms {
2035+
max_rooms: maximum_number_of_rooms,
2036+
});
20252037
}
20262038
}
20272039
}

0 commit comments

Comments
 (0)