Merge pull request #2558 from Bilb/fix-notifications-preview-skip-already-visible-check

fix: do not deduplicate notification for previews
pull/2560/head
Audric Ackermann 3 years ago committed by GitHub
commit 9f1a6c6349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -60,20 +60,17 @@ export const SessionNotificationGroupSettings = (props: { hasPassword: boolean |
if (!notificationsAreEnabled) { if (!notificationsAreEnabled) {
return; return;
} }
Notifications.addNotification( Notifications.addPreviewNotification({
{ conversationId: `preview-notification-${Date.now()}`,
conversationId: `preview-notification-${Date.now()}`, message:
message: items.find(m => m.value === initialNotificationEnabled)?.label ||
items.find(m => m.value === initialNotificationEnabled)?.label || window?.i18n?.('messageBody') ||
window?.i18n?.('messageBody') || 'Message body',
'Message body', title: window.i18n('notificationPreview'),
title: window.i18n('notificationPreview'), iconUrl: null,
iconUrl: null, isExpiringMessage: false,
isExpiringMessage: false, messageSentAt: Date.now(),
messageSentAt: Date.now(), });
},
true
);
}; };
return ( return (

@ -77,7 +77,7 @@ function disable() {
* *
* @param forceRefresh Should only be set when the user triggers a test notification from the settings * @param forceRefresh Should only be set when the user triggers a test notification from the settings
*/ */
function addNotification(notif: SessionNotification, forceRefresh = false) { function addNotification(notif: SessionNotification) {
const alreadyThere = currentNotifications.find( const alreadyThere = currentNotifications.find(
n => n.conversationId === notif.conversationId && n.messageId === notif.messageId n => n.conversationId === notif.conversationId && n.messageId === notif.messageId
); );
@ -86,11 +86,15 @@ function addNotification(notif: SessionNotification, forceRefresh = false) {
return; return;
} }
currentNotifications.push(notif); currentNotifications.push(notif);
if (forceRefresh) { debouncedUpdate();
update(true); }
} else {
debouncedUpdate(); /**
} * Special case when we want to display a preview of what notifications looks like
*/
function addPreviewNotification(notif: SessionNotification) {
currentNotifications.push(notif);
update(true);
} }
function clearByConversationID(convoId: string) { function clearByConversationID(convoId: string) {
@ -251,6 +255,7 @@ function onRemove() {
export const Notifications = { export const Notifications = {
addNotification, addNotification,
addPreviewNotification,
disable, disable,
enable, enable,
clear, clear,

Loading…
Cancel
Save