mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-22 13:29:22 +00:00
Create notification when posting a new comment
This commit is contained in:
parent
bd83a77fb2
commit
edc68a0275
@ -4,6 +4,8 @@ import { LikesHelper, LikesType } from "../helpers/LikesHelper";
|
|||||||
import { check_string_before_insert, removeHTMLNodes } from "../utils/StringUtils";
|
import { check_string_before_insert, removeHTMLNodes } from "../utils/StringUtils";
|
||||||
import { time } from "../utils/DateUtils";
|
import { time } from "../utils/DateUtils";
|
||||||
import { CommentsHelper } from "../helpers/CommentsHelper";
|
import { CommentsHelper } from "../helpers/CommentsHelper";
|
||||||
|
import { NotificationsUtils } from "../utils/NotificationsUtils";
|
||||||
|
import { NotifEventType } from "../entities/Notification";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Comments controller
|
* Comments controller
|
||||||
@ -43,7 +45,8 @@ export class CommentsController {
|
|||||||
|
|
||||||
const commentID = await CommentsHelper.Create(newComment);
|
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
|
// TODO : Delete any notifications targetting this user about the post
|
||||||
|
|
||||||
|
@ -47,28 +47,28 @@ export enum NotifEventVisibility {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface NotifBuilder {
|
export interface NotifBuilder {
|
||||||
id: number,
|
id ?: number,
|
||||||
timeCreate: number,
|
timeCreate: number,
|
||||||
seen: boolean,
|
seen ?: boolean,
|
||||||
fromUserID: number,
|
fromUserID: number,
|
||||||
destUserID: number,
|
destUserID ?: number,
|
||||||
onElemID: number,
|
onElemID: number,
|
||||||
onElemType: NotifElemType,
|
onElemType: NotifElemType,
|
||||||
type: NotifEventType,
|
type: NotifEventType,
|
||||||
eventVisibility: NotifEventVisibility,
|
eventVisibility ?: NotifEventVisibility,
|
||||||
fromContainerID ?: number,
|
fromContainerID ?: number,
|
||||||
fromContainerType ?: NotifElemType
|
fromContainerType ?: NotifElemType
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Notif implements NotifBuilder {
|
export class Notif implements NotifBuilder {
|
||||||
id: number; timeCreate: number;
|
id ?: number; timeCreate: number;
|
||||||
seen: boolean;
|
seen ?: boolean;
|
||||||
fromUserID: number;
|
fromUserID: number;
|
||||||
destUserID: number;
|
destUserID ?: number;
|
||||||
onElemID: number;
|
onElemID: number;
|
||||||
onElemType: NotifElemType;
|
onElemType: NotifElemType;
|
||||||
type: NotifEventType;
|
type: NotifEventType;
|
||||||
eventVisibility: NotifEventVisibility;
|
eventVisibility ?: NotifEventVisibility;
|
||||||
fromContainerID ?: number;
|
fromContainerID ?: number;
|
||||||
fromContainerType ?: NotifElemType;
|
fromContainerType ?: NotifElemType;
|
||||||
|
|
||||||
|
@ -11,6 +11,15 @@ const NOTIFICATIONS_TABLE = "comunic_notifications";
|
|||||||
|
|
||||||
export class NotificationsHelper {
|
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
|
* Count the number of unread notifications of a user
|
||||||
*
|
*
|
||||||
|
30
src/utils/NotificationsUtils.ts
Normal file
30
src/utils/NotificationsUtils.ts
Normal 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
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user