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

Simplify response

This commit is contained in:
Pierre HUBERT 2020-05-06 13:26:39 +02:00
parent f01c121bd4
commit 5ff3e53489
2 changed files with 9 additions and 15 deletions

View File

@ -281,7 +281,7 @@ export class AccountController {
conversations_messages: {}, conversations_messages: {},
// Friends list // Friends list
friends_list: data.friendsList.map(f => FriendsController.FriendToAPI(f, false)), friends_list: data.friendsList.map(f => FriendsController.FriendToAPI(f)),
// Groups membership // Groups membership
groups: await Promise.all((await Promise.all(data.groups.map(id => GroupsHelper.GetInfo(id)))) groups: await Promise.all((await Promise.all(data.groups.map(id => GroupsHelper.GetInfo(id))))

View File

@ -22,14 +22,14 @@ export class FriendsController {
* @param h Request handler * @param h Request handler
*/ */
public static async GetList(h: RequestHandler) { 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()); const list = await FriendsHelper.GetList(h.getUserId());
// Update user activity (if allowed) // Update user activity (if allowed)
if(!h.postBool("incognito", false)) if(!h.postBool("incognito", false))
await AccountHelper.UpdateLastActivity(h.getUserId()) 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) if(info == null)
h.error(404, "Requested frienship not found!"); 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 * Turn a friend object into an API entry
* *
* @param friend Friend object to transform * @param friend Friend object to transform
* @param full Set to true to return all information
*/ */
public static FriendToAPI(friend: Friend, full: boolean = false) : any { public static FriendToAPI(friend: Friend) : any {
let info: any = { return {
ID_friend: friend.friendID, ID_friend: friend.friendID,
accepted: friend.accepted ? 1 : 0, accepted: friend.accepted ? 1 : 0,
time_last_activity: time_last_activity:
UserWebSocketController.IsConnected(friend.friendID) && UserWebSocketController.IsConnected(friend.friendID) &&
!UserWebSocketController.IsIcognito(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;
} }
} }