1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 23:39:22 +00:00
comunicapiv3/src/data/account_export.rs

69 lines
2.1 KiB
Rust
Raw Normal View History

2020-07-13 17:12:39 +00:00
//! # Export of all account's data
//!
//! @author Pierre Hubert
2020-07-14 07:10:10 +00:00
use std::collections::{HashMap, HashSet};
2020-07-14 06:07:55 +00:00
2020-07-13 17:12:39 +00:00
use crate::data::comment::Comment;
2021-03-04 17:51:52 +00:00
use crate::data::conversation::{Conversation, ConvID};
2020-07-14 05:54:40 +00:00
use crate::data::conversation_message::ConversationMessage;
2020-07-14 07:10:10 +00:00
use crate::data::error::ResultBoxError;
2020-07-14 06:30:24 +00:00
use crate::data::friend::Friend;
use crate::data::group_id::GroupID;
2020-07-14 07:10:10 +00:00
use crate::data::post::{Post, PostPageKind};
2020-07-13 17:38:51 +00:00
use crate::data::survey_response::SurveyResponse;
2020-07-14 07:10:10 +00:00
use crate::data::user::{User, UserID};
2020-07-13 17:26:19 +00:00
use crate::data::user_like::UserLike;
2020-07-14 07:10:10 +00:00
use crate::helpers::comments_helper;
2020-07-13 17:12:39 +00:00
pub struct AccountExport {
pub user: User,
pub posts: Vec<Post>,
pub comments: Vec<Comment>,
2020-07-13 17:26:19 +00:00
pub likes: Vec<UserLike>,
2020-07-13 17:38:51 +00:00
pub survey_responses: Vec<SurveyResponse>,
2020-07-14 05:54:40 +00:00
pub all_conversation_messages: Vec<ConversationMessage>,
2020-07-14 06:07:55 +00:00
pub conversations: Vec<Conversation>,
2021-03-04 17:51:52 +00:00
pub conversation_messages: HashMap<ConvID, Vec<ConversationMessage>>,
2020-07-14 06:30:24 +00:00
pub friends_list: Vec<Friend>,
pub groups: Vec<GroupID>,
2020-07-14 07:10:10 +00:00
}
impl AccountExport {
/// Get the IDs of the related users
pub fn get_related_users_ids(&self) -> ResultBoxError<HashSet<UserID>> {
let mut set = HashSet::new();
// Own user
set.insert(self.user.id.clone());
// Friends
self.friends_list.iter().for_each(|f| { set.insert(f.friend_id.clone()); });
// Posts
for post in &self.posts {
set.insert(post.user_id.clone());
if let PostPageKind::PAGE_KIND_USER(id) = &post.target_page {
set.insert(id.clone());
}
comments_helper::get(post.id)?.iter().for_each(|f| { set.insert(f.user_id.clone()); })
}
// Comments
self.comments.iter().for_each(|f| { set.insert(f.user_id.clone()); });
// Conversation members
for conv in &self.conversations {
2021-03-04 17:51:52 +00:00
conv.members_ids().into_iter().for_each(|f| { set.insert(f); });
2020-07-14 07:10:10 +00:00
}
// Conversation messages
for (_, conv_messages) in &self.conversation_messages {
2021-03-02 17:57:34 +00:00
conv_messages.iter().for_each(|f| { set.extend(f.referenced_users_id()); })
2020-07-14 07:10:10 +00:00
}
Ok(set)
}
2020-07-13 17:12:39 +00:00
}