1mod tests;
14
15use crate::{
19 error::Error,
20 messages::{IdType, Mode, MsgQuery},
21 services::Service,
22 users::{UserAuth, UserProfile, UserUpdate},
23 Identity,
24};
25use alexandria_tags::TagSet;
26use serde::{Deserialize, Serialize};
27
28pub const ADDRESS: &'static str = "org.qaul.libqaul";
29
30#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
32#[serde(tag = "context")]
33pub enum Capabilities {
34 #[serde(rename = "users")]
35 Users(UserCapabilities),
36 #[serde(rename = "services")]
37 Services(ServiceCapabilities),
38 #[serde(rename = "messages")]
39 Messages(MessageCapabilities),
40 #[serde(rename = "contacts")]
41 Contacts(ContactCapabilities),
42}
43
44impl Capabilities {
45 pub fn to_json(&self) -> String {
46 serde_json::to_string(self).expect("Invalid type: can't be made into json!")
47 }
48
49 pub fn from_json(s: &str) -> Option<Self> {
50 serde_json::from_str(s).ok()
51 }
52}
53
54#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
56#[serde(tag = "cmd", content = "data", rename_all = "kebab-case")]
57pub enum UserCapabilities {
58 List,
59 ListRemote,
60 IsAuthenticated { auth: UserAuth },
61 Create { pw: String },
62 Delete { auth: UserAuth },
63 ChangePw { auth: UserAuth, new_pw: String },
64 Login { id: Identity, pw: String },
65 Logout { auth: UserAuth },
66 Get { id: Identity },
67 Update { auth: UserAuth, update: UserUpdate },
68}
69
70#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
71#[serde(tag = "cmd", content = "data", rename_all = "kebab-case")]
72pub enum ServiceCapabilities {}
73
74#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
75#[serde(tag = "cmd", content = "data", rename_all = "kebab-case")]
76pub enum MessageCapabilities {
77 Send {
78 auth: UserAuth,
79 mode: Mode,
80 id_type: IdType,
81 service: Service,
82 tags: TagSet,
83 payload: Vec<u8>,
84 },
85 Subscribe {
86 auth: UserAuth,
87 service: Service,
88 tags: TagSet,
89 },
90 Query {
91 auth: UserAuth,
92 service: Service,
93 query: MsgQuery,
94 },
95}
96
97#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
98#[serde(tag = "cmd", content = "data", rename_all = "kebab-case")]
99pub enum ContactCapabilities {}
100
101#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
102#[serde(tag = "context")]
103pub enum Reply {
104 Users(UserReply),
105 Error(Error),
106}
107
108impl Reply {
109 pub fn to_json(&self) -> String {
110 serde_json::to_string(self).expect("Invalid type: can't be made into json!")
111 }
112
113 pub fn from_json(s: &str) -> Option<Self> {
114 serde_json::from_str(s).ok()
115 }
116}
117
118#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
119#[serde(tag = "type", content = "data", rename_all = "kebab-case")]
120pub enum UserReply {
121 List(Vec<UserProfile>),
122 Authenticated(bool),
123 Auth(UserAuth),
124 Ok,
125 Profile(UserProfile),
126}