Browser notification: click leva pro destino real (drawer ou rota)
Bug: onclick da Notification do browser (nativa do Chrome/Windows) fazia window.location.pathname = payload.deeplink direto, sem resolver alias semântico e sem abrir o drawer em alertas com thread_key. Como praticamente todos os nossos alertas do SLA vêm com deeplink '/conversas' (alias), o click na notificação do Chrome caía em NotFound. Fix: - fireBrowserNotification agora aceita um callback onClick e é exportada. - Removido o fireBrowserNotification hardcoded do subscribeRealtime do store (passa a ser responsabilidade do composable useNotifications). - useNotifications.onRealtimeNotification dispara toast + browser notif passando handleNotificationAction como handler. - handleNotificationAction: se tem thread_key → abre ConversationDrawer global direto na thread; senão resolve alias e router.push. Mesma lógica que já existe no toast e no clique do NotificationItem do sino. Agora os 3 pontos de click (toast, sininho, notificação nativa do OS) convergem pro mesmo comportamento. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -38,7 +38,7 @@ function browserNotifEnabled() {
|
||||
}
|
||||
}
|
||||
|
||||
function fireBrowserNotification(item) {
|
||||
export function fireBrowserNotification(item, onClick) {
|
||||
if (!browserNotifEnabled()) return;
|
||||
if (document.hasFocus() && document.visibilityState === 'visible') return; // não notifica se tab ativa
|
||||
try {
|
||||
@@ -52,9 +52,11 @@ function fireBrowserNotification(item) {
|
||||
});
|
||||
n.onclick = () => {
|
||||
window.focus();
|
||||
if (item?.payload?.deeplink) {
|
||||
window.location.hash = '';
|
||||
window.location.pathname = item.payload.deeplink;
|
||||
if (typeof onClick === 'function') {
|
||||
try { onClick(item); } catch { /* ignore */ }
|
||||
} else if (item?.payload?.deeplink) {
|
||||
// fallback: navegação direta se ninguém registrou handler
|
||||
window.location.href = item.payload.deeplink;
|
||||
}
|
||||
n.close();
|
||||
};
|
||||
@@ -129,7 +131,6 @@ export const useNotificationStore = defineStore('notifications', {
|
||||
},
|
||||
(payload) => {
|
||||
this.items.unshift(payload.new);
|
||||
fireBrowserNotification(payload.new);
|
||||
if (typeof onInsert === 'function') {
|
||||
try { onInsert(payload.new); } catch { /* ignore */ }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user