jmap_chat_client/
types.rs1use serde::Serialize;
7
8#[non_exhaustive]
20#[derive(Debug, Clone, PartialEq, Serialize)]
21#[serde(rename_all = "lowercase")]
22pub enum ContactPresenceFilter {
23 Online,
25 Away,
27 Busy,
29 Invisible,
31 Offline,
33}
34
35impl TryFrom<jmap_chat_types::Presence> for ContactPresenceFilter {
36 type Error = ();
38 fn try_from(p: jmap_chat_types::Presence) -> Result<Self, ()> {
39 match p {
40 jmap_chat_types::Presence::Online => Ok(ContactPresenceFilter::Online),
41 jmap_chat_types::Presence::Away => Ok(ContactPresenceFilter::Away),
42 jmap_chat_types::Presence::Busy => Ok(ContactPresenceFilter::Busy),
43 jmap_chat_types::Presence::Invisible => Ok(ContactPresenceFilter::Invisible),
44 jmap_chat_types::Presence::Offline => Ok(ContactPresenceFilter::Offline),
45 _ => Err(()),
46 }
47 }
48}
49
50#[non_exhaustive]
59#[derive(Debug, Clone, PartialEq, Eq)]
60pub enum QuotaScope {
61 Account,
63 Domain,
65 Global,
67 Other(String),
70}
71
72impl QuotaScope {
73 pub fn as_str(&self) -> &str {
75 match self {
76 Self::Account => "account",
77 Self::Domain => "domain",
78 Self::Global => "global",
79 Self::Other(s) => s.as_str(),
80 }
81 }
82}
83
84impl std::fmt::Display for QuotaScope {
85 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86 f.write_str(self.as_str())
87 }
88}
89
90impl serde::Serialize for QuotaScope {
91 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
92 s.serialize_str(self.as_str())
93 }
94}
95
96impl<'de> serde::Deserialize<'de> for QuotaScope {
97 fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
98 let raw = String::deserialize(d)?;
99 Ok(match raw.as_str() {
100 "account" => QuotaScope::Account,
101 "domain" => QuotaScope::Domain,
102 "global" => QuotaScope::Global,
103 _ => QuotaScope::Other(raw),
104 })
105 }
106}
107
108#[non_exhaustive]
119#[derive(Debug, Clone, PartialEq)]
120pub enum ChatMemberRole {
121 Admin,
123 Member,
125 Unknown(String),
127}
128
129impl ChatMemberRole {
130 pub fn as_str(&self) -> &str {
132 match self {
133 Self::Admin => "admin",
134 Self::Member => "member",
135 Self::Unknown(s) => s.as_str(),
136 }
137 }
138}
139
140impl std::fmt::Display for ChatMemberRole {
141 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
142 f.write_str(self.as_str())
143 }
144}
145
146impl serde::Serialize for ChatMemberRole {
147 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
148 s.serialize_str(self.as_str())
149 }
150}
151
152impl<'de> serde::Deserialize<'de> for ChatMemberRole {
153 fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
154 let raw = String::deserialize(d)?;
155 Ok(match raw.as_str() {
156 "admin" => ChatMemberRole::Admin,
157 "member" => ChatMemberRole::Member,
158 _ => ChatMemberRole::Unknown(raw),
159 })
160 }
161}
162
163#[non_exhaustive]
174#[derive(Debug, Clone, PartialEq)]
175pub enum BodyType {
176 Plain,
178 Markdown,
180 Rich,
182 Unknown(String),
184}
185
186impl BodyType {
187 pub fn as_str(&self) -> &str {
189 match self {
190 Self::Plain => "text/plain",
191 Self::Markdown => "text/markdown",
192 Self::Rich => "application/jmap-chat-rich",
193 Self::Unknown(s) => s.as_str(),
194 }
195 }
196}
197
198impl std::fmt::Display for BodyType {
199 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
200 f.write_str(self.as_str())
201 }
202}
203
204impl serde::Serialize for BodyType {
205 fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
206 s.serialize_str(self.as_str())
207 }
208}
209
210impl<'de> serde::Deserialize<'de> for BodyType {
211 fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
212 let raw = String::deserialize(d)?;
213 Ok(match raw.as_str() {
214 "text/plain" => BodyType::Plain,
215 "text/markdown" => BodyType::Markdown,
216 "application/jmap-chat-rich" => BodyType::Rich,
217 _ => BodyType::Unknown(raw),
218 })
219 }
220}