1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 16:45:16 +00:00

Export information about related users

This commit is contained in:
2020-03-26 13:44:57 +01:00
parent aef43df39e
commit dc79c42949
3 changed files with 46 additions and 7 deletions

View File

@ -13,6 +13,7 @@ import { Movie } from "./Movie";
import { ConversationMessage } from "./ConversationMessage";
import { Conversation } from "./Conversation";
import { Friend } from "./Friend";
import { CommentsHelper } from "../helpers/CommentsHelper";
export interface AccountExportBuilder {
userID: number;
@ -47,4 +48,37 @@ export class AccountExport implements AccountExportBuilder {
this[key] = info[key];
}
}
/**
* Get the ID of all the related users
*/
public async getRelatedUsersID() : Promise<Set<number>> {
const set = new Set<number>();
// Own user
set.add(this.userID);
// Friends
this.friendsList.forEach(f => set.add(f.friendID))
// Posts
for(const p of this.postsList) {
set.add(p.userID);
if(p.isUserPage) set.add(p.userPageID);
// Process post comments
(await CommentsHelper.Get(p.id)).forEach(c => set.add(c.userID))
}
// Comments
this.comments.forEach(c => set.add(c.userID))
// Conversation members
this.conversations.forEach(c => c.members.forEach(id => set.add(id)))
// Conversations messages
this.conversationsMessages.forEach(c => c.forEach(m => set.add(m.userID)))
return set;
}
}