@@ -49,7 +49,11 @@ pub fn room_state_full_pdus<'a>(
|
||||
self.services
|
||||
.state
|
||||
.get_room_shortstatehash(room_id)
|
||||
.map_ok(|shortstatehash| self.state_full_pdus(shortstatehash).map(Ok).boxed())
|
||||
.map_ok(|shortstatehash| {
|
||||
self.state_full_pdus(shortstatehash)
|
||||
.map(Ok)
|
||||
.boxed()
|
||||
})
|
||||
.map_err(move |e| err!(Database("Missing state for {room_id:?}: {e:?}")))
|
||||
.try_flatten_stream()
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ use crate::rooms::{
|
||||
#[implement(super::Service)]
|
||||
#[inline]
|
||||
pub async fn user_was_joined(&self, shortstatehash: ShortStateHash, user_id: &UserId) -> bool {
|
||||
self.user_membership(shortstatehash, user_id).await == MembershipState::Join
|
||||
self.user_membership(shortstatehash, user_id)
|
||||
.await == MembershipState::Join
|
||||
}
|
||||
|
||||
/// The user was an invited or joined room member at this state (potentially
|
||||
@@ -37,7 +38,9 @@ pub async fn user_was_joined(&self, shortstatehash: ShortStateHash, user_id: &Us
|
||||
#[implement(super::Service)]
|
||||
#[inline]
|
||||
pub async fn user_was_invited(&self, shortstatehash: ShortStateHash, user_id: &UserId) -> bool {
|
||||
let s = self.user_membership(shortstatehash, user_id).await;
|
||||
let s = self
|
||||
.user_membership(shortstatehash, user_id)
|
||||
.await;
|
||||
s == MembershipState::Join || s == MembershipState::Invite
|
||||
}
|
||||
|
||||
@@ -259,7 +262,9 @@ pub fn state_keys_with_shortids<'a>(
|
||||
.zip(shorteventids)
|
||||
.ready_filter_map(|(res, id)| res.map(|res| (res, id)).ok())
|
||||
.ready_filter_map(move |((event_type_, state_key), event_id)| {
|
||||
event_type_.eq(event_type).then_some((state_key, event_id))
|
||||
event_type_
|
||||
.eq(event_type)
|
||||
.then_some((state_key, event_id))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -338,7 +343,11 @@ pub fn state_full_pdus(
|
||||
.multi_get_eventid_from_short(short_ids)
|
||||
.ready_filter_map(Result::ok)
|
||||
.broad_filter_map(move |event_id: OwnedEventId| async move {
|
||||
self.services.timeline.get_pdu(&event_id).await.ok()
|
||||
self.services
|
||||
.timeline
|
||||
.get_pdu(&event_id)
|
||||
.await
|
||||
.ok()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -406,7 +415,12 @@ async fn load_full_state(&self, shortstatehash: ShortStateHash) -> Result<Arc<Co
|
||||
.state_compressor
|
||||
.load_shortstatehash_info(shortstatehash)
|
||||
.map_err(|e| err!(Database("Missing state IDs: {e}")))
|
||||
.map_ok(|vec| vec.last().expect("at least one layer").full_state.clone())
|
||||
.map_ok(|vec| {
|
||||
vec.last()
|
||||
.expect("at least one layer")
|
||||
.full_state
|
||||
.clone()
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,11 @@ pub async fn user_can_see_event(
|
||||
return true;
|
||||
};
|
||||
|
||||
let currently_member = self.services.state_cache.is_joined(user_id, room_id).await;
|
||||
let currently_member = self
|
||||
.services
|
||||
.state_cache
|
||||
.is_joined(user_id, room_id)
|
||||
.await;
|
||||
|
||||
let history_visibility = self
|
||||
.state_get_content(shortstatehash, &StateEventType::RoomHistoryVisibility, "")
|
||||
@@ -110,11 +114,13 @@ pub async fn user_can_see_event(
|
||||
match history_visibility {
|
||||
| HistoryVisibility::Invited => {
|
||||
// Allow if any member on requesting server was AT LEAST invited, else deny
|
||||
self.user_was_invited(shortstatehash, user_id).await
|
||||
self.user_was_invited(shortstatehash, user_id)
|
||||
.await
|
||||
},
|
||||
| HistoryVisibility::Joined => {
|
||||
// Allow if any member on requested server was joined, else deny
|
||||
self.user_was_joined(shortstatehash, user_id).await
|
||||
self.user_was_joined(shortstatehash, user_id)
|
||||
.await
|
||||
},
|
||||
| HistoryVisibility::WorldReadable => true,
|
||||
| HistoryVisibility::Shared | _ => currently_member,
|
||||
@@ -126,7 +132,12 @@ pub async fn user_can_see_event(
|
||||
#[implement(super::Service)]
|
||||
#[tracing::instrument(skip_all, level = "trace")]
|
||||
pub async fn user_can_see_state_events(&self, user_id: &UserId, room_id: &RoomId) -> bool {
|
||||
if self.services.state_cache.is_joined(user_id, room_id).await {
|
||||
if self
|
||||
.services
|
||||
.state_cache
|
||||
.is_joined(user_id, room_id)
|
||||
.await
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -139,7 +150,10 @@ pub async fn user_can_see_state_events(&self, user_id: &UserId, room_id: &RoomId
|
||||
|
||||
match history_visibility {
|
||||
| HistoryVisibility::Invited =>
|
||||
self.services.state_cache.is_invited(user_id, room_id).await,
|
||||
self.services
|
||||
.state_cache
|
||||
.is_invited(user_id, room_id)
|
||||
.await,
|
||||
| HistoryVisibility::WorldReadable => true,
|
||||
| _ => false,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user