Enrich the error text for notification blockage and mention http/s issues

This commit is contained in:
Jack Kingsman
2026-03-23 09:12:17 -07:00
parent 84c500d018
commit 1a0c4833d5
2 changed files with 25 additions and 4 deletions

View File

@@ -110,6 +110,8 @@ export function useBrowserNotifications() {
const toggleConversationNotifications = useCallback(
async (type: 'channel' | 'contact', id: string, label: string) => {
const blockedDescription =
'Allow notifications in your browser settings, then try again. Some browsers may refuse notifications on non-HTTPS or self-signed HTTPS origins. Check your browser documentation for how to trust an insecure origin and the associated risks before doing so.';
const conversationKey = getConversationNotificationKey(type, id);
if (enabledByConversation[conversationKey]) {
setEnabledByConversation((prev) => {
@@ -131,7 +133,7 @@ export function useBrowserNotifications() {
if (permission === 'denied') {
toast.error('Browser notifications blocked', {
description: 'Allow notifications in your browser settings, then try again.',
description: blockedDescription,
});
return;
}
@@ -159,9 +161,7 @@ export function useBrowserNotifications() {
toast.error('Browser notifications not enabled', {
description:
nextPermission === 'denied'
? 'Permission was denied by the browser.'
: 'Permission request was dismissed.',
nextPermission === 'denied' ? blockedDescription : 'Permission request was dismissed.',
});
},
[enabledByConversation, permission]

View File

@@ -148,4 +148,25 @@ describe('useBrowserNotifications', () => {
expect(focusSpy).toHaveBeenCalledTimes(1);
expect(notificationInstance.close).toHaveBeenCalledTimes(1);
});
it('shows the browser guidance toast when notifications are blocked', async () => {
Object.assign(window.Notification, {
permission: 'denied',
});
const { result } = renderHook(() => useBrowserNotifications());
await act(async () => {
await result.current.toggleConversationNotifications(
'channel',
incomingChannelMessage.conversation_key,
'#flightless'
);
});
expect(mocks.toast.error).toHaveBeenCalledWith('Browser notifications blocked', {
description:
'Allow notifications in your browser settings, then try again. Some browsers may refuse notifications on non-HTTPS or self-signed HTTPS origins. Check your browser documentation for how to trust an insecure origin and the associated risks before doing so.',
});
});
});