events: Add relations accessors to event enums
This commit is contained in:
parent
956871cfa6
commit
fa61cc1248
@ -5,7 +5,7 @@ use serde_json::value::RawValue as RawJsonValue;
|
|||||||
use super::{
|
use super::{
|
||||||
key,
|
key,
|
||||||
room::{encrypted, redaction::SyncRoomRedactionEvent},
|
room::{encrypted, redaction::SyncRoomRedactionEvent},
|
||||||
Redact,
|
Redact, Relations,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, RoomId,
|
serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, RoomId,
|
||||||
@ -180,6 +180,9 @@ impl AnyTimelineEvent {
|
|||||||
|
|
||||||
/// Returns this event's `transaction_id` from inside `unsigned`, if there is one.
|
/// Returns this event's `transaction_id` from inside `unsigned`, if there is one.
|
||||||
pub fn transaction_id(&self) -> Option<&TransactionId>;
|
pub fn transaction_id(&self) -> Option<&TransactionId>;
|
||||||
|
|
||||||
|
/// Returns this event's `relations` from inside `unsigned`, if that field exists.
|
||||||
|
pub fn relations(&self) -> Option<&Relations>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,6 +212,9 @@ impl AnySyncTimelineEvent {
|
|||||||
|
|
||||||
/// Returns this event's `transaction_id` from inside `unsigned`, if there is one.
|
/// Returns this event's `transaction_id` from inside `unsigned`, if there is one.
|
||||||
pub fn transaction_id(&self) -> Option<&TransactionId>;
|
pub fn transaction_id(&self) -> Option<&TransactionId>;
|
||||||
|
|
||||||
|
/// Returns this event's `relations` from inside `unsigned`, if that field exists.
|
||||||
|
pub fn relations(&self) -> Option<&Relations>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts `self` to an `AnyTimelineEvent` by adding the given a room ID.
|
/// Converts `self` to an `AnyTimelineEvent` by adding the given a room ID.
|
||||||
|
@ -575,8 +575,10 @@ fn expand_accessor_methods(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let txn_id_accessor = maybe_redacted.then(|| {
|
let maybe_redacted_accessors = maybe_redacted.then(|| {
|
||||||
let variants = variants.iter().map(|v| v.match_arm(quote! { Self }));
|
let variants = variants.iter().map(|v| v.match_arm(quote! { Self }));
|
||||||
|
let variants2 = variants.clone();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
/// Returns this event's `transaction_id` from inside `unsigned`, if there is one.
|
/// Returns this event's `transaction_id` from inside `unsigned`, if there is one.
|
||||||
pub fn transaction_id(&self) -> Option<&#ruma_common::TransactionId> {
|
pub fn transaction_id(&self) -> Option<&#ruma_common::TransactionId> {
|
||||||
@ -591,6 +593,20 @@ fn expand_accessor_methods(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns this event's `relations` from inside `unsigned`, if that field exists.
|
||||||
|
pub fn relations(&self) -> Option<&#ruma_common::events::Relations> {
|
||||||
|
match self {
|
||||||
|
#(
|
||||||
|
#variants2(event) => {
|
||||||
|
event.as_original().and_then(|ev| ev.unsigned.relations.as_ref())
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
Self::_Custom(event) => {
|
||||||
|
event.as_original().and_then(|ev| ev.unsigned.relations.as_ref())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -605,7 +621,7 @@ fn expand_accessor_methods(
|
|||||||
#content_accessor
|
#content_accessor
|
||||||
#( #methods )*
|
#( #methods )*
|
||||||
#state_key_accessor
|
#state_key_accessor
|
||||||
#txn_id_accessor
|
#maybe_redacted_accessors
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user