Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Give notice if user donnot have permission to post
Browse files Browse the repository at this point in the history
aaravlu committed Nov 20, 2024
1 parent b700faa commit 2781d2d
Showing 2 changed files with 16 additions and 14 deletions.
18 changes: 9 additions & 9 deletions src/home/room_screen.rs
Original file line number Diff line number Diff line change
@@ -1434,8 +1434,6 @@ 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));
@@ -1582,14 +1580,14 @@ impl RoomScreen {
typing_users = users;
}
TimelineUpdate::SendPermission(can_send) => {
if can_send == -1 {
bottom_input.set_visible(false);
no_send_permisson_notice.set_visible(true)
}
else {
if can_send {
bottom_input.set_visible(true);
no_send_permisson_notice.set_visible(false)
}
else {
bottom_input.set_visible(false);
no_send_permisson_notice.set_visible(true)
}
}

}
@@ -1705,6 +1703,8 @@ 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) {
// Check if the user has permission to send message in this room.
self.check_user_send_permission();
let room_id = self.room_id.clone()
.expect("BUG: Timeline::show_timeline(): no room_id was set.");
// just an optional sanity check
@@ -1963,7 +1963,7 @@ impl RoomScreen {
}
tl.last_scrolled_index = first_index;
}
fn check_user_permission(&self) {
fn check_user_send_permission(&self) {
if let Some(room_id) = self.room_id.clone() {
submit_async_request(MatrixRequest::CheckUserSendPermission { room_id })
}
@@ -2031,7 +2031,7 @@ pub enum TimelineUpdate {
users: Vec<String>,
},
/// if the user has permission to send messages in this room
SendPermission(i64),
SendPermission(bool),
}

/// The global set of all timeline states, one entry per room.
12 changes: 7 additions & 5 deletions src/sliding_sync.rs
Original file line number Diff line number Diff line change
@@ -716,12 +716,11 @@ async fn async_worker(

let _check_user_send_permission_task = Handle::current().spawn(async move {
let room = timeline.room();
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")
if let Ok(can_send) = room.can_user_send_message(user_id, matrix_sdk::ruma::events::MessageLikeEventType::Message).await {
if let Err(_) = sender.send(TimelineUpdate::SendPermission(can_send)) {
error!("Failed check user send permission")
}
}
SignalToUI::set_ui_signal();
});
}
}
@@ -1629,6 +1628,9 @@ fn update_latest_event(
AnyOtherFullStateEventContent::RoomAvatar(_avatar_event) => {
room_avatar_changed = true;
}
AnyOtherFullStateEventContent::RoomPowerLevels(_user_power_level_event) => {
submit_async_request(MatrixRequest::CheckUserSendPermission { room_id: room_id.clone() });
}
_ => { }
}
_ => { }

0 comments on commit 2781d2d

Please sign in to comment.