From 5c6aafea51a7ea652f55ef73e4e5feb1e93e655a Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 24 Jul 2023 15:19:31 +0100 Subject: [PATCH] Add enum for notification type --- project/src/helpers/NotificationSendHelper.ts | 4 +-- project/src/helpers/NotifierHelper.ts | 25 +++++++++++++------ project/src/models/eft/notifier/INotifier.ts | 9 ++++++- project/src/servers/WebSocketServer.ts | 4 +-- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/project/src/helpers/NotificationSendHelper.ts b/project/src/helpers/NotificationSendHelper.ts index c756adfe..cf320f98 100644 --- a/project/src/helpers/NotificationSendHelper.ts +++ b/project/src/helpers/NotificationSendHelper.ts @@ -1,6 +1,6 @@ import { inject, injectable } from "tsyringe"; -import { INotification } from "../models/eft/notifier/INotifier"; +import { INotification, NotificationType } from "../models/eft/notifier/INotifier"; import { Dialogue, IUserDialogInfo, Message } from "../models/eft/profile/IAkiProfile"; import { MemberCategory } from "../models/enums/MemberCategory"; import { MessageType } from "../models/enums/MessageType"; @@ -62,7 +62,7 @@ export class NotificationSendHelper dialog.messages.push(message); const notification: INotification = { - type: "new_message", + type: NotificationType.NEW_MESSAGE, eventId: message._id, dialogId: message.uid, message: message diff --git a/project/src/helpers/NotifierHelper.ts b/project/src/helpers/NotifierHelper.ts index 723c3b59..41dfef64 100644 --- a/project/src/helpers/NotifierHelper.ts +++ b/project/src/helpers/NotifierHelper.ts @@ -1,6 +1,6 @@ import { inject, injectable } from "tsyringe"; -import { INotification } from "../models/eft/notifier/INotifier"; +import { INotification, NotificationType } from "../models/eft/notifier/INotifier"; import { Message, MessageContentRagfair } from "../models/eft/profile/IAkiProfile"; import { HttpServerHelper } from "./HttpServerHelper"; @@ -11,7 +11,7 @@ export class NotifierHelper * The default notification sent when waiting times out. */ protected defaultNotification: INotification = { - type: "ping", + type: NotificationType.PING, eventId: "ping" }; @@ -25,22 +25,31 @@ export class NotifierHelper return this.defaultNotification; } - /** Creates a new notification that displays the "Your offer was sold!" prompt and removes sold offer from "My Offers" on clientside */ + /** + * Create a new notification that displays the "Your offer was sold!" prompt and removes sold offer from "My Offers" on clientside + * @param dialogueMessage Message from dialog that was sent + * @param ragfairData Ragfair data to attach to notification + * @returns + */ public createRagfairOfferSoldNotification(dialogueMessage: Message, ragfairData: MessageContentRagfair): INotification { return { - "type": "RagfairOfferSold", - "eventId": dialogueMessage._id, - "dialogId": dialogueMessage.uid, + type: NotificationType.RAGFAIR_OFFER_SOLD, + eventId: dialogueMessage._id, + dialogId: dialogueMessage.uid, ...ragfairData }; } - /** Creates a new notification with the specified dialogueMessage object. */ + /** + * Create a new notification with the specified dialogueMessage object + * @param dialogueMessage + * @returns + */ public createNewMessageNotification(dialogueMessage: Message): INotification { return { - type: "new_message", + type: NotificationType.NEW_MESSAGE, eventId: dialogueMessage._id, dialogId: dialogueMessage.uid, message: dialogueMessage diff --git a/project/src/models/eft/notifier/INotifier.ts b/project/src/models/eft/notifier/INotifier.ts index 3c41f6f4..ec12ba80 100644 --- a/project/src/models/eft/notifier/INotifier.ts +++ b/project/src/models/eft/notifier/INotifier.ts @@ -12,8 +12,15 @@ export interface INotifierChannel export interface INotification { - type: "RagfairOfferSold" | "new_message" | "ping"; + type: NotificationType; eventId: string dialogId?: string message?: Message +} + +export enum NotificationType + { + RAGFAIR_OFFER_SOLD = "RagfairOfferSold", + NEW_MESSAGE = "new_message", + PING = "ping" } \ No newline at end of file diff --git a/project/src/servers/WebSocketServer.ts b/project/src/servers/WebSocketServer.ts index dcf17021..8a91d1f3 100644 --- a/project/src/servers/WebSocketServer.ts +++ b/project/src/servers/WebSocketServer.ts @@ -3,7 +3,7 @@ import { inject, injectable } from "tsyringe"; import WebSocket from "ws"; import { HttpServerHelper } from "../helpers/HttpServerHelper"; -import { INotification } from "../models/eft/notifier/INotifier"; +import { INotification, NotificationType } from "../models/eft/notifier/INotifier"; import { ConfigTypes } from "../models/enums/ConfigTypes"; import { IHttpConfig } from "../models/spt/config/IHttpConfig"; import { ILogger } from "../models/spt/utils/ILogger"; @@ -28,7 +28,7 @@ export class WebSocketServer protected httpConfig: IHttpConfig; protected defaultNotification: INotification = { - type: "ping", + type: NotificationType.PING, eventId: "ping" };