fix: mv paths() to top of NotificationsService to make it more intuitive

This commit is contained in:
Pujit Mehrotra
2024-09-24 19:23:44 -04:00
parent acc847ef1d
commit 1dc665dbd8
5 changed files with 34 additions and 47 deletions

View File

@@ -1,8 +1,8 @@
export interface NotificationIni {
timestamp: string;
event: string;
subject: string;
description: string;
importance: 'normal' | 'alert' | 'warning';
link?: string;
}
timestamp: string;
event: string;
subject: string;
description: string;
importance: 'normal' | 'alert' | 'warning';
link?: string;
}

View File

@@ -793,7 +793,7 @@ export type Notification = Node & {
importance: Importance;
link?: Maybe<Scalars['String']['output']>;
subject: Scalars['String']['output'];
/** ISO Timestamp for when the notification occurred */
/** ISO Timestamp for when the notification occurred */
timestamp?: Maybe<Scalars['String']['output']>;
title: Scalars['String']['output'];
type: NotificationType;

View File

@@ -46,7 +46,9 @@ type Notification implements Node {
importance: Importance!
link: String
type: NotificationType!
""" ISO Timestamp for when the notification occurred """
"""
ISO Timestamp for when the notification occurred
"""
timestamp: String
}
@@ -68,4 +70,4 @@ type NotificationCounts {
warning: Int!
alert: Int!
total: Int!
}
}

View File

@@ -45,6 +45,24 @@ export class NotificationsService {
NotificationsService.watcher = this.getNotificationsWatcher();
}
/**
* Returns the paths to the notification directories.
*
* @returns an object with the:
* - base path
* - path to the unread notifications
* - path to the archived notifications
*/
private paths(): Record<'basePath' | NotificationType, string> {
const basePath = getters.dynamix().notify!.path;
const makePath = (type: NotificationType) => join(basePath, type.toLowerCase());
return {
basePath,
[NotificationType.UNREAD]: makePath(NotificationType.UNREAD),
[NotificationType.ARCHIVE]: makePath(NotificationType.ARCHIVE),
};
}
/**------------------------------------------------------------------------
* Subscription Events
*
@@ -92,21 +110,6 @@ export class NotificationsService {
});
}
private async addToOverview(notification: Notification) {
const { type, importance } = notification;
NotificationsService.overview[type.toLowerCase()][importance.toLowerCase()] += 1;
NotificationsService.overview[type.toLowerCase()]['total'] += 1;
pubsub.publish(PUBSUB_CHANNEL.NOTIFICATION_ADDED, {
notificationAdded: notification,
});
pubsub.publish(PUBSUB_CHANNEL.NOTIFICATION_OVERVIEW, {
notificationsOverview: NotificationsService.overview,
});
}
private async removeFromOverview(notification: Notification) {
const { type, id, importance } = notification;
this.logger.debug(`Removing ${type} Notification: ${id}`);
@@ -415,22 +418,4 @@ export class NotificationsService {
}
return null;
}
/**
* Returns the paths to the notification directories.
*
* @returns an object with the:
* - base path,
* - path to the unread notifications,
* - path to the archived notifications
*/
private paths(): Record<'basePath' | NotificationType, string> {
const basePath = getters.dynamix().notify!.path;
const makePath = (type: NotificationType) => join(basePath, type.toLowerCase());
return {
basePath,
[NotificationType.UNREAD]: makePath(NotificationType.UNREAD),
[NotificationType.ARCHIVE]: makePath(NotificationType.ARCHIVE),
};
}
}

View File

@@ -1,5 +1,5 @@
export function notNull<T>(value: T): value is NonNullable<T> {
return value !== null;
return value !== null;
}
/**
@@ -9,7 +9,7 @@ export function notNull<T>(value: T): value is NonNullable<T> {
* @returns true if the result is fulfilled, false otherwise.
*/
export function isFulfilled<T>(result: PromiseSettledResult<T>): result is PromiseFulfilledResult<T> {
return result.status === 'fulfilled';
return result.status === 'fulfilled';
}
/**
@@ -19,5 +19,5 @@ export function isFulfilled<T>(result: PromiseSettledResult<T>): result is Promi
* @returns true if the result is rejected, false otherwise.
*/
export function isRejected<T>(result: PromiseSettledResult<T>): result is PromiseRejectedResult {
return result.status === 'rejected';
}
return result.status === 'rejected';
}