1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-24 22:39:21 +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: {},
// 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))))

View File

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