diff options
author | 2022-08-31 13:20:52 -0400 | |
---|---|---|
committer | 2022-08-31 19:20:52 +0200 | |
commit | ecb97f4e0bae0735464880cd850e964f292f2e92 (patch) | |
tree | c0c6c6576beaf1e4a0bbd740d8db9341d77b2ae6 /internal/db | |
parent | [bugfix] Use custom blackfriday renderer to only add mention/hashtag links in... (diff) | |
download | gotosocial-ecb97f4e0bae0735464880cd850e964f292f2e92.tar.xz |
[feature] Add support for the exclude_types[] parameter on the notifications endpoint (#784)
* Add support for the exclude_types[] parameter on the notifications endpoint
* Add swagger docs to notifications
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/bundb/notification.go | 6 | ||||
-rw-r--r-- | internal/db/bundb/notification_test.go | 8 | ||||
-rw-r--r-- | internal/db/notification.go | 2 |
3 files changed, 10 insertions, 6 deletions
diff --git a/internal/db/bundb/notification.go b/internal/db/bundb/notification.go index 034b3b8ec..32523ca24 100644 --- a/internal/db/bundb/notification.go +++ b/internal/db/bundb/notification.go @@ -56,7 +56,7 @@ func (n *notificationDB) GetNotification(ctx context.Context, id string) (*gtsmo return &dst, nil } -func (n *notificationDB) GetNotifications(ctx context.Context, accountID string, limit int, maxID string, sinceID string) ([]*gtsmodel.Notification, db.Error) { +func (n *notificationDB) GetNotifications(ctx context.Context, accountID string, excludeTypes []string, limit int, maxID string, sinceID string) ([]*gtsmodel.Notification, db.Error) { // Ensure reasonable if limit < 0 { limit = 0 @@ -78,6 +78,10 @@ func (n *notificationDB) GetNotifications(ctx context.Context, accountID string, q = q.Where("id > ?", sinceID) } + for _, excludeType := range excludeTypes { + q = q.Where("notification_type != ?", excludeType) + } + q = q. Where("target_account_id = ?", accountID). Order("id DESC") diff --git a/internal/db/bundb/notification_test.go b/internal/db/bundb/notification_test.go index d79c73ad2..704d3373b 100644 --- a/internal/db/bundb/notification_test.go +++ b/internal/db/bundb/notification_test.go @@ -91,7 +91,7 @@ func (suite *NotificationTestSuite) TestGetNotificationsWithSpam() { suite.spamNotifs() testAccount := suite.testAccounts["local_account_1"] before := time.Now() - notifications, err := suite.db.GetNotifications(context.Background(), testAccount.ID, 20, "ZZZZZZZZZZZZZZZZZZZZZZZZZZ", "00000000000000000000000000") + notifications, err := suite.db.GetNotifications(context.Background(), testAccount.ID, []string{}, 20, "ZZZZZZZZZZZZZZZZZZZZZZZZZZ", "00000000000000000000000000") suite.NoError(err) timeTaken := time.Since(before) fmt.Printf("\n\n\n withSpam: got %d notifications in %s\n\n\n", len(notifications), timeTaken) @@ -105,7 +105,7 @@ func (suite *NotificationTestSuite) TestGetNotificationsWithSpam() { func (suite *NotificationTestSuite) TestGetNotificationsWithoutSpam() { testAccount := suite.testAccounts["local_account_1"] before := time.Now() - notifications, err := suite.db.GetNotifications(context.Background(), testAccount.ID, 20, "ZZZZZZZZZZZZZZZZZZZZZZZZZZ", "00000000000000000000000000") + notifications, err := suite.db.GetNotifications(context.Background(), testAccount.ID, []string{}, 20, "ZZZZZZZZZZZZZZZZZZZZZZZZZZ", "00000000000000000000000000") suite.NoError(err) timeTaken := time.Since(before) fmt.Printf("\n\n\n withoutSpam: got %d notifications in %s\n\n\n", len(notifications), timeTaken) @@ -125,7 +125,7 @@ func (suite *NotificationTestSuite) TestClearNotificationsWithSpam() { err := suite.db.ClearNotifications(context.Background(), testAccount.ID) suite.NoError(err) - notifications, err := suite.db.GetNotifications(context.Background(), testAccount.ID, 20, "ZZZZZZZZZZZZZZZZZZZZZZZZZZ", "00000000000000000000000000") + notifications, err := suite.db.GetNotifications(context.Background(), testAccount.ID, []string{}, 20, "ZZZZZZZZZZZZZZZZZZZZZZZZZZ", "00000000000000000000000000") suite.NoError(err) suite.NotNil(notifications) suite.Empty(notifications) @@ -137,7 +137,7 @@ func (suite *NotificationTestSuite) TestClearNotificationsWithTwoAccounts() { err := suite.db.ClearNotifications(context.Background(), testAccount.ID) suite.NoError(err) - notifications, err := suite.db.GetNotifications(context.Background(), testAccount.ID, 20, "ZZZZZZZZZZZZZZZZZZZZZZZZZZ", "00000000000000000000000000") + notifications, err := suite.db.GetNotifications(context.Background(), testAccount.ID, []string{}, 20, "ZZZZZZZZZZZZZZZZZZZZZZZZZZ", "00000000000000000000000000") suite.NoError(err) suite.NotNil(notifications) suite.Empty(notifications) diff --git a/internal/db/notification.go b/internal/db/notification.go index 7d8258d93..14d9b2c47 100644 --- a/internal/db/notification.go +++ b/internal/db/notification.go @@ -29,7 +29,7 @@ type Notification interface { // GetNotifications returns a slice of notifications that pertain to the given accountID. // // Returned notifications will be ordered ID descending (ie., highest/newest to lowest/oldest). - GetNotifications(ctx context.Context, accountID string, limit int, maxID string, sinceID string) ([]*gtsmodel.Notification, Error) + GetNotifications(ctx context.Context, accountID string, excludeTypes []string, limit int, maxID string, sinceID string) ([]*gtsmodel.Notification, Error) // GetNotification returns one notification according to its id. GetNotification(ctx context.Context, id string) (*gtsmodel.Notification, Error) // ClearNotifications deletes every notification that pertain to the given accountID. |