Server/project/src/helpers/NotifierHelper.ts

57 lines
2.1 KiB
TypeScript
Raw Normal View History

import { HttpServerHelper } from "@spt/helpers/HttpServerHelper";
import { IMessage, IMessageContentRagfair } from "@spt/models/eft/profile/ISptProfile";
import { IWsChatMessageReceived } from "@spt/models/eft/ws/IWsChatMessageReceived";
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { IWsRagfairOfferSold } from "@spt/models/eft/ws/IWsRagfairOfferSold";
import { NotificationEventType } from "@spt/models/enums/NotificationEventType";
import { inject, injectable } from "tsyringe";
2023-03-03 15:23:46 +00:00
@injectable()
export class NotifierHelper {
2023-03-03 15:23:46 +00:00
/**
* The default notification sent when waiting times out.
*/
protected defaultNotification: IWsNotificationEvent = { type: NotificationEventType.PING, eventId: "ping" };
2023-03-03 15:23:46 +00:00
constructor(@inject("HttpServerHelper") protected httpServerHelper: HttpServerHelper) {}
2023-03-03 15:23:46 +00:00
public getDefaultNotification(): IWsNotificationEvent {
2023-03-03 15:23:46 +00:00
return this.defaultNotification;
}
2023-07-24 15:19:31 +01:00
/**
* 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
2023-11-15 20:35:05 -05:00
* @returns
2023-07-24 15:19:31 +01:00
*/
2023-11-15 20:35:05 -05:00
public createRagfairOfferSoldNotification(
dialogueMessage: IMessage,
ragfairData: IMessageContentRagfair,
): IWsRagfairOfferSold {
2023-03-03 15:23:46 +00:00
return {
type: NotificationEventType.RAGFAIR_OFFER_SOLD,
2023-07-24 15:19:31 +01:00
eventId: dialogueMessage._id,
2023-11-15 20:35:05 -05:00
...ragfairData,
2023-03-03 15:23:46 +00:00
};
}
2023-07-24 15:19:31 +01:00
/**
* Create a new notification with the specified dialogueMessage object
2023-11-15 20:35:05 -05:00
* @param dialogueMessage
* @returns
2023-07-24 15:19:31 +01:00
*/
public createNewMessageNotification(dialogueMessage: IMessage): IWsChatMessageReceived {
2023-03-03 15:23:46 +00:00
return {
type: NotificationEventType.CHAT_MESSAGE_RECEIVED,
2023-03-03 15:23:46 +00:00
eventId: dialogueMessage._id,
dialogId: dialogueMessage.uid,
2023-11-15 20:35:05 -05:00
message: dialogueMessage,
2023-03-03 15:23:46 +00:00
};
}
public getWebSocketServer(sessionID: string): string {
2023-03-03 15:23:46 +00:00
return `${this.httpServerHelper.getWebsocketUrl()}/notifierServer/getwebsocket/${sessionID}`;
}
2023-11-15 20:35:05 -05:00
}