diff --git a/src/controllers/UserWebSocketActions.ts b/src/controllers/UserWebSocketActions.ts index 9e5b472..644ce33 100644 --- a/src/controllers/UserWebSocketActions.ts +++ b/src/controllers/UserWebSocketActions.ts @@ -16,6 +16,7 @@ import { PostAccessLevel } from "../entities/Post"; import { Comment } from "../entities/Comment"; import { CommentsController } from "./CommentsController"; import { AbritraryUserConnection } from "../entities/UserConnectionContainer"; +import { CommentsHelper } from "../helpers/CommentsHelper"; export class UserWebSocketActions { @@ -153,6 +154,17 @@ export class UserWebSocketActions { } } + + /** + * Propagate comment update + * + * @param c New comment + */ + public static async UpdatedComment(commentID: number) { + const comment = await CommentsHelper.GetSingle(commentID); + + console.info(comment) + } } @@ -165,5 +177,6 @@ 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 -EventsHelper.Listen("comment_created", async (e) => await UserWebSocketActions.CreatedNewComment(e.comment)) \ No newline at end of file +// When a comment is created / updated +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 diff --git a/src/helpers/CommentsHelper.ts b/src/helpers/CommentsHelper.ts index 3b43b09..a96e3b8 100644 --- a/src/helpers/CommentsHelper.ts +++ b/src/helpers/CommentsHelper.ts @@ -55,6 +55,10 @@ export class CommentsHelper { commentaire: newContent } }) + + await EventsHelper.Emit("comment_updated", { + commentID: commentID + }); } /** diff --git a/src/helpers/EventsHelper.ts b/src/helpers/EventsHelper.ts index 4d25b8a..d5d3049 100644 --- a/src/helpers/EventsHelper.ts +++ b/src/helpers/EventsHelper.ts @@ -34,6 +34,11 @@ export interface CommentCreatedEvent { comment: Comment } +// When a comment is updated +export interface CommentUpdatedEvent { + commentID: number +} + /** * Global map of all possible events */ @@ -42,7 +47,8 @@ export interface EventsMap { "updated_number_notifications": UpdatedNotificationsNumberEvent, "updated_number_unread_conversations": UpdateNumberUnreadConversationsEvent, "sent_conversation_message": SentNewConversationMessageEvent, - "comment_created": CommentCreatedEvent + "comment_created": CommentCreatedEvent, + "comment_updated": CommentUpdatedEvent } export class EventsHelper {