not all notifications have a user property

pull/10070/head
Thibault Duplessis 2021-11-02 11:30:26 +01:00
parent a20bf5ae4c
commit fabf60f91d
2 changed files with 3 additions and 3 deletions

View File

@ -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);

View File

@ -24,7 +24,7 @@ interface NotificationUser {
interface NotificationContent {
text: string;
user: NotificationUser;
user?: NotificationUser;
[key: string]: any;
}