mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 15:21:24 +01:00
refactor Pdu::copy_redacts to use early returns
This commit is contained in:
parent
88ad596e8d
commit
9a142c7557
1 changed files with 19 additions and 18 deletions
|
|
@ -161,26 +161,27 @@ impl PduEvent {
|
||||||
pub(crate) fn copy_redacts(
|
pub(crate) fn copy_redacts(
|
||||||
&self,
|
&self,
|
||||||
) -> (Option<Arc<EventId>>, Box<RawJsonValue>) {
|
) -> (Option<Arc<EventId>>, Box<RawJsonValue>) {
|
||||||
if self.kind == TimelineEventType::RoomRedaction {
|
if self.kind != TimelineEventType::RoomRedaction {
|
||||||
if let Ok(mut content) = serde_json::from_str::<
|
return (self.redacts.clone(), self.content.clone());
|
||||||
RoomRedactionEventContent,
|
|
||||||
>(self.content.get())
|
|
||||||
{
|
|
||||||
if let Some(redacts) = content.redacts {
|
|
||||||
return (Some(redacts.into()), self.content.clone());
|
|
||||||
} else if let Some(redacts) = self.redacts.clone() {
|
|
||||||
content.redacts = Some(redacts.into());
|
|
||||||
return (
|
|
||||||
self.redacts.clone(),
|
|
||||||
to_raw_value(&content).expect(
|
|
||||||
"Must be valid, we only added redacts field",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
let Ok(mut content) = serde_json::from_str::<RoomRedactionEventContent>(
|
||||||
|
self.content.get(),
|
||||||
|
) else {
|
||||||
|
return (self.redacts.clone(), self.content.clone());
|
||||||
|
};
|
||||||
|
|
||||||
(self.redacts.clone(), self.content.clone())
|
if let Some(redacts) = content.redacts {
|
||||||
|
(Some(redacts.into()), self.content.clone())
|
||||||
|
} else if let Some(redacts) = self.redacts.clone() {
|
||||||
|
content.redacts = Some(redacts.into());
|
||||||
|
(
|
||||||
|
self.redacts.clone(),
|
||||||
|
to_raw_value(&content)
|
||||||
|
.expect("Must be valid, we only added redacts field"),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(self.redacts.clone(), self.content.clone())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue