mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-12-28 21:43:47 +03:00
refactor: restore src/service/rooms/outlier/mod.rs
This commit is contained in:
parent
715b30a2b5
commit
daa969508f
1 changed files with 27 additions and 0 deletions
27
src/service/rooms/outlier/mod.rs
Normal file
27
src/service/rooms/outlier/mod.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/// Returns the pdu from the outlier tree.
|
||||||
|
pub fn get_outlier_pdu_json(&self, event_id: &EventId) -> Result<Option<CanonicalJsonObject>> {
|
||||||
|
self.eventid_outlierpdu
|
||||||
|
.get(event_id.as_bytes())?
|
||||||
|
.map_or(Ok(None), |pdu| {
|
||||||
|
serde_json::from_slice(&pdu).map_err(|_| Error::bad_database("Invalid PDU in db."))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the pdu from the outlier tree.
|
||||||
|
pub fn get_pdu_outlier(&self, event_id: &EventId) -> Result<Option<PduEvent>> {
|
||||||
|
self.eventid_outlierpdu
|
||||||
|
.get(event_id.as_bytes())?
|
||||||
|
.map_or(Ok(None), |pdu| {
|
||||||
|
serde_json::from_slice(&pdu).map_err(|_| Error::bad_database("Invalid PDU in db."))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Append the PDU as an outlier.
|
||||||
|
#[tracing::instrument(skip(self, pdu))]
|
||||||
|
pub fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()> {
|
||||||
|
self.eventid_outlierpdu.insert(
|
||||||
|
event_id.as_bytes(),
|
||||||
|
&serde_json::to_vec(&pdu).expect("CanonicalJsonObject is valid"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue