50c7a26a58
This is the first pass of ESLint on the codebase. ESLint formatting is less strict when it comes to line-length and line-breaks then dprint/biome, so if you see formatting that you don't like... fix it! It shouldn't require a configuration change. - This should merge clean into master (when the time comes). - This will not merge clean into `3.9.0-DEV`, but the conflicts aren't that bad.
64 lines
1.3 KiB
TypeScript
64 lines
1.3 KiB
TypeScript
import { injectable } from "tsyringe";
|
|
import { INotification } from "@spt-aki/models/eft/notifier/INotifier";
|
|
|
|
@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];
|
|
}
|
|
}
|