diff options
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/bundb/notification.go | 10 | ||||
-rw-r--r-- | internal/db/bundb/notification_test.go | 5 | ||||
-rw-r--r-- | internal/db/notification.go | 7 |
3 files changed, 17 insertions, 5 deletions
diff --git a/internal/db/bundb/notification.go b/internal/db/bundb/notification.go index 04688a379..af147ab08 100644 --- a/internal/db/bundb/notification.go +++ b/internal/db/bundb/notification.go @@ -200,6 +200,7 @@ func (n *notificationDB) GetAccountNotifications( sinceID string, minID string, limit int, + includeTypes []string, excludeTypes []string, ) ([]*gtsmodel.Notification, error) { // Ensure reasonable @@ -237,9 +238,14 @@ func (n *notificationDB) GetAccountNotifications( frontToBack = false // page up } - for _, excludeType := range excludeTypes { + if len(includeTypes) > 0 { + // Include only requested notification types. + q = q.Where("? IN (?)", bun.Ident("notification.notification_type"), bun.In(includeTypes)) + } + + if len(excludeTypes) > 0 { // Filter out unwanted notif types. - q = q.Where("? != ?", bun.Ident("notification.notification_type"), excludeType) + q = q.Where("? NOT IN (?)", bun.Ident("notification.notification_type"), bun.In(excludeTypes)) } // Return only notifs for this account. diff --git a/internal/db/bundb/notification_test.go b/internal/db/bundb/notification_test.go index 984c0ef8d..eb2c02066 100644 --- a/internal/db/bundb/notification_test.go +++ b/internal/db/bundb/notification_test.go @@ -97,6 +97,7 @@ func (suite *NotificationTestSuite) TestGetAccountNotificationsWithSpam() { "", 20, nil, + nil, ) suite.NoError(err) timeTaken := time.Since(before) @@ -119,6 +120,7 @@ func (suite *NotificationTestSuite) TestGetAccountNotificationsWithoutSpam() { "", 20, nil, + nil, ) suite.NoError(err) timeTaken := time.Since(before) @@ -143,6 +145,7 @@ func (suite *NotificationTestSuite) TestDeleteNotificationsWithSpam() { "", 20, nil, + nil, ) if err != nil { suite.FailNow(err.Error()) @@ -163,6 +166,7 @@ func (suite *NotificationTestSuite) TestDeleteNotificationsWithSpam() { "", 20, nil, + nil, ) if err != nil { suite.FailNow(err.Error()) @@ -184,6 +188,7 @@ func (suite *NotificationTestSuite) TestDeleteNotificationsWithTwoAccounts() { "", 20, nil, + nil, ) suite.NoError(err) suite.Nil(notifications) diff --git a/internal/db/notification.go b/internal/db/notification.go index 9ff459b9c..2e8f5ed1f 100644 --- a/internal/db/notification.go +++ b/internal/db/notification.go @@ -25,12 +25,13 @@ import ( // Notification contains functions for creating and getting notifications. type Notification interface { - // GetNotifications returns a slice of notifications that pertain to the given accountID. + // GetAccountNotifications returns a slice of notifications that pertain to the given accountID. // // Returned notifications will be ordered ID descending (ie., highest/newest to lowest/oldest). - GetAccountNotifications(ctx context.Context, accountID string, maxID string, sinceID string, minID string, limit int, excludeTypes []string) ([]*gtsmodel.Notification, error) + // If includeTypes is empty, *all* notification types will be included. + GetAccountNotifications(ctx context.Context, accountID string, maxID string, sinceID string, minID string, limit int, includeTypes []string, excludeTypes []string) ([]*gtsmodel.Notification, error) - // GetNotification returns one notification according to its id. + // GetNotificationByID returns one notification according to its id. GetNotificationByID(ctx context.Context, id string) (*gtsmodel.Notification, error) // GetNotificationsByIDs returns a slice of notifications of the the provided IDs. |