notification.ts 671 B

123456789101112131415161718192021222324252627282930313233
  1. import Crowi from '../crowi';
  2. class NortificationService {
  3. crowi!: any;
  4. socketIoService!: any;
  5. notificationEvent!: any;
  6. constructor(crowi: Crowi) {
  7. this.crowi = crowi;
  8. this.socketIoService = crowi.socketIoService;
  9. this.notificationEvent = crowi.event('notification');
  10. // init
  11. this.updateNotificationevent();
  12. }
  13. updateNotificationevent() {
  14. this.notificationEvent.on('update', (user) => {
  15. this.notificationEvent.onUpdate();
  16. if (this.socketIoService.isInitialized) {
  17. this.socketIoService.getDefaultSocket().emit('notification updated', { user });
  18. }
  19. });
  20. }
  21. }
  22. module.exports = NortificationService;