mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
refactor: Replace more uses of RoomVersionId with RoomVersionRules
This commit is contained in:
@@ -11,7 +11,7 @@ use std::fmt::Debug;
|
||||
|
||||
use ruma::{
|
||||
CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, RoomId,
|
||||
RoomVersionId, UserId, events::TimelineEventType,
|
||||
RoomVersionId, UserId, events::TimelineEventType, room_version_rules::RoomVersionRules,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value as JsonValue, value::RawValue as RawJsonValue};
|
||||
@@ -95,11 +95,11 @@ pub trait Event: Clone + Debug {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn redacts_id(&self, room_version: &RoomVersionId) -> Option<OwnedEventId>
|
||||
fn redacts_id(&self, room_version_rules: &RoomVersionRules) -> Option<OwnedEventId>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
redact::redacts_id(self, room_version)
|
||||
redact::redacts_id(self, room_version_rules)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use ruma::{CanonicalJsonObject, OwnedEventId, RoomVersionId};
|
||||
use ruma::{CanonicalJsonObject, OwnedEventId, room_version_rules::RoomVersionRules};
|
||||
use serde_json::value::RawValue as RawJsonValue;
|
||||
|
||||
use crate::{Err, Result, err};
|
||||
@@ -9,12 +9,12 @@ use crate::{Err, Result, err};
|
||||
/// CanonicalJsonValue>`.
|
||||
pub fn gen_event_id_canonical_json(
|
||||
pdu: &RawJsonValue,
|
||||
room_version_id: &RoomVersionId,
|
||||
room_version_rules: &RoomVersionRules,
|
||||
) -> Result<(OwnedEventId, CanonicalJsonObject)> {
|
||||
let value: CanonicalJsonObject = serde_json::from_str(pdu.get())
|
||||
.map_err(|e| err!(BadServerResponse(warn!("Error parsing incoming event: {e:?}"))))?;
|
||||
|
||||
let event_id = gen_event_id(&value, room_version_id)?;
|
||||
let event_id = gen_event_id(&value, room_version_rules)?;
|
||||
|
||||
Ok((event_id, value))
|
||||
}
|
||||
@@ -22,12 +22,9 @@ pub fn gen_event_id_canonical_json(
|
||||
/// Generates a correct eventId for the incoming pdu.
|
||||
pub fn gen_event_id(
|
||||
value: &CanonicalJsonObject,
|
||||
room_version_id: &RoomVersionId,
|
||||
room_version_rules: &RoomVersionRules,
|
||||
) -> Result<OwnedEventId> {
|
||||
let Some(rules) = room_version_id.rules() else {
|
||||
return Err!("Cannot generate event ID for unknown room version {room_version_id}");
|
||||
};
|
||||
let reference_hash = ruma::signatures::reference_hash(value, &rules)?;
|
||||
let reference_hash = ruma::signatures::reference_hash(value, room_version_rules)?;
|
||||
let event_id: OwnedEventId = format!("${reference_hash}").try_into()?;
|
||||
|
||||
Ok(event_id)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use ruma::{
|
||||
OwnedEventId, RoomVersionId,
|
||||
events::{TimelineEventType, room::redaction::RoomRedactionEventContent},
|
||||
room_version_rules::RoomVersionRules,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::value::{RawValue as RawJsonValue, to_raw_value};
|
||||
@@ -61,7 +62,7 @@ pub(super) fn is_redacted<E: Event>(event: &E) -> bool {
|
||||
#[must_use]
|
||||
pub(super) fn redacts_id<E: Event>(
|
||||
event: &E,
|
||||
room_version: &RoomVersionId,
|
||||
room_version_rules: &RoomVersionRules,
|
||||
) -> Option<OwnedEventId> {
|
||||
use RoomVersionId::*;
|
||||
|
||||
@@ -69,14 +70,13 @@ pub(super) fn redacts_id<E: Event>(
|
||||
return None;
|
||||
}
|
||||
|
||||
match *room_version {
|
||||
| V1 | V2 | V3 | V4 | V5 | V6 | V7 | V8 | V9 | V10 =>
|
||||
event.redacts().map(ToOwned::to_owned),
|
||||
| _ =>
|
||||
event
|
||||
.get_content::<RoomRedactionEventContent>()
|
||||
.ok()?
|
||||
.redacts,
|
||||
if room_version_rules.redaction.content_field_redacts {
|
||||
event.redacts().map(ToOwned::to_owned)
|
||||
} else {
|
||||
event
|
||||
.get_content::<RoomRedactionEventContent>()
|
||||
.ok()?
|
||||
.redacts
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user