From fabf60f91d311f1d230fa8f3820497ab5a719d96 Mon Sep 17 00:00:00 2001 From: Thibault Duplessis Date: Tue, 2 Nov 2021 11:30:26 +0100 Subject: [PATCH] not all notifications have a user property --- ui/notify/src/ctrl.ts | 4 ++-- ui/notify/src/interfaces.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/notify/src/ctrl.ts b/ui/notify/src/ctrl.ts index fa1e56519f..7c139cb164 100644 --- a/ui/notify/src/ctrl.ts +++ b/ui/notify/src/ctrl.ts @@ -38,7 +38,7 @@ export default function makeCtrl(opts: NotifyOpts, redraw: Redraw): Ctrl { const notif = data.pager.currentPageResults.find(n => !n.read); if (!notif) return; opts.pulse(); - if (!lichess.quietMode || notif.content.user.id == 'lichess') lichess.sound.playOnce('newPM'); + if (!lichess.quietMode || notif.content.user?.id == 'lichess') lichess.sound.playOnce('newPM'); const text = asText(notif, lichess.trans(data.i18n)); const pushSubscribed = parseInt(lichess.storage.get('push-subscribed') || '0', 10) + 86400000 >= Date.now(); // 24h if (!pushSubscribed && text) notify(text); @@ -71,7 +71,7 @@ export default function makeCtrl(opts: NotifyOpts, redraw: Redraw): Ctrl { function setMsgRead(user: string) { if (data) data.pager.currentPageResults.forEach(n => { - if (n.type == 'privateMessage' && n.content.user.id == user && !n.read) { + if (n.type == 'privateMessage' && n.content.user?.id == user && !n.read) { n.read = true; data!.unread = Math.max(0, data!.unread - 1); opts.setCount(data!.unread); diff --git a/ui/notify/src/interfaces.ts b/ui/notify/src/interfaces.ts index b7e430406c..1329df17f1 100644 --- a/ui/notify/src/interfaces.ts +++ b/ui/notify/src/interfaces.ts @@ -24,7 +24,7 @@ interface NotificationUser { interface NotificationContent { text: string; - user: NotificationUser; + user?: NotificationUser; [key: string]: any; }