Skip to content

Commit

Permalink
subscribe to updates to the list of ignored users
Browse files Browse the repository at this point in the history
This allows Robrix to be aware of the current logged-in user
ignoring or unignoring a user on a different client instance,
and respond to the fact that an ignore/unignore action has occurred
elsewhere, i.e., *beyond* the ignore user UI flow that is
driven from the UserProfileSlidingPane action buttons.

As such, we move the logic for re-paginating all cleared timelines
to the handler for updates to the ignored users lists.
  • Loading branch information
kevinaboos committed Aug 1, 2024
1 parent 3544fbc commit cbf1191
Showing 1 changed file with 38 additions and 18 deletions.
56 changes: 38 additions & 18 deletions src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,6 @@ async fn async_worker(mut receiver: UnboundedReceiver<MatrixRequest>) -> Result<
if ignore_result.is_err() {
return;
}
// After successfully (un)ignoring a user, all timelines are fully cleared by the Matrix SDK.
// Therefore, we need to re-fetch all timelines for all rooms,
// and currently the only way to actually accomplish this is via pagination.
// See: <https://github.com/matrix-org/matrix-rust-sdk/issues/1703#issuecomment-2250297923>

// We need to re-acquire the `RoomMember` object now that its state
// has changed, i.e., the user has been (un)ignored).
Expand All @@ -394,20 +390,19 @@ async fn async_worker(mut receiver: UnboundedReceiver<MatrixRequest>) -> Result<
}
}

// After a successful (un)ignore operation, all timelines get completely cleared,
// so we must re-fetch all timelines for all rooms.
// Start with the current room, since that's the one being displayed.
for room_id_to_paginate in client.get_room(&room_id)
.into_iter()
.chain(client.joined_rooms())
.map(|room| room.room_id().to_owned())
{
submit_async_request(MatrixRequest::PaginateRoomTimeline {
room_id: room_id_to_paginate,
num_events: 50,
forwards: false,
});
}
// After successfully (un)ignoring a user, all timelines are fully cleared by the Matrix SDK.
// Therefore, we need to re-fetch all timelines for all rooms,
// and currently the only way to actually accomplish this is via pagination.
// See: <https://github.com/matrix-org/matrix-rust-sdk/issues/1703#issuecomment-2250297923>
//
// Note that here we only proactively re-paginate the *current* room
// (the one being viewed by the user when this ignore request was issued),
// and all other rooms will be re-paginated in on-demand when they are viewed.
submit_async_request(MatrixRequest::PaginateRoomTimeline {
room_id,
num_events: 50,
forwards: false,
});
});
}

Expand Down Expand Up @@ -653,6 +648,9 @@ async fn async_main_loop() -> Result<()> {
let (client, _token) = login(cli).await?;
CLIENT.set(client.clone()).expect("BUG: CLIENT already set!");

// Listen for updates to the ignored user list.
handle_ignore_user_list_subscriber(client.clone());

let mut filters = ListFilters::default();
filters.not_room_types = vec!["m.space".into()]; // Ignore spaces for now.

Expand Down Expand Up @@ -904,6 +902,28 @@ async fn async_main_loop() -> Result<()> {
}


fn handle_ignore_user_list_subscriber(client: Client) {
let mut subscriber = client.subscribe_to_ignore_user_list_changes();
Handle::current().spawn(async move {
while let Some(_ignore_list) = subscriber.next().await {
log!("Received an updated ignored-user list: {_ignore_list:?}");

// After successfully (un)ignoring a user, all timelines are fully cleared by the Matrix SDK.
// Therefore, we need to re-fetch all timelines for all rooms,
// and currently the only way to actually accomplish this is via pagination.
// See: <https://github.com/matrix-org/matrix-rust-sdk/issues/1703#issuecomment-2250297923>
for joined_room in client.joined_rooms() {
submit_async_request(MatrixRequest::PaginateRoomTimeline {
room_id: joined_room.room_id().to_owned(),
num_events: 50,
forwards: false,
});
}
}
});
}


async fn timeline_subscriber_handler(
room_id: OwnedRoomId,
timeline: Arc<Timeline>,
Expand Down

0 comments on commit cbf1191

Please sign in to comment.