Something went wrong. Try again.
A self-hosted web platform for applications & services with design based on Google's Material 3 Expressive. (Work In Progress)
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889import EventEmitter from "node:events";import type { Instance } from "../index.ts";import System from "../system.ts";
export enum WorkspacesNoticeType { Login, Signup,}
export enum WorkspacesNotificationPriority { Normal, Important, Urgent,}
export interface WorkspacesNotificationContent { title: string; icon?: string; body: string;}
export enum WorkspacesNotificationEventEmitterEvent { SendNotification = "send_notification",}
export interface WorkspacesNotificationOptions { buttons: { id: string; label: string; type: "filled" | "tonal" }[];}
export interface WorkspacesNotificationOptionsCallbacks { onButton(optionId: string): void | { action: { type: "navigate"; value: string } | { type: "reload" }; };}
export interface WorkspacesNotification { recipient: number; sourceId: string; priority: WorkspacesNotificationPriority; content: WorkspacesNotificationContent; uuid: string; options?: WorkspacesNotificationOptions; optionsCallbacks?: WorkspacesNotificationOptionsCallbacks;}
export default class NotificationsSystem extends System { eventEmitter: EventEmitter;
constructor(instance: Instance) { super("notifications", instance);
this.eventEmitter = new EventEmitter(); }
// TODO: implement this // applyNotice(targetUserId: number, noticeType: WorkspacesNoticeType[], noticeTitle: string, noticeBody: string) { // this.log.warning("Notices are Unimplemented"); // return this; // }
send( recipient: number, sourceId: string, priority: WorkspacesNotificationPriority, content: WorkspacesNotificationContent, options?: WorkspacesNotificationOptions, optionsCallbacks?: WorkspacesNotificationOptionsCallbacks, ) { this.eventEmitter.emit(WorkspacesNotificationEventEmitterEvent.SendNotification, { recipient, sourceId, priority, content, uuid: crypto.randomUUID(), options: { buttons: options?.buttons || [], }, optionsCallbacks: optionsCallbacks, } satisfies WorkspacesNotification);
return this; }
override async startup(): Promise<boolean> { this.log.info("Starting up..."); return true; }}