From 5ff3e53489e64ef48b4d5e7e16cc39f6b5a1ac2f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 6 May 2020 13:26:39 +0200 Subject: [PATCH] Simplify response --- src/controllers/AccountController.ts | 2 +- src/controllers/FriendsController.ts | 22 ++++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index f250d83..f8f8a9e 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -281,7 +281,7 @@ export class AccountController { conversations_messages: {}, // Friends list - friends_list: data.friendsList.map(f => FriendsController.FriendToAPI(f, false)), + friends_list: data.friendsList.map(f => FriendsController.FriendToAPI(f)), // Groups membership groups: await Promise.all((await Promise.all(data.groups.map(id => GroupsHelper.GetInfo(id)))) diff --git a/src/controllers/FriendsController.ts b/src/controllers/FriendsController.ts index fcd062a..170ffa7 100644 --- a/src/controllers/FriendsController.ts +++ b/src/controllers/FriendsController.ts @@ -22,14 +22,14 @@ export class FriendsController { * @param h Request handler */ public static async GetList(h: RequestHandler) { - const returnAllInfo = h.postBool("complete", false); + //const returnAllInfo = h.postBool("complete", false); const list = await FriendsHelper.GetList(h.getUserId()); // Update user activity (if allowed) if(!h.postBool("incognito", false)) await AccountHelper.UpdateLastActivity(h.getUserId()) - h.send(list.map((f) => this.FriendToAPI(f, returnAllInfo))); + h.send(list.map((f) => this.FriendToAPI(f))); } /** @@ -64,7 +64,7 @@ export class FriendsController { if(info == null) h.error(404, "Requested frienship not found!"); - h.send(this.FriendToAPI(info, true)); + h.send(this.FriendToAPI(info)); } /** @@ -213,24 +213,18 @@ export class FriendsController { * Turn a friend object into an API entry * * @param friend Friend object to transform - * @param full Set to true to return all information */ - public static FriendToAPI(friend: Friend, full: boolean = false) : any { - let info: any = { + public static FriendToAPI(friend: Friend) : any { + return { ID_friend: friend.friendID, accepted: friend.accepted ? 1 : 0, time_last_activity: UserWebSocketController.IsConnected(friend.friendID) && !UserWebSocketController.IsIcognito(friend.friendID) - ? time() : friend.lastActivityTime + ? time() : friend.lastActivityTime, + following: friend.following ? 1 : 0, + canPostTexts: friend.canPostTexts, } - - if(full) { - info.following = friend.following ? 1 : 0 - info.canPostTexts = friend.canPostTexts - } - - return info; } } \ No newline at end of file