diff --git a/src/controllers/UserWebSocketActions.ts b/src/controllers/UserWebSocketActions.ts index e7482ec..d4711b9 100644 --- a/src/controllers/UserWebSocketActions.ts +++ b/src/controllers/UserWebSocketActions.ts @@ -158,7 +158,7 @@ export class UserWebSocketActions { /** * Propagate comment update * - * @param c New comment + * @param c Updated comment */ public static async UpdatedComment(commentID: number) { const comment = await CommentsHelper.GetSingle(commentID); @@ -171,6 +171,15 @@ export class UserWebSocketActions { })) } } + + /** + * Propagage the deletion of a comment + * + * @param comment Deleted comment + */ + public static async DeletedComment(comment: Comment) { + console.log(comment); + } } @@ -183,6 +192,7 @@ EventsHelper.Listen("updated_number_unread_conversations", async (e) => await Us // When a new message is sent EventsHelper.Listen("sent_conversation_message", async (e) => await UserWebSocketActions.SentNewConversationMessage(e.msg)); -// When a comment is created / updated +// When a comment is created / updated / deleted EventsHelper.Listen("comment_created", async (e) => await UserWebSocketActions.CreatedNewComment(e.comment)) -EventsHelper.Listen("comment_updated", async (e) => await UserWebSocketActions.UpdatedComment(e.commentID)); \ No newline at end of file +EventsHelper.Listen("comment_updated", async (e) => await UserWebSocketActions.UpdatedComment(e.commentID)); +EventsHelper.Listen("comment_deleted", async (e) => await UserWebSocketActions.DeletedComment(e.comment)); \ No newline at end of file diff --git a/src/helpers/CommentsHelper.ts b/src/helpers/CommentsHelper.ts index a96e3b8..44ab678 100644 --- a/src/helpers/CommentsHelper.ts +++ b/src/helpers/CommentsHelper.ts @@ -156,6 +156,11 @@ export class CommentsHelper { await DatabaseHelper.DeleteRows(COMMENTS_TABLE, { ID: comment.id }) + + // Notify system + await EventsHelper.Emit("comment_deleted", { + comment: comment + }); } /** diff --git a/src/helpers/EventsHelper.ts b/src/helpers/EventsHelper.ts index d5d3049..9090562 100644 --- a/src/helpers/EventsHelper.ts +++ b/src/helpers/EventsHelper.ts @@ -39,6 +39,11 @@ export interface CommentUpdatedEvent { commentID: number } +// When a comment is deleted +export interface CommentDeletedEvent { + comment: Comment +} + /** * Global map of all possible events */ @@ -48,7 +53,8 @@ export interface EventsMap { "updated_number_unread_conversations": UpdateNumberUnreadConversationsEvent, "sent_conversation_message": SentNewConversationMessageEvent, "comment_created": CommentCreatedEvent, - "comment_updated": CommentUpdatedEvent + "comment_updated": CommentUpdatedEvent, + "comment_deleted": CommentDeletedEvent, } export class EventsHelper {