Server/project/src/helpers/NotifierHelper.ts

63 lines
1.9 KiB
TypeScript
Raw Normal View History

2023-03-03 16:23:46 +01:00
import { inject, injectable } from "tsyringe";
import { HttpServerHelper } from "@spt-aki/helpers/HttpServerHelper";
import { INotification, NotificationType } from "@spt-aki/models/eft/notifier/INotifier";
import { Message, MessageContentRagfair } from "@spt-aki/models/eft/profile/IAkiProfile";
2023-03-03 16:23:46 +01:00
@injectable()
export class NotifierHelper
{
/**
* The default notification sent when waiting times out.
*/
protected defaultNotification: INotification = {
2023-07-24 16:19:31 +02:00
type: NotificationType.PING,
2023-03-03 16:23:46 +01:00
eventId: "ping"
};
constructor(
@inject("HttpServerHelper") protected httpServerHelper: HttpServerHelper
)
{}
public getDefaultNotification(): INotification
{
return this.defaultNotification;
}
2023-07-24 16:19:31 +02: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
* @returns
*/
2023-03-03 16:23:46 +01:00
public createRagfairOfferSoldNotification(dialogueMessage: Message, ragfairData: MessageContentRagfair): INotification
{
return {
2023-07-24 16:19:31 +02:00
type: NotificationType.RAGFAIR_OFFER_SOLD,
eventId: dialogueMessage._id,
dialogId: dialogueMessage.uid,
2023-03-03 16:23:46 +01:00
...ragfairData
};
}
2023-07-24 16:19:31 +02:00
/**
* Create a new notification with the specified dialogueMessage object
* @param dialogueMessage
* @returns
*/
2023-03-03 16:23:46 +01:00
public createNewMessageNotification(dialogueMessage: Message): INotification
{
return {
2023-07-24 16:19:31 +02:00
type: NotificationType.NEW_MESSAGE,
2023-03-03 16:23:46 +01:00
eventId: dialogueMessage._id,
dialogId: dialogueMessage.uid,
message: dialogueMessage
};
}
public getWebSocketServer(sessionID: string): string
{
return `${this.httpServerHelper.getWebsocketUrl()}/notifierServer/getwebsocket/${sessionID}`;
}
}