refactor various Arc<EventId> to OwnedEventId

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-12-28 00:57:02 +00:00 committed by strawberry
parent 5a335933b8
commit 6458f4b195
29 changed files with 142 additions and 152 deletions

View file

@ -1,8 +1,8 @@
use std::{collections::BTreeMap, sync::Arc};
use std::collections::BTreeMap;
use ruma::{
events::{EventContent, MessageLikeEventType, StateEventType, TimelineEventType},
EventId, MilliSecondsSinceUnixEpoch,
MilliSecondsSinceUnixEpoch, OwnedEventId,
};
use serde::Deserialize;
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
@ -19,7 +19,7 @@ pub struct Builder {
pub state_key: Option<String>,
pub redacts: Option<Arc<EventId>>,
pub redacts: Option<OwnedEventId>,
/// For timestamped messaging, should only be used for appservices.
/// Will be set to current time if None

View file

@ -1,13 +1,11 @@
use std::sync::Arc;
pub use ruma::state_res::Event;
use ruma::{events::TimelineEventType, EventId, MilliSecondsSinceUnixEpoch, RoomId, UserId};
use ruma::{events::TimelineEventType, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, UserId};
use serde_json::value::RawValue as RawJsonValue;
use super::Pdu;
impl Event for Pdu {
type Id = Arc<EventId>;
type Id = OwnedEventId;
fn event_id(&self) -> &Self::Id { &self.event_id }

View file

@ -12,11 +12,11 @@ mod strip;
mod tests;
mod unsigned;
use std::{cmp::Ordering, sync::Arc};
use std::cmp::Ordering;
use ruma::{
events::TimelineEventType, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedRoomId,
OwnedUserId, UInt,
events::TimelineEventType, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId,
OwnedRoomId, OwnedUserId, UInt,
};
use serde::{Deserialize, Serialize};
use serde_json::value::RawValue as RawJsonValue;
@ -35,7 +35,7 @@ use crate::Result;
/// Persistent Data Unit (Event)
#[derive(Clone, Deserialize, Serialize, Debug)]
pub struct Pdu {
pub event_id: Arc<EventId>,
pub event_id: OwnedEventId,
pub room_id: OwnedRoomId,
pub sender: OwnedUserId,
#[serde(skip_serializing_if = "Option::is_none")]
@ -46,11 +46,11 @@ pub struct Pdu {
pub content: Box<RawJsonValue>,
#[serde(skip_serializing_if = "Option::is_none")]
pub state_key: Option<String>,
pub prev_events: Vec<Arc<EventId>>,
pub prev_events: Vec<OwnedEventId>,
pub depth: UInt,
pub auth_events: Vec<Arc<EventId>>,
pub auth_events: Vec<OwnedEventId>,
#[serde(skip_serializing_if = "Option::is_none")]
pub redacts: Option<Arc<EventId>>,
pub redacts: Option<OwnedEventId>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub unsigned: Option<Box<RawJsonValue>>,
pub hashes: EventHash,

View file

@ -1,9 +1,7 @@
use std::sync::Arc;
use ruma::{
canonical_json::redact_content_in_place,
events::{room::redaction::RoomRedactionEventContent, TimelineEventType},
EventId, RoomVersionId,
OwnedEventId, RoomVersionId,
};
use serde::Deserialize;
use serde_json::{
@ -73,15 +71,15 @@ pub fn is_redacted(&self) -> bool {
/// > such events over the Client-Server API.
#[implement(super::Pdu)]
#[must_use]
pub fn copy_redacts(&self) -> (Option<Arc<EventId>>, Box<RawJsonValue>) {
pub fn copy_redacts(&self) -> (Option<OwnedEventId>, Box<RawJsonValue>) {
if self.kind == TimelineEventType::RoomRedaction {
if let Ok(mut content) =
serde_json::from_str::<RoomRedactionEventContent>(self.content.get())
{
if let Some(redacts) = content.redacts {
return (Some(redacts.into()), self.content.clone());
return (Some(redacts), self.content.clone());
} else if let Some(redacts) = self.redacts.clone() {
content.redacts = Some(redacts.into());
content.redacts = Some(redacts);
return (
self.redacts.clone(),
to_raw_value(&content).expect("Must be valid, we only added redacts field"),