1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 05:19:22 +00:00

Export information about related users

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

View File

@ -231,7 +231,7 @@ export class AccountController {
// Query the database
const data = await AccountHelper.Export(h.getUserId());
const out: any = {
const out = {
userID: data.userID,
// General account information
@ -262,7 +262,10 @@ export class AccountController {
conversation_messages: {},
// Friends list
friends_list: data.friendsList.map(f => FriendsController.FriendToAPI(f, false))
friends_list: data.friendsList.map(f => FriendsController.FriendToAPI(f, false)),
// Related users info
users_info: new Map<number, any>(),
};
// Fill conversation messages entry
@ -272,7 +275,10 @@ export class AccountController {
}
// TODO : continue (additional user info)
// Load related users info
for(const id of await data.getRelatedUsersID()) {
out.users_info[id] = await UserController.UserToAPI(await UserHelper.GetUserInfo(id), h, false);
}
h.send(out);

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;
}
}

View File

@ -419,7 +419,9 @@ export class AccountHelper {
conversationsMessages: new Map(),
// Friends
friendsList: await FriendsHelper.GetList(userID)
friendsList: await FriendsHelper.GetList(userID),
// TODO : add groups list
})
// Process conversation messages
@ -428,9 +430,6 @@ export class AccountHelper {
= await ConversationsHelper.GetAllMessages(conv.id);
}
// TODO : continue
return data;
}
}