push/internal/storage/
record.rs1use rusqlite::Row;
6
7use crate::error::Result;
8use crate::internal::crypto::KeyV1 as Key;
9
10use types::Timestamp;
11
12pub type ChannelID = String;
13
14#[derive(Clone, Debug, PartialEq, Eq)]
15pub struct PushRecord {
16 pub channel_id: ChannelID,
18
19 pub endpoint: String,
21
22 pub scope: String,
24
25 pub key: Vec<u8>,
27
28 pub ctime: Timestamp,
30
31 pub app_server_key: Option<String>,
34}
35
36impl PushRecord {
37 pub fn new(chid: &str, endpoint: &str, scope: &str, key: Key) -> Result<Self> {
40 Ok(Self {
41 channel_id: chid.to_owned(),
42 endpoint: endpoint.to_owned(),
43 scope: scope.to_owned(),
44 key: key.serialize()?,
45 ctime: Timestamp::now(),
46 app_server_key: None,
47 })
48 }
49
50 pub(crate) fn from_row(row: &Row<'_>) -> Result<Self> {
51 Ok(PushRecord {
52 channel_id: row.get("channel_id")?,
53 endpoint: row.get("endpoint")?,
54 scope: row.get("scope")?,
55 key: row.get("key")?,
56 ctime: row.get("ctime")?,
57 app_server_key: row.get("app_server_key")?,
58 })
59 }
60}