aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/db/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/db/models.py')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/db/models.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/db/models.py b/packages/meshbay-hub/src/meshbay_hub/db/models.py
index dbc0f10..7291485 100644
--- a/packages/meshbay-hub/src/meshbay_hub/db/models.py
+++ b/packages/meshbay-hub/src/meshbay_hub/db/models.py
@@ -398,6 +398,34 @@ class ContentReview(Base):
decided_by: Mapped[str | None] = mapped_column(String(64))
+class PushSubscription(Base):
+ """A phone told about this account's notifications (§11.3): pushed to its
+ Web Push endpoint when it has one, fetched with its poll secret when not.
+
+ The endpoint is a capability — whoever holds the URL can wake the phone —
+ and the keys are what the hub encrypts to, so the push server relays bytes
+ it cannot read. One account holds a handful at most
+ (`api/push.MAX_SUBSCRIPTIONS`): the rows are shared, and every notification
+ costs one outbound request per row.
+ """
+
+ __tablename__ = "push_subscriptions"
+
+ id: Mapped[str] = mapped_column(String(36), primary_key=True, default=_uuid)
+ user_id: Mapped[str] = mapped_column(ForeignKey("users.id"), nullable=False)
+ # All three empty for a phone with no push distributor, which fetches instead.
+ endpoint: Mapped[str | None] = mapped_column(String(1024), nullable=True)
+ p256dh: Mapped[str | None] = mapped_column(String(128), nullable=True)
+ auth: Mapped[str | None] = mapped_column(String(32), nullable=True)
+ # sha256 of the secret `POST /v1/push/poll` is answered for; never the secret.
+ poll_hash: Mapped[str | None] = mapped_column(String(64), nullable=True)
+ created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=_now)
+
+ __table_args__ = (
+ Index("ix_push_subscriptions_user_endpoint", "user_id", "endpoint", unique=True),
+ )
+
+
class UserPreference(Base):
__tablename__ = "user_preferences"