1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-25 23:09:22 +00:00

Create notification when posting a new comment

This commit is contained in:
Pierre HUBERT 2020-03-23 19:08:04 +01:00
parent bd83a77fb2
commit edc68a0275
4 changed files with 51 additions and 9 deletions

View File

@ -4,6 +4,8 @@ import { LikesHelper, LikesType } from "../helpers/LikesHelper";
import { check_string_before_insert, removeHTMLNodes } from "../utils/StringUtils";
import { time } from "../utils/DateUtils";
import { CommentsHelper } from "../helpers/CommentsHelper";
import { NotificationsUtils } from "../utils/NotificationsUtils";
import { NotifEventType } from "../entities/Notification";
/**
* Comments controller
@ -43,7 +45,8 @@ export class CommentsController {
const commentID = await CommentsHelper.Create(newComment);
// TODO : Create notifications
// Create notifications
await NotificationsUtils.CreatePostNotification(h.getUserId(), postID, NotifEventType.COMMENT_CREATED);
// TODO : Delete any notifications targetting this user about the post

View File

@ -47,28 +47,28 @@ export enum NotifEventVisibility {
}
export interface NotifBuilder {
id: number,
id ?: number,
timeCreate: number,
seen: boolean,
seen ?: boolean,
fromUserID: number,
destUserID: number,
destUserID ?: number,
onElemID: number,
onElemType: NotifElemType,
type: NotifEventType,
eventVisibility: NotifEventVisibility,
eventVisibility ?: NotifEventVisibility,
fromContainerID ?: number,
fromContainerType ?: NotifElemType
}
export class Notif implements NotifBuilder {
id: number; timeCreate: number;
seen: boolean;
id ?: number; timeCreate: number;
seen ?: boolean;
fromUserID: number;
destUserID: number;
destUserID ?: number;
onElemID: number;
onElemType: NotifElemType;
type: NotifEventType;
eventVisibility: NotifEventVisibility;
eventVisibility ?: NotifEventVisibility;
fromContainerID ?: number;
fromContainerType ?: NotifElemType;

View File

@ -11,6 +11,15 @@ const NOTIFICATIONS_TABLE = "comunic_notifications";
export class NotificationsHelper {
/**
* Push a new notification
*
* @param n Notification to push
*/
public static async Push(n: Notif) {
// TODO : push notification
}
/**
* Count the number of unread notifications of a user
*

View File

@ -0,0 +1,30 @@
/**
* Notifications utilities
*
* @author Pierre Hubert
*/
import { NotifEventType, Notif, NotifElemType } from "../entities/Notification";
import { NotificationsHelper } from "../helpers/NotificationsHelper";
import { time } from "./DateUtils";
export class NotificationsUtils {
/**
* Create a notification about a post
*
* @param fromUser Source user ID
* @param postID Target post ID
* @param action Action to notify
*/
public static async CreatePostNotification(fromUser: number, postID: number, action: NotifEventType) {
await NotificationsHelper.Push(new Notif({
timeCreate: time(),
fromUserID: fromUser,
onElemID: postID,
onElemType: NotifElemType.POST,
type: action
}));
}
}