events: Add method to get user receipt in ReceiptEventContent
This commit is contained in:
parent
77e44d6428
commit
0450f9d8f7
@ -23,6 +23,20 @@ use crate::{receipt::ReceiptType, EventId, MilliSecondsSinceUnixEpoch, UserId};
|
|||||||
#[ruma_event(type = "m.receipt", kind = EphemeralRoom)]
|
#[ruma_event(type = "m.receipt", kind = EphemeralRoom)]
|
||||||
pub struct ReceiptEventContent(pub BTreeMap<Box<EventId>, Receipts>);
|
pub struct ReceiptEventContent(pub BTreeMap<Box<EventId>, Receipts>);
|
||||||
|
|
||||||
|
impl ReceiptEventContent {
|
||||||
|
/// Get the receipt for the given user ID with the given receipt type, if it exists.
|
||||||
|
pub fn user_receipt(
|
||||||
|
&self,
|
||||||
|
user_id: &UserId,
|
||||||
|
receipt_type: ReceiptType,
|
||||||
|
) -> Option<(&EventId, &Receipt)> {
|
||||||
|
self.iter().find_map(|(event_id, receipts)| {
|
||||||
|
let receipt = receipts.get(&receipt_type)?.get(user_id)?;
|
||||||
|
Some((event_id.as_ref(), receipt))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Deref for ReceiptEventContent {
|
impl Deref for ReceiptEventContent {
|
||||||
type Target = BTreeMap<Box<EventId>, Receipts>;
|
type Target = BTreeMap<Box<EventId>, Receipts>;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user