Skip to content

Commit

Permalink
removed serde_json for read_receipts
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpoon committed Dec 26, 2024
1 parent 3028b7b commit 9011594
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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<u64>
},
/// 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,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/jump_to_bottom_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down Expand Up @@ -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<EventHandlerDropGuard>,
/// 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<OwnedRoomId>,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9011594

Please sign in to comment.