//! # Export of all account's data //! //! @author Pierre Hubert use std::collections::{HashMap, HashSet}; use crate::data::comment::Comment; use crate::data::conversation::Conversation; use crate::data::conversation_message::ConversationMessage; use crate::data::error::ResultBoxError; use crate::data::friend::Friend; use crate::data::group_id::GroupID; use crate::data::post::{Post, PostPageKind}; use crate::data::survey_response::SurveyResponse; use crate::data::user::{User, UserID}; use crate::data::user_like::UserLike; use crate::helpers::comments_helper; pub struct AccountExport { pub user: User, pub posts: Vec, pub comments: Vec, pub likes: Vec, pub survey_responses: Vec, pub all_conversation_messages: Vec, pub conversations: Vec, pub conversation_messages: HashMap>, pub friends_list: Vec, pub groups: Vec, } impl AccountExport { /// Get the IDs of the related users pub fn get_related_users_ids(&self) -> ResultBoxError> { 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 { conv.members.iter().for_each(|f| { set.insert(f.clone()); }); } // Conversation messages for (_, conv_messages) in &self.conversation_messages { conv_messages.iter().for_each(|f| { set.insert(f.user_id.clone()); }) } Ok(set) } }