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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use rusqlite::Row;
use crate::crypto::KeyV1 as Key;
use crate::error::Result;
use super::types::Timestamp;
pub type ChannelID = String;
#[derive(Clone, Debug, PartialEq)]
pub struct MetaRecord {
pub key: String,
pub val: String,
}
#[derive(Clone, Debug, PartialEq)]
pub struct PushRecord {
pub uaid: String,
pub channel_id: ChannelID,
pub endpoint: String,
pub scope: String,
pub key: Vec<u8>,
pub ctime: Timestamp,
pub app_server_key: Option<String>,
pub native_id: Option<String>,
}
impl PushRecord {
pub fn new(uaid: &str, chid: &str, endpoint: &str, scope: &str, key: Key) -> Self {
Self {
uaid: uaid.to_owned(),
channel_id: chid.to_owned(),
endpoint: endpoint.to_owned(),
scope: scope.to_owned(),
key: key.serialize().unwrap(),
ctime: Timestamp::now(),
app_server_key: None,
native_id: None,
}
}
pub(crate) fn from_row(row: &Row<'_>) -> Result<Self> {
Ok(PushRecord {
uaid: row.get("uaid")?,
channel_id: row.get("channel_id")?,
endpoint: row.get("endpoint")?,
scope: row.get("scope")?,
key: row.get("key")?,
ctime: row.get("ctime")?,
app_server_key: row.get("app_server_key")?,
native_id: row.get("native_id")?,
})
}
}