mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-10 05:48:08 -06:00
[feature] Implement types[] param for notifications (#3009)
Counterpart of exclude_types[]. Also updates Swagger spec for types[] to use the correct param name and enumerate possible values. Fixes #3003
This commit is contained in:
parent
7ab404d643
commit
b08c1bd0cb
10 changed files with 459 additions and 13 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue