use serde::Serialize;
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum ContactPresenceFilter {
Online,
Away,
Busy,
Invisible,
Offline,
}
impl TryFrom<jmap_chat_types::Presence> for ContactPresenceFilter {
type Error = ();
fn try_from(p: jmap_chat_types::Presence) -> Result<Self, ()> {
match p {
jmap_chat_types::Presence::Online => Ok(ContactPresenceFilter::Online),
jmap_chat_types::Presence::Away => Ok(ContactPresenceFilter::Away),
jmap_chat_types::Presence::Busy => Ok(ContactPresenceFilter::Busy),
jmap_chat_types::Presence::Invisible => Ok(ContactPresenceFilter::Invisible),
jmap_chat_types::Presence::Offline => Ok(ContactPresenceFilter::Offline),
_ => Err(()),
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum QuotaScope {
Account,
Domain,
Global,
Other(String),
}
impl QuotaScope {
pub fn as_str(&self) -> &str {
match self {
Self::Account => "account",
Self::Domain => "domain",
Self::Global => "global",
Self::Other(s) => s.as_str(),
}
}
}
impl std::fmt::Display for QuotaScope {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl serde::Serialize for QuotaScope {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for QuotaScope {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let raw = String::deserialize(d)?;
Ok(match raw.as_str() {
"account" => QuotaScope::Account,
"domain" => QuotaScope::Domain,
"global" => QuotaScope::Global,
_ => QuotaScope::Other(raw),
})
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub enum ChatMemberRole {
Admin,
Member,
Unknown(String),
}
impl ChatMemberRole {
pub fn as_str(&self) -> &str {
match self {
Self::Admin => "admin",
Self::Member => "member",
Self::Unknown(s) => s.as_str(),
}
}
}
impl std::fmt::Display for ChatMemberRole {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl serde::Serialize for ChatMemberRole {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for ChatMemberRole {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let raw = String::deserialize(d)?;
Ok(match raw.as_str() {
"admin" => ChatMemberRole::Admin,
"member" => ChatMemberRole::Member,
_ => ChatMemberRole::Unknown(raw),
})
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq)]
pub enum BodyType {
Plain,
Markdown,
Rich,
Unknown(String),
}
impl BodyType {
pub fn as_str(&self) -> &str {
match self {
Self::Plain => "text/plain",
Self::Markdown => "text/markdown",
Self::Rich => "application/jmap-chat-rich",
Self::Unknown(s) => s.as_str(),
}
}
}
impl std::fmt::Display for BodyType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
impl serde::Serialize for BodyType {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for BodyType {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let raw = String::deserialize(d)?;
Ok(match raw.as_str() {
"text/plain" => BodyType::Plain,
"text/markdown" => BodyType::Markdown,
"application/jmap-chat-rich" => BodyType::Rich,
_ => BodyType::Unknown(raw),
})
}
}