From 092ca9040348e101c43a5e08f25c6d751683fdf4 Mon Sep 17 00:00:00 2001 From: SaurusXI Date: Sun, 20 Jun 2021 12:24:40 +0530 Subject: [PATCH 1/5] matrix-sdk: add method to check room's event visibility --- matrix_sdk/src/room/common.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/matrix_sdk/src/room/common.rs b/matrix_sdk/src/room/common.rs index 22fab1c8..516c234d 100644 --- a/matrix_sdk/src/room/common.rs +++ b/matrix_sdk/src/room/common.rs @@ -7,6 +7,7 @@ use ruma::{ membership::{get_member_events, join_room_by_id, leave_room}, message::get_message_events, }, + events::room::history_visibility::HistoryVisibility, UserId, }; @@ -176,6 +177,17 @@ impl Common { Ok(()) } + fn are_events_visible(&self) -> bool { + if let RoomType::Invited = self.inner.room_type() { + match self.inner.history_visibility() { + HistoryVisibility::WorldReadable | HistoryVisibility::Shared => true, + _ => false, + } + } + + true + } + /// Sync the member list with the server. /// /// This method will de-duplicate requests if it is called multiple times in From 0e84349d059c08d5b958013390e1a8ee99968d7c Mon Sep 17 00:00:00 2001 From: SaurusXI Date: Sun, 20 Jun 2021 12:30:12 +0530 Subject: [PATCH 2/5] matrix-sdk: add event visibility check to ensure_members --- matrix_sdk/src/room/common.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/matrix_sdk/src/room/common.rs b/matrix_sdk/src/room/common.rs index 516c234d..4da317f4 100644 --- a/matrix_sdk/src/room/common.rs +++ b/matrix_sdk/src/room/common.rs @@ -13,7 +13,7 @@ use ruma::{ use crate::{ media::{MediaFormat, MediaRequest, MediaType}, - BaseRoom, Client, Result, RoomMember, + BaseRoom, Client, Result, RoomMember, room::RoomType, error::{self, HttpError} }; /// A struct containing methods that are common for Joined, Invited and Left @@ -170,6 +170,12 @@ impl Common { } async fn ensure_members(&self) -> Result<()> { + if !self.are_events_visible() { + return Err( + error::Error::Http(HttpError::NotClientRequest) + ) + } + if !self.are_members_synced() { self.request_members().await?; } @@ -179,7 +185,7 @@ impl Common { fn are_events_visible(&self) -> bool { if let RoomType::Invited = self.inner.room_type() { - match self.inner.history_visibility() { + return match self.inner.history_visibility() { HistoryVisibility::WorldReadable | HistoryVisibility::Shared => true, _ => false, } From b984fcca0c8969917405f2d742f2356ba6540b72 Mon Sep 17 00:00:00 2001 From: SaurusXI Date: Mon, 21 Jun 2021 18:06:55 +0530 Subject: [PATCH 3/5] matrix-sdk: (fix) correct the history visibility states that allow us to view events in are_events_visible --- matrix_sdk/src/room/common.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/matrix_sdk/src/room/common.rs b/matrix_sdk/src/room/common.rs index 4da317f4..02c8583b 100644 --- a/matrix_sdk/src/room/common.rs +++ b/matrix_sdk/src/room/common.rs @@ -12,8 +12,10 @@ use ruma::{ }; use crate::{ + error::{self, HttpError}, media::{MediaFormat, MediaRequest, MediaType}, - BaseRoom, Client, Result, RoomMember, room::RoomType, error::{self, HttpError} + room::RoomType, + BaseRoom, Client, Result, RoomMember, }; /// A struct containing methods that are common for Joined, Invited and Left @@ -171,9 +173,7 @@ impl Common { async fn ensure_members(&self) -> Result<()> { if !self.are_events_visible() { - return Err( - error::Error::Http(HttpError::NotClientRequest) - ) + return Err(error::Error::Http(HttpError::NotClientRequest)); } if !self.are_members_synced() { @@ -186,11 +186,11 @@ impl Common { fn are_events_visible(&self) -> bool { if let RoomType::Invited = self.inner.room_type() { return match self.inner.history_visibility() { - HistoryVisibility::WorldReadable | HistoryVisibility::Shared => true, + HistoryVisibility::WorldReadable | HistoryVisibility::Invited => true, _ => false, - } + }; } - + true } From ae5be67322a6a48ea81cca1424c472c033f9c81c Mon Sep 17 00:00:00 2001 From: SaurusXI Date: Mon, 21 Jun 2021 18:28:11 +0530 Subject: [PATCH 4/5] matrix-sdk: (fix) return Ok(()) in ensure_members when returning early --- matrix_sdk/src/room/common.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/matrix_sdk/src/room/common.rs b/matrix_sdk/src/room/common.rs index 02c8583b..dfc2cf08 100644 --- a/matrix_sdk/src/room/common.rs +++ b/matrix_sdk/src/room/common.rs @@ -12,7 +12,6 @@ use ruma::{ }; use crate::{ - error::{self, HttpError}, media::{MediaFormat, MediaRequest, MediaType}, room::RoomType, BaseRoom, Client, Result, RoomMember, @@ -173,7 +172,7 @@ impl Common { async fn ensure_members(&self) -> Result<()> { if !self.are_events_visible() { - return Err(error::Error::Http(HttpError::NotClientRequest)); + return Ok(()); } if !self.are_members_synced() { From 58369fe7d08b20f0cd898255dad16b79665a13e8 Mon Sep 17 00:00:00 2001 From: SaurusXI Date: Mon, 21 Jun 2021 20:14:40 +0530 Subject: [PATCH 5/5] matrix-sdk: (fix) use macro for matching in are_events_visible --- matrix_sdk/src/room/common.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/matrix_sdk/src/room/common.rs b/matrix_sdk/src/room/common.rs index dfc2cf08..f8709b66 100644 --- a/matrix_sdk/src/room/common.rs +++ b/matrix_sdk/src/room/common.rs @@ -184,10 +184,10 @@ impl Common { fn are_events_visible(&self) -> bool { if let RoomType::Invited = self.inner.room_type() { - return match self.inner.history_visibility() { - HistoryVisibility::WorldReadable | HistoryVisibility::Invited => true, - _ => false, - }; + return matches!( + self.inner.history_visibility(), + HistoryVisibility::WorldReadable | HistoryVisibility::Invited + ); } true