not all notifications have a user property
parent
a20bf5ae4c
commit
fabf60f91d
|
@ -38,7 +38,7 @@ export default function makeCtrl(opts: NotifyOpts, redraw: Redraw): Ctrl {
|
||||||
const notif = data.pager.currentPageResults.find(n => !n.read);
|
const notif = data.pager.currentPageResults.find(n => !n.read);
|
||||||
if (!notif) return;
|
if (!notif) return;
|
||||||
opts.pulse();
|
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 text = asText(notif, lichess.trans(data.i18n));
|
||||||
const pushSubscribed = parseInt(lichess.storage.get('push-subscribed') || '0', 10) + 86400000 >= Date.now(); // 24h
|
const pushSubscribed = parseInt(lichess.storage.get('push-subscribed') || '0', 10) + 86400000 >= Date.now(); // 24h
|
||||||
if (!pushSubscribed && text) notify(text);
|
if (!pushSubscribed && text) notify(text);
|
||||||
|
@ -71,7 +71,7 @@ export default function makeCtrl(opts: NotifyOpts, redraw: Redraw): Ctrl {
|
||||||
function setMsgRead(user: string) {
|
function setMsgRead(user: string) {
|
||||||
if (data)
|
if (data)
|
||||||
data.pager.currentPageResults.forEach(n => {
|
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;
|
n.read = true;
|
||||||
data!.unread = Math.max(0, data!.unread - 1);
|
data!.unread = Math.max(0, data!.unread - 1);
|
||||||
opts.setCount(data!.unread);
|
opts.setCount(data!.unread);
|
||||||
|
|
|
@ -24,7 +24,7 @@ interface NotificationUser {
|
||||||
|
|
||||||
interface NotificationContent {
|
interface NotificationContent {
|
||||||
text: string;
|
text: string;
|
||||||
user: NotificationUser;
|
user?: NotificationUser;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue