robespierre_models/
sync.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::id::{ChannelId, MessageId, UserId};
6
7/*
8Types
9*/
10
11// https://github.com/revoltchat/api/blob/094f8e650dbbbfd6a61be60d20943ea471a816c6/types/Sync.ts#L3-L5
12
13#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
14#[serde(transparent)]
15pub struct UserSettings(pub HashMap<String, SettingTuple>);
16
17// https://github.com/revoltchat/api/blob/094f8e650dbbbfd6a61be60d20943ea471a816c6/types/Sync.ts#L7-L10
18
19#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
20#[serde(deny_unknown_fields)]
21pub struct ChannelCompositeKey {
22    pub channel: ChannelId,
23    pub user: UserId,
24}
25
26// https://github.com/revoltchat/api/blob/094f8e650dbbbfd6a61be60d20943ea471a816c6/types/Sync.ts#L12-L17
27
28#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
29#[serde(deny_unknown_fields)]
30pub struct ChannelUnread {
31    #[serde(rename = "_id")]
32    pub id: ChannelCompositeKey,
33    pub last_id: MessageId,
34    #[serde(default, skip_serializing_if = "Vec::is_empty")]
35    pub mentions: Vec<MessageId>,
36}
37
38// https://github.com/revoltchat/api/blob/094f8e650dbbbfd6a61be60d20943ea471a816c6/types/Sync.ts#L19-L23
39
40#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
41#[serde(deny_unknown_fields)]
42pub struct WebPushSubscription {
43    pub endpoint: String,
44    pub p256dh: String,
45    pub auth: String,
46}
47
48/*
49Extra
50*/
51
52// https://github.com/revoltchat/api/blob/094f8e650dbbbfd6a61be60d20943ea471a816c6/types/Sync.ts#L4
53
54pub type SettingTuple = (usize, String);