diff options
author | 2024-11-27 18:22:45 +0100 | |
---|---|---|
committer | 2024-11-27 17:22:45 +0000 | |
commit | 65917f5bb98f1c0a0ce7285c284d25ea843c02c7 (patch) | |
tree | 9dd34f87dd8f5fd08ff22e98ba26556486eb6a97 /internal/gtsmodel/notification.go | |
parent | pull in ncruces/go-sqlite3 v0.20.3 with tetratelabs/wazero v1.8.2 (#3574) (diff) | |
download | gotosocial-65917f5bb98f1c0a0ce7285c284d25ea843c02c7.tar.xz |
[bugfix] Log + ignore unknown notification types (#3577)
* [bugfix] Log + ignore unknown notification types
* pass context to ParseNotificationTypes
Diffstat (limited to 'internal/gtsmodel/notification.go')
-rw-r--r-- | internal/gtsmodel/notification.go | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/internal/gtsmodel/notification.go b/internal/gtsmodel/notification.go index 49f1fe2bb..47bf7daa5 100644 --- a/internal/gtsmodel/notification.go +++ b/internal/gtsmodel/notification.go @@ -17,7 +17,10 @@ package gtsmodel -import "time" +import ( + "strings" + "time" +) // Notification models an alert/notification sent to an account about something like a reblog, like, new follow request, etc. type Notification struct { @@ -40,6 +43,7 @@ type NotificationType enumType const ( // Notification Types + NotificationUnknown NotificationType = 0 // NotificationUnknown -- unknown notification type, error if this occurs 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 @@ -82,3 +86,33 @@ func (t NotificationType) String() string { panic("invalid notification type") } } + +// NewNotificationType returns a notification type from the given value. +func NewNotificationType(in string) NotificationType { + switch strings.ToLower(in) { + case "follow": + return NotificationFollow + case "follow_request": + return NotificationFollowRequest + case "mention": + return NotificationMention + case "reblog": + return NotificationReblog + case "favourite": + return NotificationFave + case "poll": + return NotificationPoll + case "status": + return NotificationStatus + case "admin.sign_up": + return NotificationSignup + case "pending.favourite": + return NotificationPendingFave + case "pending.reply": + return NotificationPendingReply + case "pending.reblog": + return NotificationPendingReblog + default: + return NotificationUnknown + } +} |