diff --git a/src/controllers/CommentsController.ts b/src/controllers/CommentsController.ts index f70432c..0706b9a 100644 --- a/src/controllers/CommentsController.ts +++ b/src/controllers/CommentsController.ts @@ -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 { - return { + public static async CommentToAPI(h: AbstractUserConnectionContainer, c: Comment, assumeNoLike: boolean = false) : Promise { + 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; } } \ No newline at end of file diff --git a/src/controllers/UserWebSocketActions.ts b/src/controllers/UserWebSocketActions.ts index 10311c7..9e5b472 100644 --- a/src/controllers/UserWebSocketActions.ts +++ b/src/controllers/UserWebSocketActions.ts @@ -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) })) }