summaryrefslogtreecommitdiff
path: root/internal/processing/notification.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-04-29 18:29:51 +0200
committerLibravatar GitHub <noreply@github.com>2023-04-29 17:29:51 +0100
commit8b1e2288d80a723a0c51770f0427fb6c7e07a366 (patch)
tree93970e7138dffdc320e8bb28671548be88d44001 /internal/processing/notification.go
parent[bugfix] add From to email header (#1717) (diff)
downloadgotosocial-8b1e2288d80a723a0c51770f0427fb6c7e07a366.tar.xz
[feature] Add GET endpoint for single notification (#1719)
Diffstat (limited to 'internal/processing/notification.go')
-rw-r--r--internal/processing/notification.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/processing/notification.go b/internal/processing/notification.go
index 48c8f92ac..1cfe71b28 100644
--- a/internal/processing/notification.go
+++ b/internal/processing/notification.go
@@ -20,10 +20,12 @@ package processing
import (
"context"
"errors"
+ "fmt"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/util"
@@ -72,6 +74,35 @@ func (p *Processor) NotificationsGet(ctx context.Context, authed *oauth.Auth, ex
})
}
+func (p *Processor) NotificationGet(ctx context.Context, account *gtsmodel.Account, targetNotifID string) (*apimodel.Notification, gtserror.WithCode) {
+ notif, err := p.state.DB.GetNotificationByID(ctx, targetNotifID)
+ if err != nil {
+ if errors.Is(err, db.ErrNoEntries) {
+ return nil, gtserror.NewErrorNotFound(err)
+ }
+
+ // Real error.
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ if notifTargetAccountID := notif.TargetAccountID; notifTargetAccountID != account.ID {
+ err = fmt.Errorf("account %s does not have permission to view notification belong to account %s", account.ID, notifTargetAccountID)
+ return nil, gtserror.NewErrorNotFound(err)
+ }
+
+ apiNotif, err := p.tc.NotificationToAPINotification(ctx, notif)
+ if err != nil {
+ if errors.Is(err, db.ErrNoEntries) {
+ return nil, gtserror.NewErrorNotFound(err)
+ }
+
+ // Real error.
+ return nil, gtserror.NewErrorInternalError(err)
+ }
+
+ return apiNotif, nil
+}
+
func (p *Processor) NotificationsClear(ctx context.Context, authed *oauth.Auth) gtserror.WithCode {
// Delete all notifications of all types that target the authorized account.
if err := p.state.DB.DeleteNotifications(ctx, nil, authed.Account.ID, ""); err != nil && !errors.Is(err, db.ErrNoEntries) {