mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-02-07 09:47:04 +00:00
57 lines
1.7 KiB
Rust
57 lines
1.7 KiB
Rust
|
//! # Conversation API object
|
||
|
//!
|
||
|
//! @author Pierre Hubert
|
||
|
use serde::{Serialize, Serializer};
|
||
|
use crate::api_data::legacy_api_bool::LegacyBool;
|
||
|
use crate::data::conversation::Conversation;
|
||
|
|
||
|
/// Special implementation of conversation name (false if none / the name otherwise)
|
||
|
struct ConvName(Option<String>);
|
||
|
|
||
|
impl Serialize for ConvName {
|
||
|
fn serialize<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
|
||
|
S: Serializer {
|
||
|
match &self.0 {
|
||
|
None => serializer.serialize_bool(false),
|
||
|
Some(n) => serializer.serialize_str(n)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[derive(Serialize)]
|
||
|
#[allow(non_snake_case)]
|
||
|
pub struct ConversationAPI {
|
||
|
ID: u64,
|
||
|
ID_owner: u64,
|
||
|
last_active: u64,
|
||
|
name: ConvName,
|
||
|
following: LegacyBool,
|
||
|
saw_last_message: LegacyBool,
|
||
|
members: Vec<u64>,
|
||
|
canEveryoneAddMembers: bool,
|
||
|
can_have_call: bool,
|
||
|
can_have_video_call: bool,
|
||
|
has_call_now: bool,
|
||
|
}
|
||
|
|
||
|
impl ConversationAPI {
|
||
|
|
||
|
/// Construct a new Conversation instance
|
||
|
pub fn new(conv: &Conversation) -> ConversationAPI {
|
||
|
ConversationAPI {
|
||
|
ID: conv.id,
|
||
|
ID_owner: conv.owner_id as u64,
|
||
|
last_active: conv.last_active,
|
||
|
name: ConvName(conv.name.clone()),
|
||
|
following: LegacyBool(conv.following),
|
||
|
saw_last_message: LegacyBool(conv.saw_last_message),
|
||
|
members: conv.members.iter().map(|x| x.clone() as u64).collect(),
|
||
|
canEveryoneAddMembers: conv.can_everyone_add_members,
|
||
|
|
||
|
// TODO : update when call system is implemented
|
||
|
can_have_call: false,
|
||
|
can_have_video_call: false,
|
||
|
has_call_now: false
|
||
|
}
|
||
|
}
|
||
|
}
|