From ed515cc24cc3156acc445a7dc07244fb23c3e292 Mon Sep 17 00:00:00 2001 From: Michcio Date: Fri, 23 Sep 2022 11:59:54 +0200 Subject: [PATCH] Send notifications also when the tab is not visible --- packages/client/src/ui/_common_/common.vue | 102 ++++++++++----------- 1 file changed, 48 insertions(+), 54 deletions(-) diff --git a/packages/client/src/ui/_common_/common.vue b/packages/client/src/ui/_common_/common.vue index 494692c20..c2698d04c 100644 --- a/packages/client/src/ui/_common_/common.vue +++ b/packages/client/src/ui/_common_/common.vue @@ -36,61 +36,55 @@ const dev: Ref = ref(_DEV_); const onNotification = (notification: foundkey.entities.Notification): void => { if ($i?.mutingNotificationTypes.includes(notification.type)) return; - if (document.visibilityState === 'visible') { - stream.send('readNotification', { - id: notification.id, - }); - - if (notification.type !== 'app') { - const user = notification.user; - const userName = acct(user); - let title: string; - let body = 'note' in notification ? getNoteSummary(notification.note) : undefined; - switch (notification.type) { - case 'pollEnded': - title = `${userName}'s poll has ended`; - break; - case 'follow': - title = `${userName} followed you`; - break; - case 'followRequestAccepted': - title = `${userName} accepted your follow request`; - break; - case 'mention': - title = `${userName} mentioned you`; - break; - case 'pollVote': - title = `${userName} voted in your poll`; - break; - case 'quote': - title = `${userName} quoted your post`; - break; - case 'reaction': - title = `${userName} ${notification.reaction}ed your post`; - break; - case 'receiveFollowRequest': - title = `${userName} sent you a follow request`; - break; - case 'renote': - title = `${userName} renoted your post`; - break; - case 'reply': - title = `${userName} replied to your post`; - break; - case 'groupInvited': - title = `${userName} invited you to a group`; - break; - } - - console.log(user, userName, title, body); - new Notification(title, { - body, - image: user.avatarUrl, - icon: instance.iconUrl, - // TODO: timestamp? - }); + if (notification.type !== 'app') { + const user = notification.user; + const userName = acct(user); + let title: string; + let body = 'note' in notification ? getNoteSummary(notification.note) : undefined; + switch (notification.type) { + case 'pollEnded': + title = `${userName}'s poll has ended`; + break; + case 'follow': + title = `${userName} followed you`; + break; + case 'followRequestAccepted': + title = `${userName} accepted your follow request`; + break; + case 'mention': + title = `${userName} mentioned you`; + break; + case 'pollVote': + title = `${userName} voted in your poll`; + break; + case 'quote': + title = `${userName} quoted your post`; + break; + case 'reaction': + title = `${userName} ${notification.reaction}ed your post`; + break; + case 'receiveFollowRequest': + title = `${userName} sent you a follow request`; + break; + case 'renote': + title = `${userName} renoted your post`; + break; + case 'reply': + title = `${userName} replied to your post`; + break; + case 'groupInvited': + title = `${userName} invited you to a group`; + break; } - } + + console.log(user, userName, title, body); + new Notification(title, { + body, + image: user.avatarUrl, + icon: instance.iconUrl, + // TODO: timestamp? + }); + }; sound.play('notification'); };