feat: handle note deletion and permission change via event system

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2022-09-22 22:49:25 +02:00 committed by David Mehren
parent 77615f0878
commit 865c70b942
4 changed files with 27 additions and 15 deletions

View file

@ -5,9 +5,11 @@
*/
import { Optional } from '@mrdrogdrog/optional';
import { BeforeApplicationShutdown, Inject, Injectable } from '@nestjs/common';
import { OnEvent } from '@nestjs/event-emitter';
import { SchedulerRegistry } from '@nestjs/schedule';
import appConfiguration, { AppConfig } from '../../config/app.config';
import { NoteEvent } from '../../events';
import { ConsoleLoggerService } from '../../logger/console-logger.service';
import { Note } from '../../notes/note.entity';
import { RevisionsService } from '../../revisions/revisions.service';
@ -101,4 +103,20 @@ export class RealtimeNoteService implements BeforeApplicationShutdown {
});
});
}
@OnEvent(NoteEvent.PERMISSION_CHANGE)
public handleNotePermissionChanged(noteId: Note['id']): void {
const realtimeNote = this.realtimeNoteStore.find(noteId);
if (realtimeNote) {
realtimeNote.announcePermissionChange();
}
}
@OnEvent(NoteEvent.DELETION)
public handleNoteDeleted(noteId: Note['id']): void {
const realtimeNote = this.realtimeNoteStore.find(noteId);
if (realtimeNote) {
realtimeNote.announceNoteDeletion();
}
}
}