mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 08:25:16 +00:00
Continue refactoring
This commit is contained in:
@ -53,7 +53,7 @@ impl AccountExportAPI {
|
||||
conversations_list: ConversationAPI::for_list(&export.conversations),
|
||||
conversations_messages: export.conversation_messages
|
||||
.iter()
|
||||
.map(|r| (r.0.clone(), ConversationMessageAPI::for_list(r.1)))
|
||||
.map(|r| (r.0.id(), ConversationMessageAPI::for_list(r.1)))
|
||||
.collect(),
|
||||
friends_list: FriendAPI::from_list(&export.friends_list),
|
||||
groups: export.groups
|
||||
|
@ -17,7 +17,7 @@ pub struct CallPeerInterruptedStreamingAPI {
|
||||
impl CallPeerInterruptedStreamingAPI {
|
||||
pub fn new(call_id: &ConvID, peer_id: &UserID) -> Self {
|
||||
Self {
|
||||
callID: call_id.clone(),
|
||||
callID: call_id.id(),
|
||||
peerID: peer_id.id(),
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ pub struct CallPeerReadyAPI {
|
||||
impl CallPeerReadyAPI {
|
||||
pub fn new(call_id: &ConvID, user_id: &UserID) -> Self {
|
||||
Self {
|
||||
callID: call_id.clone(),
|
||||
callID: call_id.id(),
|
||||
peerID: user_id.id(),
|
||||
}
|
||||
}
|
||||
|
@ -1,54 +1,58 @@
|
||||
//! # Conversation API object
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
use serde::{Serialize, Serializer};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::api_data::legacy_api_bool::LegacyBool;
|
||||
use crate::controllers::calls_controller;
|
||||
use crate::data::conversation::Conversation;
|
||||
use crate::data::conversation::{Conversation, ConversationMember};
|
||||
use crate::helpers::calls_helper;
|
||||
|
||||
/// 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)]
|
||||
struct ConversationMembersAPI {
|
||||
user_id: u64,
|
||||
last_message_seen: u64,
|
||||
following: bool,
|
||||
is_admin: bool,
|
||||
}
|
||||
|
||||
#[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,
|
||||
id: u64,
|
||||
last_activity: u64,
|
||||
name: Option<String>,
|
||||
color: Option<String>,
|
||||
background: Option<String>,
|
||||
group_id: Option<u64>,
|
||||
members: Vec<ConversationMembersAPI>,
|
||||
can_everyone_add_members: bool,
|
||||
can_have_call: bool,
|
||||
can_have_video_call: bool,
|
||||
has_call_now: bool,
|
||||
}
|
||||
|
||||
impl ConversationMembersAPI {
|
||||
pub fn new(m: &ConversationMember) -> Self {
|
||||
Self {
|
||||
user_id: m.user_id.id(),
|
||||
last_message_seen: m.last_message_seen,
|
||||
following: m.following,
|
||||
is_admin: m.is_admin,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ConversationAPI {
|
||||
/// Construct a new Conversation instance
|
||||
pub fn new(conv: &Conversation) -> ConversationAPI {
|
||||
ConversationAPI {
|
||||
ID: conv.id,
|
||||
ID_owner: conv.owner_id.id(),
|
||||
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.id()).collect(),
|
||||
canEveryoneAddMembers: conv.can_everyone_add_members,
|
||||
id: conv.id.id(),
|
||||
last_activity: conv.last_activity,
|
||||
name: conv.name.clone(),
|
||||
members: conv.members.iter().map(ConversationMembersAPI::new).collect(),
|
||||
can_everyone_add_members: conv.can_everyone_add_members,
|
||||
color: conv.color.clone(),
|
||||
background: conv.background.clone(),
|
||||
group_id: conv.group_id.as_ref().map(|i| i.id()),
|
||||
|
||||
can_have_call: calls_helper::can_have_call(conv),
|
||||
can_have_video_call: calls_helper::can_have_video_calls(conv),
|
||||
|
@ -79,7 +79,7 @@ impl ConversationMessageAPI {
|
||||
|
||||
ConversationMessageAPI {
|
||||
id: msg.id,
|
||||
conv_id: msg.conv_id,
|
||||
conv_id: msg.conv_id.id(),
|
||||
user_id: msg.user_id.clone().map(|u| u.id()),
|
||||
time_insert: msg.time_sent,
|
||||
message: msg.message.clone(),
|
||||
|
@ -1,37 +0,0 @@
|
||||
//! # Conversation refresh result
|
||||
//!
|
||||
//! Note : this structure is now deprecated and should no longer be used for further developments
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::api_data::conversation_message_api::ConversationMessageAPI;
|
||||
use crate::data::conversation_message::ConversationMessage;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
pub struct ConversationRefreshResultAPI {
|
||||
#[serde(flatten)]
|
||||
list: HashMap<String, Vec<ConversationMessageAPI>>,
|
||||
}
|
||||
|
||||
impl ConversationRefreshResultAPI {
|
||||
/// Create a new list
|
||||
pub fn new(list: HashMap<u64, Vec<ConversationMessage>>) -> ConversationRefreshResultAPI {
|
||||
let list = list
|
||||
.iter()
|
||||
.map(|v| (
|
||||
format!("conversation-{}", v.0),
|
||||
ConversationMessageAPI::for_list(v.1)
|
||||
))
|
||||
.collect();
|
||||
|
||||
ConversationRefreshResultAPI {
|
||||
list
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ pub struct JoinedCallMessage {
|
||||
impl JoinedCallMessage {
|
||||
pub fn new(call_id: &ConvID, user_id: &UserID) -> Self {
|
||||
Self {
|
||||
callID: call_id.clone(),
|
||||
callID: call_id.id(),
|
||||
userID: user_id.id(),
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ pub struct LeftCallMessage {
|
||||
impl LeftCallMessage {
|
||||
pub fn new(call_id: &ConvID, user_id: &UserID) -> Self {
|
||||
Self {
|
||||
callID: call_id.clone(),
|
||||
callID: call_id.id(),
|
||||
userID: user_id.id(),
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ pub mod conversation_api;
|
||||
mod legacy_api_bool;
|
||||
pub mod res_find_private_conversations;
|
||||
pub mod conversation_message_api;
|
||||
pub mod conversations_refresh_api;
|
||||
pub mod res_count_unread_conversations;
|
||||
pub mod list_unread_conversations_api;
|
||||
pub mod global_search_result_api;
|
||||
|
@ -19,7 +19,7 @@ pub struct NewCallSignalAPI {
|
||||
impl NewCallSignalAPI {
|
||||
pub fn new(call_id: &ConvID, peer_id: &UserID, data: &str) -> Res<Self> {
|
||||
Ok(Self {
|
||||
callID: call_id.clone(),
|
||||
callID: call_id.id(),
|
||||
peerID: peer_id.id(),
|
||||
data: serde_json::from_str(data)?,
|
||||
})
|
||||
|
@ -3,6 +3,7 @@
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use serde::{Serialize};
|
||||
use crate::data::conversation::ConvID;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
@ -13,9 +14,9 @@ pub struct ResCreateConversation {
|
||||
|
||||
impl ResCreateConversation {
|
||||
/// Construct a new Result instance
|
||||
pub fn new(conv_id: u64) -> ResCreateConversation {
|
||||
pub fn new(conv_id: ConvID) -> ResCreateConversation {
|
||||
ResCreateConversation {
|
||||
conversationID: conv_id,
|
||||
conversationID: conv_id.id(),
|
||||
success: "The conversation was successfully created!".to_string(),
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::data::conversation::ConvID;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
pub struct ResFindPrivateConversations {
|
||||
@ -12,9 +14,9 @@ pub struct ResFindPrivateConversations {
|
||||
|
||||
impl ResFindPrivateConversations {
|
||||
/// Construct a new instance of this structure
|
||||
pub fn new(list: Vec<u64>) -> ResFindPrivateConversations {
|
||||
pub fn new(list: Vec<ConvID>) -> ResFindPrivateConversations {
|
||||
ResFindPrivateConversations {
|
||||
conversationsID: list
|
||||
conversationsID: list.iter().map(|i| i.id()).collect()
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user