2023-03-03 16:23:46 +01:00
|
|
|
import { injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 19:21:17 +02:00
|
|
|
import { INotification } from "@spt-aki/models/eft/notifier/INotifier";
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class NotificationService
|
|
|
|
{
|
|
|
|
protected messageQueue: Record<string, any[]> = {};
|
|
|
|
|
|
|
|
public getMessageQueue(): Record<string, any[]>
|
|
|
|
{
|
|
|
|
return this.messageQueue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getMessageFromQueue(sessionId: string): any[]
|
|
|
|
{
|
|
|
|
return this.messageQueue[sessionId];
|
|
|
|
}
|
|
|
|
|
|
|
|
public updateMessageOnQueue(sessionId: string, value: any[]): void
|
|
|
|
{
|
|
|
|
this.messageQueue[sessionId] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public has(sessionID: string): boolean
|
|
|
|
{
|
|
|
|
return this.get(sessionID).length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pop first message from queue.
|
|
|
|
*/
|
|
|
|
public pop(sessionID: string): any
|
|
|
|
{
|
|
|
|
return this.get(sessionID).shift();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add message to queue
|
|
|
|
*/
|
|
|
|
public add(sessionID: string, message: INotification): void
|
|
|
|
{
|
|
|
|
this.get(sessionID).push(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get message queue for session
|
|
|
|
* @param sessionID
|
|
|
|
*/
|
|
|
|
public get(sessionID: string): any[]
|
|
|
|
{
|
|
|
|
if (!sessionID)
|
|
|
|
{
|
|
|
|
throw new Error("sessionID missing");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.messageQueue[sessionID])
|
|
|
|
{
|
|
|
|
this.messageQueue[sessionID] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.messageQueue[sessionID];
|
|
|
|
}
|
2023-11-16 02:35:05 +01:00
|
|
|
}
|