Simplify web push UX and updates

- Use a single endpoint
- Use a declarative web push sync hook. This thus handles all edge cases
  that had to be manually handled before: logout, login, account sync,
  etc.
- Simplify UX: browser notifications are always enabled (unless denied),
  web push toggle only shows up if permissions are already granted.
This commit is contained in:
nimbleghost
2023-06-02 13:22:54 +02:00
parent 4944e3ae4b
commit 47ad024ec7
20 changed files with 294 additions and 427 deletions

View File

@@ -1,5 +1,4 @@
import Connection from "./Connection";
import { NotificationType } from "./SubscriptionManager";
import { hashCode } from "./utils";
const makeConnectionId = (subscription, user) =>
@@ -52,11 +51,9 @@ class ConnectionManager {
const connectionId = makeConnectionId(s, user);
return { ...s, user, connectionId };
})
// we want to create a ws for both sound-only and active browser notifications,
// only background notifications don't need this as they come over web push.
// however, if background notifications are muted, we again need the ws while
// the page is active
.filter((s) => s.notificationType !== NotificationType.BACKGROUND && s.mutedUntil !== 1);
// background notifications don't need this as they come over web push.
// however, if they are muted, we again need the ws while the page is active
.filter((s) => !s.webPushEnabled && s.mutedUntil !== 1);
console.log();
const targetIds = subscriptionsWithUsersAndConnectionId.map((s) => s.connectionId);