conduwuit/src/service/rooms/outlier.rs

21 lines
798 B
Rust
Raw Normal View History

/// Returns the pdu from the outlier tree.
pub fn get_pdu_outlier(&self, event_id: &EventId) -> Result<Option<PduEvent>> {
self.eventid_outlierpdu
2021-02-01 12:44:30 -05:00
.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.
///
/// Any event given to this will be processed (state-res) on another thread.
#[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(),
2021-06-08 18:10:00 +02:00
&serde_json::to_vec(&pdu).expect("CanonicalJsonObject is valid"),
2021-08-28 11:39:33 +02:00
)
}