mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-24 22:39:21 +00:00
Optimize request
This commit is contained in:
parent
4ec84dfc06
commit
500137c031
@ -145,9 +145,10 @@ export class CommentsController {
|
||||
*
|
||||
* @param h Request handler
|
||||
* @param c Comment
|
||||
* @param assumeNoLike Assume there are not any likes on this comment (false by default)
|
||||
*/
|
||||
public static async CommentToAPI(h: AbstractUserConnectionContainer, c: Comment) : Promise<any> {
|
||||
return {
|
||||
public static async CommentToAPI(h: AbstractUserConnectionContainer, c: Comment, assumeNoLike: boolean = false) : Promise<any> {
|
||||
const data = {
|
||||
ID: c.id,
|
||||
userID: c.userID,
|
||||
postID: c.postID,
|
||||
@ -155,9 +156,17 @@ export class CommentsController {
|
||||
content: c.content,
|
||||
img_path: c.hasImage ? c.imagePath : null,
|
||||
img_url: c.hasImage ? c.imageURL : null,
|
||||
likes: await LikesHelper.Count(c.id, LikesType.COMMENT),
|
||||
userlike: h.signedIn ? await LikesHelper.IsLiking(h.getUserId(), c.id, LikesType.COMMENT) : false
|
||||
likes: 0,
|
||||
userlike: false
|
||||
}
|
||||
|
||||
// Check if we have to load like information
|
||||
if(!assumeNoLike) {
|
||||
data.likes = await LikesHelper.Count(c.id, LikesType.COMMENT);
|
||||
data.userlike = h.signedIn ? await LikesHelper.IsLiking(h.getUserId(), c.id, LikesType.COMMENT) : false;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
@ -148,7 +148,7 @@ export class UserWebSocketActions {
|
||||
UserWebSocketController.SendToClient(client, new WsMessage({
|
||||
id: "",
|
||||
title: "new_comment",
|
||||
data: await CommentsController.CommentToAPI(new AbritraryUserConnection(client.userID), c)
|
||||
data: await CommentsController.CommentToAPI(new AbritraryUserConnection(client.userID), c, true)
|
||||
}))
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user