mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Export all conversations
This commit is contained in:
parent
30edf5f1a6
commit
df7aecc906
@ -1,9 +1,12 @@
|
||||
//! # Export account API entry
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::api_data::comment_api::CommentAPI;
|
||||
use crate::api_data::conversation_api::ConversationAPI;
|
||||
use crate::api_data::conversation_message_api::ConversationMessageAPI;
|
||||
use crate::api_data::movie_api::MovieAPI;
|
||||
use crate::api_data::post_api::PostAPI;
|
||||
@ -24,6 +27,8 @@ pub struct AccountExportAPI {
|
||||
survey_responses: Vec<SurveyResponseAPI>,
|
||||
movies: Vec<MovieAPI>,
|
||||
all_conversation_messages: Vec<ConversationMessageAPI>,
|
||||
conversations_list: Vec<ConversationAPI>,
|
||||
conversations_messages: HashMap<u64, Vec<ConversationMessageAPI>>,
|
||||
}
|
||||
|
||||
impl AccountExportAPI {
|
||||
@ -38,6 +43,11 @@ impl AccountExportAPI {
|
||||
survey_responses: SurveyResponseAPI::for_list(&export.survey_responses),
|
||||
movies: MovieAPI::for_list(&export.movies),
|
||||
all_conversation_messages: ConversationMessageAPI::for_list(&export.all_conversation_messages),
|
||||
conversations_list: ConversationAPI::for_list(&export.conversations),
|
||||
conversations_messages: export.conversation_messages
|
||||
.iter()
|
||||
.map(|r| (r.0.clone(), ConversationMessageAPI::for_list(r.1)))
|
||||
.collect(),
|
||||
};
|
||||
|
||||
Ok(export)
|
||||
|
@ -2,6 +2,7 @@
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
use serde::{Serialize, Serializer};
|
||||
|
||||
use crate::api_data::legacy_api_bool::LegacyBool;
|
||||
use crate::data::conversation::Conversation;
|
||||
|
||||
@ -35,7 +36,6 @@ pub struct ConversationAPI {
|
||||
}
|
||||
|
||||
impl ConversationAPI {
|
||||
|
||||
/// Construct a new Conversation instance
|
||||
pub fn new(conv: &Conversation) -> ConversationAPI {
|
||||
ConversationAPI {
|
||||
@ -51,7 +51,11 @@ impl ConversationAPI {
|
||||
// TODO : update when call system is implemented
|
||||
can_have_call: false,
|
||||
can_have_video_call: false,
|
||||
has_call_now: false
|
||||
has_call_now: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn for_list(l: &Vec<Conversation>) -> Vec<Self> {
|
||||
l.iter().map(Self::new).collect()
|
||||
}
|
||||
}
|
@ -2,7 +2,10 @@
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::data::comment::Comment;
|
||||
use crate::data::conversation::Conversation;
|
||||
use crate::data::conversation_message::ConversationMessage;
|
||||
use crate::data::movie::Movie;
|
||||
use crate::data::post::Post;
|
||||
@ -18,4 +21,6 @@ pub struct AccountExport {
|
||||
pub survey_responses: Vec<SurveyResponse>,
|
||||
pub movies: Vec<Movie>,
|
||||
pub all_conversation_messages: Vec<ConversationMessage>,
|
||||
pub conversations: Vec<Conversation>,
|
||||
pub conversation_messages: HashMap<u64, Vec<ConversationMessage>>,
|
||||
}
|
@ -193,7 +193,7 @@ pub fn update_last_activity(user_id: &UserID) -> ResultBoxError {
|
||||
|
||||
/// Export an account's data
|
||||
pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
|
||||
let data = AccountExport {
|
||||
let mut data = AccountExport {
|
||||
user: user_helper::find_user_by_id(user_id)?,
|
||||
posts: posts_helper::export_all_posts_user(user_id)?,
|
||||
comments: comments_helper::export_all_user(user_id)?,
|
||||
@ -201,9 +201,17 @@ pub fn export(user_id: &UserID) -> ResultBoxError<AccountExport> {
|
||||
survey_responses: survey_helper::export_all_user_responses(user_id)?,
|
||||
movies: movies_helper::get_list_user(user_id)?,
|
||||
all_conversation_messages: conversations_helper::export_all_user_messages(user_id)?,
|
||||
conversations: conversations_helper::get_list_user(user_id)?,
|
||||
conversation_messages: Default::default(),
|
||||
|
||||
//TODO : add other fields
|
||||
};
|
||||
|
||||
// Process conversation messages
|
||||
for conv in &data.conversations {
|
||||
data.conversation_messages
|
||||
.insert(conv.id, conversations_helper::get_all_messages(conv.id)?);
|
||||
}
|
||||
|
||||
Ok(data)
|
||||
}
|
Loading…
Reference in New Issue
Block a user