mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 16:35:17 +00:00
Get the list of conversations of the user
This commit is contained in:
57
src/api_data/conversation_api.rs
Normal file
57
src/api_data/conversation_api.rs
Normal file
@ -0,0 +1,57 @@
|
||||
//! # 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
|
||||
}
|
||||
}
|
||||
}
|
20
src/api_data/legacy_api_bool.rs
Normal file
20
src/api_data/legacy_api_bool.rs
Normal file
@ -0,0 +1,20 @@
|
||||
//! # Legacy API boolean
|
||||
//!
|
||||
//! true => 1
|
||||
//! false => 0
|
||||
|
||||
|
||||
use serde::{Serialize, Serializer};
|
||||
|
||||
/// Special implementation of conversation name (false if none / the name otherwise)
|
||||
pub struct LegacyBool(pub bool);
|
||||
|
||||
impl Serialize for LegacyBool {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
|
||||
S: Serializer {
|
||||
match &self.0 {
|
||||
true => serializer.serialize_i8(1),
|
||||
false => serializer.serialize_i8(0),
|
||||
}
|
||||
}
|
||||
}
|
@ -14,4 +14,6 @@ pub mod user_info;
|
||||
pub mod custom_emoji;
|
||||
pub mod res_find_user_by_virtual_directory;
|
||||
pub mod res_find_virtual_directory;
|
||||
pub mod res_create_conversation;
|
||||
pub mod res_create_conversation;
|
||||
pub mod conversation_api;
|
||||
mod legacy_api_bool;
|
Reference in New Issue
Block a user