()
| 117 | } |
| 118 | |
| 119 | private async run(): Promise<void> { |
| 120 | if (!this.enabled || this.loading) { |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | try { |
| 125 | this.loading = true; |
| 126 | await icAgent.loadIdentity(); |
| 127 | |
| 128 | const notifications = await this.stationService.listUnreadNotifications( |
| 129 | this.lastNotificationDate ?? undefined, |
| 130 | this.lastNotificationId ?? undefined, |
| 131 | ); |
| 132 | const lastNotification = notifications?.[0]; |
| 133 | this.lastNotificationId = lastNotification?.id ?? null; |
| 134 | if (lastNotification) { |
| 135 | this.lastNotificationDate = new Date(lastNotification.created_at); |
| 136 | } |
| 137 | |
| 138 | postMessage({ |
| 139 | type: 'notifications', |
| 140 | data: { |
| 141 | notifications, |
| 142 | }, |
| 143 | } as NotificationsWorkerResponseMessage); |
| 144 | } catch (err) { |
| 145 | logger.error(`Failed to fetch notifications`, { err }); |
| 146 | |
| 147 | postMessage({ |
| 148 | type: 'error', |
| 149 | data: { |
| 150 | code: 'ERR_FETCH_NOTIFICATIONS', |
| 151 | msg: `Failed to fetch notifications: ${err}`, |
| 152 | }, |
| 153 | } as NotificationsWorkerResponseMessage); |
| 154 | } finally { |
| 155 | this.loading = false; |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | NotificationsWorkerImpl.register(); |
no test coverage detected