Skip to content

Commit

Permalink
Mut user can hot-update
Browse files Browse the repository at this point in the history
  • Loading branch information
aaravlu committed Nov 18, 2024
1 parent 4b1b354 commit b2afd2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,8 @@ impl RoomScreen {
///
/// Redraws this RoomScreen view if any updates were applied.
fn process_timeline_updates(&mut self, cx: &mut Cx, portal_list: &PortalListRef) {
// Check if the user has permission to send message in this room.
self.check_user_permission();
let top_space = self.view(id!(top_space));
let bottom_input = self.view(id!(bottom_input));
let no_send_permisson_notice = self.view(id!(no_send_permisson_notice));
Expand Down Expand Up @@ -1580,7 +1582,8 @@ impl RoomScreen {
typing_users = users;
}
TimelineUpdate::SendPermission(can_send) => {
if !can_send {
log!("YESYES");
if can_send == -1 {
bottom_input.set_visible(false);
no_send_permisson_notice.set_visible(true)
}
Expand Down Expand Up @@ -1762,8 +1765,6 @@ impl RoomScreen {
submit_async_request(MatrixRequest::FetchRoomMembers { room_id });
}

// Check if the user has permission to send message in this room.
self.check_user_permission();
// Now, restore the visual state of this timeline from its previously-saved state.
self.restore_state(cx, &mut tl_state);

Expand Down Expand Up @@ -2031,7 +2032,7 @@ pub enum TimelineUpdate {
users: Vec<String>,
},
/// if the user has permission to send messages in this room
SendPermission(bool),
SendPermission(i64),
}

/// The global set of all timeline states, one entry per room.
Expand Down
5 changes: 3 additions & 2 deletions src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,13 +714,14 @@ async fn async_worker(
let Some(client) = CLIENT.get() else { continue };
let Some(user_id) = client.user_id() else { continue };

let _send_frr_task = Handle::current().spawn(async move {
let _check_user_send_permission_task = Handle::current().spawn(async move {
let room = timeline.room();
let can_send = room.can_user_send_message(user_id, matrix_sdk::ruma::events::MessageLikeEventType::Message).await.unwrap_or(false);
let can_send = room.get_user_power_level(user_id).await.unwrap_or(0);

if let Err(_) = sender.send(TimelineUpdate::SendPermission(can_send)) {
error!("Failed to send the result of user send permission")
}
SignalToUI::set_ui_signal();
});
}
}
Expand Down

0 comments on commit b2afd2d

Please sign in to comment.