Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aaravlu committed Dec 18, 2024
1 parent e096933 commit 1f0df95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
12 changes: 4 additions & 8 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,10 @@ impl RoomScreen {
/// Invoke this when this timeline is being shown,
/// e.g., when the user navigates to this timeline.
fn show_timeline(&mut self, cx: &mut Cx) {
self.check_can_user_send_message();
// Send request as `MatrixRequest` to check post permission.
if let Some(room_id) = self.room_id.clone() {
submit_async_request(MatrixRequest::CheckCanUserSendMessage { room_id })
}

let room_id = self.room_id.clone()
.expect("BUG: Timeline::show_timeline(): no room_id was set.");
Expand Down Expand Up @@ -2132,13 +2135,6 @@ impl RoomScreen {
}
tl.last_scrolled_index = first_index;
}

/// Send request as `MatrixRequest` to check post permission.
fn check_can_user_send_message(&self) {
if let Some(room_id) = self.room_id.clone() {
submit_async_request(MatrixRequest::CheckCanUserSendMessage { room_id })
}
}
}

impl RoomScreenRef {
Expand Down
17 changes: 11 additions & 6 deletions src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ pub enum MatrixRequest {
room_id: OwnedRoomId,
event_id: OwnedEventId,
},
/// Sends user permission's checking once user entered room.
/// Sends a request checking if the currently logged-in user can send a message to the given room.
///
/// The response is delivered back to the main UI thread via a `TimelineUpdate::CanUserSendMessage`.
CheckCanUserSendMessage{
room_id: OwnedRoomId,
}
Expand Down Expand Up @@ -791,13 +793,17 @@ async fn async_worker(
(room_info.timeline.clone(), room_info.timeline_update_sender.clone())
};

let Some(client) = CLIENT.get() else { continue };
let Some(user_id) = client.user_id() else { continue };
let Some(user_id) = current_user_id() else { continue };

let _check_can_user_send_message_task = Handle::current().spawn(async move {
let room = timeline.room();

let can_user_send_message = room.can_user_send_message(user_id, matrix_sdk::ruma::events::MessageLikeEventType::Message).await.unwrap_or(false);
let can_user_send_message = room.can_user_send_message(
&user_id,
matrix_sdk::ruma::events::MessageLikeEventType::Message
)
.await
.unwrap_or(false);

if let Err(e) = sender.send(TimelineUpdate::CanUserSendMessage(can_user_send_message)) {
error!("Failed to send the result of if user can send message: {e}")
Expand Down Expand Up @@ -1923,8 +1929,7 @@ fn update_latest_event(
room_avatar_changed = true;
}
AnyOtherFullStateEventContent::RoomPowerLevels(_power_level_event) => {
let id = room_id.clone();
submit_async_request(MatrixRequest::CheckCanUserSendMessage { room_id: id })
submit_async_request(MatrixRequest::CheckCanUserSendMessage { room_id: room_id.clone() })
}
_ => { }
}
Expand Down

0 comments on commit 1f0df95

Please sign in to comment.