events: Add transaction_id accessor to applicable event enums
This commit is contained in:
parent
dd24d6be77
commit
1db716f643
@ -8,7 +8,8 @@ use super::{
|
||||
Redact,
|
||||
};
|
||||
use crate::{
|
||||
serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId, UserId,
|
||||
serde::from_raw_json_value, EventId, MilliSecondsSinceUnixEpoch, RoomId, RoomVersionId,
|
||||
TransactionId, UserId,
|
||||
};
|
||||
|
||||
event_enum! {
|
||||
@ -153,6 +154,14 @@ impl AnyRoomEvent {
|
||||
room_ev_accessor!(room_id: &RoomId);
|
||||
room_ev_accessor!(event_id: &EventId);
|
||||
room_ev_accessor!(sender: &UserId);
|
||||
|
||||
/// Returns this event's `transaction_id` from inside `unsigned`, if there is one.
|
||||
pub fn transaction_id(&self) -> Option<&TransactionId> {
|
||||
match self {
|
||||
Self::MessageLike(ev) => ev.transaction_id(),
|
||||
Self::State(ev) => ev.transaction_id(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Any sync room event.
|
||||
@ -173,6 +182,14 @@ impl AnySyncRoomEvent {
|
||||
room_ev_accessor!(event_id: &EventId);
|
||||
room_ev_accessor!(sender: &UserId);
|
||||
|
||||
/// Returns this event's `transaction_id` from inside `unsigned`, if there is one.
|
||||
pub fn transaction_id(&self) -> Option<&TransactionId> {
|
||||
match self {
|
||||
Self::MessageLike(ev) => ev.transaction_id(),
|
||||
Self::State(ev) => ev.transaction_id(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts `self` to an `AnyRoomEvent` by adding the given a room ID.
|
||||
pub fn into_full_event(self, room_id: Box<RoomId>) -> AnyRoomEvent {
|
||||
match self {
|
||||
|
@ -487,6 +487,25 @@ fn expand_accessor_methods(
|
||||
})
|
||||
});
|
||||
|
||||
let txn_id_accessor = maybe_redacted.then(|| {
|
||||
let variants = variants.iter().map(|v| v.match_arm(quote! { Self }));
|
||||
quote! {
|
||||
/// Returns this event's `transaction_id` from inside `unsigned`, if there is one.
|
||||
pub fn transaction_id(&self) -> Option<&#ruma_common::TransactionId> {
|
||||
match self {
|
||||
#(
|
||||
#variants(event) => {
|
||||
event.as_original().and_then(|ev| ev.unsigned.transaction_id.as_deref())
|
||||
}
|
||||
)*
|
||||
Self::_Custom(event) => {
|
||||
event.as_original().and_then(|ev| ev.unsigned.transaction_id.as_deref())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Ok(quote! {
|
||||
#[automatically_derived]
|
||||
impl #ident {
|
||||
@ -497,6 +516,7 @@ fn expand_accessor_methods(
|
||||
|
||||
#content_accessors
|
||||
#( #methods )*
|
||||
#txn_id_accessor
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user