summaryrefslogtreecommitdiff
path: root/internal/gtsmodel/webpushsubscription.go
diff options
context:
space:
mode:
authorLibravatar Vyr Cossont <VyrCossont@users.noreply.github.com>2025-02-03 02:25:53 -0800
committerLibravatar GitHub <noreply@github.com>2025-02-03 10:25:53 +0000
commit27844b7da2567491661f9ddd2d4662f9f1b3ce40 (patch)
tree1832fe4ec4d3a0fbf6d01bcb5f39acf6885cc1f5 /internal/gtsmodel/webpushsubscription.go
parent[chore]: Bump github.com/tdewolff/minify/v2 from 2.21.2 to 2.21.3 (#3727) (diff)
downloadgotosocial-27844b7da2567491661f9ddd2d4662f9f1b3ce40.tar.xz
[feature] Implement Web Push notification policy (#3721)
* Web Push: add policy column to subscriptions * Web Push: add policy to API * Web Push: test notification policy * go-fmt unrelated file (how did this get thru?)
Diffstat (limited to 'internal/gtsmodel/webpushsubscription.go')
-rw-r--r--internal/gtsmodel/webpushsubscription.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/internal/gtsmodel/webpushsubscription.go b/internal/gtsmodel/webpushsubscription.go
index 4aeef654a..1e310bc50 100644
--- a/internal/gtsmodel/webpushsubscription.go
+++ b/internal/gtsmodel/webpushsubscription.go
@@ -39,12 +39,15 @@ type WebPushSubscription struct {
// P256dh is a Base64-encoded Diffie-Hellman public key on the P-256 elliptic curve.
P256dh string `bun:",nullzero,notnull"`
- // NotificationFlags controls which notifications are delivered to a given subscription.
- // Corresponds to model.PushSubscriptionAlerts.
+ // NotificationFlags controls which notifications are delivered to this subscription.
NotificationFlags WebPushSubscriptionNotificationFlags `bun:",notnull"`
+
+ // Policy controls which accounts are allowed to trigger notifications for this subscription.
+ Policy WebPushNotificationPolicy `bun:",nullzero,notnull,default:1"`
}
// WebPushSubscriptionNotificationFlags is a bitfield representation of a set of NotificationType.
+// Corresponds to apimodel.WebPushSubscriptionAlerts.
type WebPushSubscriptionNotificationFlags int64
// WebPushSubscriptionNotificationFlagsFromSlice packs a slice of NotificationType into a WebPushSubscriptionNotificationFlags.
@@ -80,3 +83,18 @@ func (n *WebPushSubscriptionNotificationFlags) Set(notificationType Notification
*n &= ^(1 << notificationType)
}
}
+
+// WebPushNotificationPolicy represents the notification policy of a Web Push subscription.
+// Corresponds to apimodel.WebPushNotificationPolicy.
+type WebPushNotificationPolicy enumType
+
+const (
+ // WebPushNotificationPolicyAll allows all accounts to send notifications to the subscribing user.
+ WebPushNotificationPolicyAll WebPushNotificationPolicy = 1
+ // WebPushNotificationPolicyFollowed allows accounts followed by the subscribing user to send notifications.
+ WebPushNotificationPolicyFollowed WebPushNotificationPolicy = 2
+ // WebPushNotificationPolicyFollower allows accounts following the subscribing user to send notifications.
+ WebPushNotificationPolicyFollower WebPushNotificationPolicy = 3
+ // WebPushNotificationPolicyNone doesn't allow any accounts to send notifications to the subscribing user.
+ WebPushNotificationPolicyNone WebPushNotificationPolicy = 4
+)