mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
fix: Simplify visibility check code
This commit is contained in:
@@ -81,17 +81,9 @@ impl super::Service {
|
|||||||
// Handle m.replace relations - find the most recent valid one (lazy load
|
// Handle m.replace relations - find the most recent valid one (lazy load
|
||||||
// original event)
|
// original event)
|
||||||
if !replace_events.is_empty() {
|
if !replace_events.is_empty() {
|
||||||
if let Some(replacement) = Self::find_most_recent_valid_replacement(
|
if let Some(replacement) = self
|
||||||
pdu,
|
.find_most_recent_valid_replacement(user_id, pdu, &replace_events)
|
||||||
&replace_events,
|
.await?
|
||||||
async |pdu: &PduEvent| {
|
|
||||||
self.services
|
|
||||||
.state_accessor
|
|
||||||
.user_can_see_event(user_id, &pdu.room_id_or_hash(), &pdu.event_id())
|
|
||||||
.await
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
{
|
{
|
||||||
bundled.replace = Some(Self::serialize_replacement(replacement)?);
|
bundled.replace = Some(Self::serialize_replacement(replacement)?);
|
||||||
}
|
}
|
||||||
@@ -128,9 +120,10 @@ impl super::Service {
|
|||||||
/// Find the most recent valid replacement event based on origin_server_ts
|
/// Find the most recent valid replacement event based on origin_server_ts
|
||||||
/// and lexicographic event_id ordering
|
/// and lexicographic event_id ordering
|
||||||
async fn find_most_recent_valid_replacement<'a>(
|
async fn find_most_recent_valid_replacement<'a>(
|
||||||
|
&self,
|
||||||
|
user_id: &UserId,
|
||||||
original_event: &PduEvent,
|
original_event: &PduEvent,
|
||||||
replacement_events: &[&'a PdusIterItem],
|
replacement_events: &[&'a PdusIterItem],
|
||||||
visible: impl AsyncFn(&PduEvent) -> bool,
|
|
||||||
) -> Result<Option<&'a PduEvent>> {
|
) -> Result<Option<&'a PduEvent>> {
|
||||||
// Filter valid replacements and find the maximum in a single pass
|
// Filter valid replacements and find the maximum in a single pass
|
||||||
let mut result: Option<&PduEvent> = None;
|
let mut result: Option<&PduEvent> = None;
|
||||||
@@ -156,7 +149,11 @@ impl super::Service {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
if let Some(pdu) = next
|
if let Some(pdu) = next
|
||||||
&& visible(pdu).await
|
&& self
|
||||||
|
.services
|
||||||
|
.state_accessor
|
||||||
|
.user_can_see_event(user_id, &pdu.room_id_or_hash(), pdu.event_id())
|
||||||
|
.await
|
||||||
{
|
{
|
||||||
result = Some(pdu);
|
result = Some(pdu);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user