summaryrefslogtreecommitdiff
path: root/internal/gtsmodel/notification.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-11-25 13:48:59 +0000
committerLibravatar GitHub <noreply@github.com>2024-11-25 14:48:59 +0100
commitcac9d65029e972af9440ff79a2617d5c524a9d64 (patch)
tree87353498b2d6bb29679cd4af8744d5b3f7cd3423 /internal/gtsmodel/notification.go
parent[chore]: Bump github.com/stretchr/testify from 1.9.0 to 1.10.0 (#3564) (diff)
downloadgotosocial-cac9d65029e972af9440ff79a2617d5c524a9d64.tar.xz
[performance] convert enum strings to ints (#3558)
* convert statuses.visibility and notifications.notification_type columns from type string -> int for performance / space savings * fix test trying to compare string to int * fix instance count query using string literal instead of gtsmodel const type * ensure a default value is always set * also migrate the account settings and sin bin status tables * initialize maps outside loops and place into singular enum mapping creation func * use int16 for enum types * update sinbinstatus creation to be from a snapshot at initial creation * add snapshot of poll type at creation time
Diffstat (limited to 'internal/gtsmodel/notification.go')
-rw-r--r--internal/gtsmodel/notification.go59
1 files changed, 45 insertions, 14 deletions
diff --git a/internal/gtsmodel/notification.go b/internal/gtsmodel/notification.go
index 5cf6b061a..49f1fe2bb 100644
--- a/internal/gtsmodel/notification.go
+++ b/internal/gtsmodel/notification.go
@@ -34,20 +34,51 @@ type Notification struct {
Read *bool `bun:",nullzero,notnull,default:false"` // Notification has been seen/read
}
-// NotificationType describes the reason/type of this notification.
-type NotificationType string
+// NotificationType describes the
+// reason/type of this notification.
+type NotificationType enumType
-// Notification Types
const (
- NotificationFollow NotificationType = "follow" // NotificationFollow -- someone followed you
- NotificationFollowRequest NotificationType = "follow_request" // NotificationFollowRequest -- someone requested to follow you
- NotificationMention NotificationType = "mention" // NotificationMention -- someone mentioned you in their status
- NotificationReblog NotificationType = "reblog" // NotificationReblog -- someone boosted one of your statuses
- NotificationFave NotificationType = "favourite" // NotificationFave -- someone faved/liked one of your statuses
- NotificationPoll NotificationType = "poll" // NotificationPoll -- a poll you voted in or created has ended
- NotificationStatus NotificationType = "status" // NotificationStatus -- someone you enabled notifications for has posted a status.
- NotificationSignup NotificationType = "admin.sign_up" // NotificationSignup -- someone has submitted a new account sign-up to the instance.
- NotificationPendingFave NotificationType = "pending.favourite" // Someone has faved a status of yours, which requires approval by you.
- NotificationPendingReply NotificationType = "pending.reply" // Someone has replied to a status of yours, which requires approval by you.
- NotificationPendingReblog NotificationType = "pending.reblog" // Someone has boosted a status of yours, which requires approval by you.
+ // Notification Types
+ NotificationFollow NotificationType = 1 // NotificationFollow -- someone followed you
+ NotificationFollowRequest NotificationType = 2 // NotificationFollowRequest -- someone requested to follow you
+ NotificationMention NotificationType = 3 // NotificationMention -- someone mentioned you in their status
+ NotificationReblog NotificationType = 4 // NotificationReblog -- someone boosted one of your statuses
+ NotificationFave NotificationType = 5 // NotificationFave -- someone faved/liked one of your statuses
+ NotificationPoll NotificationType = 6 // NotificationPoll -- a poll you voted in or created has ended
+ NotificationStatus NotificationType = 7 // NotificationStatus -- someone you enabled notifications for has posted a status.
+ NotificationSignup NotificationType = 8 // NotificationSignup -- someone has submitted a new account sign-up to the instance.
+ NotificationPendingFave NotificationType = 9 // Someone has faved a status of yours, which requires approval by you.
+ NotificationPendingReply NotificationType = 10 // Someone has replied to a status of yours, which requires approval by you.
+ NotificationPendingReblog NotificationType = 11 // Someone has boosted a status of yours, which requires approval by you.
)
+
+// String returns a stringified, frontend API compatible form of NotificationType.
+func (t NotificationType) String() string {
+ switch t {
+ case NotificationFollow:
+ return "follow"
+ case NotificationFollowRequest:
+ return "follow_request"
+ case NotificationMention:
+ return "mention"
+ case NotificationReblog:
+ return "reblog"
+ case NotificationFave:
+ return "favourite"
+ case NotificationPoll:
+ return "poll"
+ case NotificationStatus:
+ return "status"
+ case NotificationSignup:
+ return "admin.sign_up"
+ case NotificationPendingFave:
+ return "pending.favourite"
+ case NotificationPendingReply:
+ return "pending.reply"
+ case NotificationPendingReblog:
+ return "pending.reblog"
+ default:
+ panic("invalid notification type")
+ }
+}