From 90115944bffa0cbadc9883fa0fbe3bdac505f3d7 Mon Sep 17 00:00:00 2001 From: alanpoon Date: Thu, 26 Dec 2024 11:48:26 +0800 Subject: [PATCH] removed serde_json for read_receipts --- src/home/room_screen.rs | 16 ++++++++-------- src/shared/jump_to_bottom_button.rs | 2 +- src/sliding_sync.rs | 11 ++++------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/home/room_screen.rs b/src/home/room_screen.rs index 14d62386..a6cd2d74 100644 --- a/src/home/room_screen.rs +++ b/src/home/room_screen.rs @@ -1482,7 +1482,7 @@ impl RoomScreen { tl.items = initial_items; done_loading = true; } - TimelineUpdate::NewItems { new_items, changed_indices, is_append, clear_cache, unread_messages_count } => { + TimelineUpdate::NewItems { new_items, changed_indices, is_append, clear_cache } => { if new_items.is_empty() { if !tl.items.is_empty() { log!("Timeline::handle_event(): timeline (had {} items) was cleared for room {}", tl.items.len(), tl.room_id); @@ -1546,13 +1546,10 @@ impl RoomScreen { if is_append && !portal_list.is_at_end() { if let Some(room_id) = &self.room_id { // Set the number of unread messages to unread_notification_badge by async request to avoid locking in the Main UI thread - submit_async_request(MatrixRequest::GetNumOfUnReadMessages{ room_id: room_id.clone() }); + submit_async_request(MatrixRequest::GetNumberUnreadMessages{ room_id: room_id.clone() }); } } - if let Some(unread_messages_count) = unread_messages_count { - jump_to_bottom.show_unread_message_badge(cx, unread_messages_count); - continue; - } + if clear_cache { tl.content_drawn_since_last_update.clear(); tl.profile_drawn_since_last_update.clear(); @@ -1586,6 +1583,9 @@ impl RoomScreen { tl.items = new_items; done_loading = true; } + TimelineUpdate::NewUnreadMessagesCount(unread_messages_count) => { + jump_to_bottom.show_unread_message_badge(cx, unread_messages_count); + } TimelineUpdate::TargetEventFound { target_event_id, index } => { // log!("Target event found in room {}: {target_event_id}, index: {index}", tl.room_id); tl.request_sender.send_if_modified(|requests| { @@ -2230,9 +2230,9 @@ pub enum TimelineUpdate { /// Whether to clear the entire cache of drawn items in the timeline. /// This supersedes `index_of_first_change` and is used when the entire timeline is being redrawn. clear_cache: bool, - /// The updated number of unread messages in the room. - unread_messages_count: Option }, + /// The updated number of unread messages in the room. + NewUnreadMessagesCount(u64), /// The target event ID was found at the given `index` in the timeline items vector. /// /// This means that the RoomScreen widget can scroll the timeline up to this event, diff --git a/src/shared/jump_to_bottom_button.rs b/src/shared/jump_to_bottom_button.rs index bd85ecd9..76a24477 100644 --- a/src/shared/jump_to_bottom_button.rs +++ b/src/shared/jump_to_bottom_button.rs @@ -138,7 +138,7 @@ impl JumpToBottomButton { border_width: 0.0 } }); - } if unread_message_count > 9 { + } else if unread_message_count > 9 { self.view(id!(unread_message_badge.green_view)).apply_over(cx, live!{ draw_bg: { border_width: 1.0 diff --git a/src/sliding_sync.rs b/src/sliding_sync.rs index 8334999f..71a549a2 100644 --- a/src/sliding_sync.rs +++ b/src/sliding_sync.rs @@ -616,7 +616,7 @@ async fn async_worker( } }); } - MatrixRequest::GetNumOfUnReadMessages { room_id } => { + MatrixRequest::GetNumberUnreadMessages { room_id } => { let sender = { let mut all_room_info = ALL_ROOM_INFO.lock().unwrap(); let Some(room_info) = all_room_info.get_mut(&room_id) else { @@ -628,11 +628,9 @@ async fn async_worker( }; let _fetch_task = Handle::current().spawn(async move { if let Some(unread_messages_count) = get_client() - .and_then(|c| c.get_room(&room_id)) - .map(|room| Some(room.num_unread_messages())) + .and_then(|c| c.get_room(&room_id)).map(|room| room.num_unread_messages()) { - if let Err(e) = sender.send(TimelineUpdate::NewItems { new_items: Vec::new().into(), changed_indices: 0..1, - is_append: false, clear_cache: false, unread_messages_count }) { + if let Err(e) = sender.send(TimelineUpdate::NewUnreadMessagesCount(unread_messages_count)) { log!("Failed to send timeline update: {e:?} for NumOfUnReadMessages request for room {room_id}"); } else { SignalToUI::set_ui_signal(); @@ -1049,7 +1047,7 @@ struct RoomInfo { timeline_subscriber_handler_task: JoinHandle<()>, /// A drop guard for the event handler that represents a subscription to typing notices for this room. typing_notice_subscriber: Option, - /// A broadcast receiver for room updates. + /// A boolean indicating if the update subsciber has been initialised update_subscriber_initialised: bool, /// The ID of the old tombstoned room that this room has replaced, if any. replaces_tombstoned_room: Option, @@ -2052,7 +2050,6 @@ async fn timeline_subscriber_handler( changed_indices, clear_cache, is_append, - unread_messages_count: None }).expect("Error: timeline update sender couldn't send update with new items!"); // We must send this update *after* the actual NewItems update,