1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-09-21 14:48:48 +00:00

Can be automatically be notified of comments creation

This commit is contained in:
2020-04-01 17:51:33 +02:00
parent 21ba8eff25
commit 53d121708d
7 changed files with 89 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ import { DatabaseHelper } from "./DatabaseHelper";
import { unlinkSync, existsSync } from "fs";
import { LikesHelper, LikesType } from "./LikesHelper";
import { mysql_date, time } from "../utils/DateUtils";
import { EventsHelper } from "./EventsHelper";
/**
* Comments helper
@@ -20,7 +21,7 @@ export class CommentsHelper {
* @param comment Information about the comment to create
*/
public static async Create(comment: Comment) : Promise<number> {
return await DatabaseHelper.InsertRow(COMMENTS_TABLE, {
const commentID = await DatabaseHelper.InsertRow(COMMENTS_TABLE, {
ID_texte: comment.postID,
ID_personne: comment.userID,
date_envoi: mysql_date(),
@@ -28,6 +29,14 @@ export class CommentsHelper {
commentaire: comment.content,
image_commentaire: comment.hasImage ? comment.imagePath : ""
});
// Propagate event
comment.id = commentID;
await EventsHelper.Emit("comment_created", {
comment: comment
});
return commentID
}
/**

View File

@@ -1,5 +1,6 @@
import { APIClient } from "../entities/APIClient";
import { ConversationMessage } from "../entities/ConversationMessage";
import { Comment } from "../entities/Comment";
/**
* Events manager
@@ -28,6 +29,11 @@ export interface SentNewConversationMessageEvent {
msg: ConversationMessage
}
// When a comment is created
export interface CommentCreatedEvent {
comment: Comment
}
/**
* Global map of all possible events
*/
@@ -35,7 +41,8 @@ export interface EventsMap {
"destroyed_login_tokens": DestroyedLoginTokensEvent,
"updated_number_notifications": UpdatedNotificationsNumberEvent,
"updated_number_unread_conversations": UpdateNumberUnreadConversationsEvent,
"sent_conversation_message": SentNewConversationMessageEvent
"sent_conversation_message": SentNewConversationMessageEvent,
"comment_created": CommentCreatedEvent
}
export class EventsHelper {