arminius_lib_model/
read_receipts.rs1use std::collections::BTreeMap;
8
9use arminius_lib_component::error::FeatureNotImplemented;
10use ruma::{
11 OwnedEventId, OwnedRoomId, OwnedUserId,
12 events::receipt::{Receipt, ReceiptType},
13};
14
15pub type SyncReceiptsMap = BTreeMap<
17 OwnedRoomId,
18 BTreeMap<OwnedEventId, BTreeMap<ReceiptType, BTreeMap<OwnedUserId, Receipt>>>,
19>;
20
21#[derive(Debug, sqlx::Type, PartialEq, Eq, Hash)]
27#[sqlx(type_name = "RECEIPT_TYPE")]
28pub enum DbReceiptType {
29 #[sqlx(rename = "m.read")]
31 Read,
32 #[sqlx(rename = "m.read.private")]
34 ReadPrivate,
35}
36
37impl AsRef<str> for DbReceiptType {
39 fn as_ref(&self) -> &str {
40 match self {
41 DbReceiptType::Read => "m.read",
42 DbReceiptType::ReadPrivate => "m.read.private",
43 }
44 }
45}
46
47impl TryFrom<ReceiptType> for DbReceiptType {
51 type Error = FeatureNotImplemented;
52
53 fn try_from(receipt_type: ReceiptType) -> Result<Self, Self::Error> {
54 match receipt_type {
55 ReceiptType::Read => Ok(DbReceiptType::Read),
56 ReceiptType::ReadPrivate => Ok(DbReceiptType::ReadPrivate),
57 custom => Err(FeatureNotImplemented(format!(
58 "This server does not support '{custom}' custom read receipts"
59 ))),
60 }
61 }
62}
63
64impl From<DbReceiptType> for ReceiptType {
66 fn from(db_receipt_type: DbReceiptType) -> Self {
67 ReceiptType::from(db_receipt_type.as_ref())
68 }
69}