1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use crate::id::{ChannelId, MessageId, UserId};

/*
Types
*/

// https://github.com/revoltchat/api/blob/094f8e650dbbbfd6a61be60d20943ea471a816c6/types/Sync.ts#L3-L5

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
#[serde(transparent)]
pub struct UserSettings(pub HashMap<String, SettingTuple>);

// https://github.com/revoltchat/api/blob/094f8e650dbbbfd6a61be60d20943ea471a816c6/types/Sync.ts#L7-L10

#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[serde(deny_unknown_fields)]
pub struct ChannelCompositeKey {
    pub channel: ChannelId,
    pub user: UserId,
}

// https://github.com/revoltchat/api/blob/094f8e650dbbbfd6a61be60d20943ea471a816c6/types/Sync.ts#L12-L17

#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[serde(deny_unknown_fields)]
pub struct ChannelUnread {
    #[serde(rename = "_id")]
    pub id: ChannelCompositeKey,
    pub last_id: MessageId,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub mentions: Vec<MessageId>,
}

// https://github.com/revoltchat/api/blob/094f8e650dbbbfd6a61be60d20943ea471a816c6/types/Sync.ts#L19-L23

#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[serde(deny_unknown_fields)]
pub struct WebPushSubscription {
    pub endpoint: String,
    pub p256dh: String,
    pub auth: String,
}

/*
Extra
*/

// https://github.com/revoltchat/api/blob/094f8e650dbbbfd6a61be60d20943ea471a816c6/types/Sync.ts#L4

pub type SettingTuple = (usize, String);