mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 02:12:25 -05:00
[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?)
This commit is contained in:
parent
8b74cad422
commit
27844b7da2
16 changed files with 340 additions and 35 deletions
|
|
@ -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
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue