aboutsummaryrefslogtreecommitdiffstats
path: root/src/xchan.rs
blob: e4f68933c1125097038a6253687e476d4554a6af (plain) (blame)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// zotapi - Rust wrapper for Sot API as implemented by Hubzilla
// Copyright (C) 2018  Harald Eilertsen <haraldei@anduin.net>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

use crate::{error::Error};
use serde::Deserialize;
use std::convert::TryFrom;

#[derive(Debug, Default, Deserialize)]
pub struct XChan {
    #[serde(alias = "xchan_hash")]
    pub hash: String,

    #[serde(alias = "xchan_guid")]
    pub guid: String,

    #[serde(alias = "xchan_guid_sig")]
    pub guid_sig: String,

    #[serde(alias = "xchan_pubkey")]
    pub pubkey: String,

    #[serde(alias = "xchan_photo_mimetype")]
    pub photo_mimetype: String,

    #[serde(alias = "xchan_photo_l")]
    pub photo_l: String,

    #[serde(alias = "xchan_photo_m")]
    pub photo_m: String,

    #[serde(alias = "xchan_photo_s")]
    pub photo_s: String,

    // For some reason the address field will be exported as `addr`
    // when part of an aboox entry, but `address` when just exporting
    // the xchan. `addr` is the name used in the database table.

    #[serde(alias = "xchan_addr")]
    pub address: String,

    #[serde(alias = "xchan_url")]
    pub url: String,

    #[serde(alias = "xchan_connurl")]
    pub connurl: String,

    #[serde(alias = "xchan_follow")]
    pub follow: String,

    #[serde(alias = "xchan_connpage")]
    pub connpage: String,

    #[serde(alias = "xchan_name")]
    pub name: String,

    #[serde(alias = "xchan_network")]
    pub network: String,

    #[serde(alias = "xchan_instance_url")]
    pub instance_url: String,

    #[serde(alias = "xchan_flags")]
    pub flags: u32,

    #[serde(alias = "xchan_photo_date")]
    pub photo_date: String,

    #[serde(alias = "xchan_name_date")]
    pub name_date: String,

    #[serde(alias = "xchan_hidden")]
    pub hidden: u32,

    #[serde(alias = "xchan_orphan")]
    pub orphan: u32,

    #[serde(alias = "xchan_censored")]
    pub censored: u32,

    #[serde(alias = "xchan_selfcensored")]
    pub selfcensored: u32,

    #[serde(alias = "xchan_system")]
    pub system: u32,

    #[serde(alias = "xchan_pubforum")]
    pub pubforum: u32,

    #[serde(alias = "deleted", default)]
    pub deleted: u32,
}

impl<'a> TryFrom<&'a str> for XChan {
    type Error = Error;

    fn try_from(s: &'a str) -> Result<Self, Self::Error> {
        Ok(serde_json::from_str(s)?)
    }
}