mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 03:24:04 +00:00 
			
		
		
		
	Optimize request
This commit is contained in:
		@@ -145,9 +145,10 @@ export class CommentsController {
 | 
				
			|||||||
	 * 
 | 
						 * 
 | 
				
			||||||
	 * @param h Request handler
 | 
						 * @param h Request handler
 | 
				
			||||||
	 * @param c Comment
 | 
						 * @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> {
 | 
						public static async CommentToAPI(h: AbstractUserConnectionContainer, c: Comment, assumeNoLike: boolean = false) : Promise<any> {
 | 
				
			||||||
		return {
 | 
							const data = {
 | 
				
			||||||
			ID: c.id,
 | 
								ID: c.id,
 | 
				
			||||||
			userID: c.userID,
 | 
								userID: c.userID,
 | 
				
			||||||
			postID: c.postID,
 | 
								postID: c.postID,
 | 
				
			||||||
@@ -155,9 +156,17 @@ export class CommentsController {
 | 
				
			|||||||
			content: c.content,
 | 
								content: c.content,
 | 
				
			||||||
			img_path: c.hasImage ? c.imagePath : null,
 | 
								img_path: c.hasImage ? c.imagePath : null,
 | 
				
			||||||
			img_url: c.hasImage ? c.imageURL : null,
 | 
								img_url: c.hasImage ? c.imageURL : null,
 | 
				
			||||||
			likes: await LikesHelper.Count(c.id, LikesType.COMMENT),
 | 
								likes: 0,
 | 
				
			||||||
			userlike: h.signedIn ? await LikesHelper.IsLiking(h.getUserId(), c.id, LikesType.COMMENT) : false
 | 
								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({
 | 
								UserWebSocketController.SendToClient(client, new WsMessage({
 | 
				
			||||||
				id: "",
 | 
									id: "",
 | 
				
			||||||
				title: "new_comment",
 | 
									title: "new_comment",
 | 
				
			||||||
				data: await CommentsController.CommentToAPI(new AbritraryUserConnection(client.userID), c)
 | 
									data: await CommentsController.CommentToAPI(new AbritraryUserConnection(client.userID), c, true)
 | 
				
			||||||
			}))
 | 
								}))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user