@@ -529,14 +529,25 @@ export class NotificationsService {
529529 * @returns An array of all notifications in the system.
530530 */
531531 public async getNotifications ( filters : NotificationFilter ) : Promise < Notification [ ] > {
532- this . logger . debug ( 'Getting Notifications' ) ;
532+ this . logger . verbose ( 'Getting Notifications' ) ;
533533
534+ const { type = NotificationType . UNREAD } = filters ;
534535 const { ARCHIVE , UNREAD } = this . paths ( ) ;
535- const directoryPath = filters . type === NotificationType . ARCHIVE ? ARCHIVE : UNREAD ;
536-
537- const unreadFiles = await this . listFilesInFolder ( directoryPath ) ;
538- const [ notifications ] = await this . loadNotificationsFromPaths ( unreadFiles , filters ) ;
536+ let files : string [ ] ;
537+
538+ if ( type === NotificationType . UNREAD ) {
539+ files = await this . listFilesInFolder ( UNREAD ) ;
540+ } else {
541+ // Exclude notifications present in both unread & archive from archive.
542+ //* this is necessary because the legacy script writes new notifications to both places.
543+ //* this should be a temporary measure.
544+ const unreads = new Set ( await readdir ( UNREAD ) ) ;
545+ files = await this . listFilesInFolder ( ARCHIVE , ( archives ) => {
546+ return archives . filter ( ( file ) => ! unreads . has ( file ) ) ;
547+ } ) ;
548+ }
539549
550+ const [ notifications ] = await this . loadNotificationsFromPaths ( files , filters ) ;
540551 return notifications ;
541552 }
542553
@@ -545,12 +556,16 @@ export class NotificationsService {
545556 * Sorted latest-first by default.
546557 *
547558 * @param folderPath The path of the folder to read.
559+ * @param narrowContent Returns which files from `folderPath` to include. Defaults to all.
548560 * @param sortFn An optional function to sort folder contents. Defaults to descending birth time.
549561 * @returns A list of absolute paths of all the files and contents in the folder.
550562 */
551- private async listFilesInFolder ( folderPath : string , sortFn ?: SortFn < Stats > ) : Promise < string [ ] > {
552- sortFn ??= ( fileA , fileB ) => fileB . birthtimeMs - fileA . birthtimeMs ; // latest first
553- const contents = await readdir ( folderPath ) ;
563+ private async listFilesInFolder (
564+ folderPath : string ,
565+ narrowContent : ( contents : string [ ] ) => string [ ] = ( contents ) => contents ,
566+ sortFn : SortFn < Stats > = ( fileA , fileB ) => fileB . birthtimeMs - fileA . birthtimeMs // latest first
567+ ) : Promise < string [ ] > {
568+ const contents = narrowContent ( await readdir ( folderPath ) ) ;
554569 return contents
555570 . map ( ( content ) => {
556571 // pre-map each file's stats to avoid excess calls during sorting
0 commit comments