From 40add686913b7eb6edd5a780e37e7513b43a337f Mon Sep 17 00:00:00 2001 From: Tobi Smethurst <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 27 May 2021 16:06:24 +0200 Subject: Notifications (#34) Notifications working for: * Mentions * Faves * New follow requests * New followers --- internal/db/db.go | 2 ++ internal/db/pg/pg.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'internal/db') diff --git a/internal/db/db.go b/internal/db/db.go index 9ad811580..e71484a6d 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -284,6 +284,8 @@ type DB interface { // It will use the given filters and try to return as many statuses up to the limit as possible. GetHomeTimelineForAccount(accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, error) + GetNotificationsForAccount(accountID string, limit int, maxID string) ([]*gtsmodel.Notification, error) + /* USEFUL CONVERSION FUNCTIONS */ diff --git a/internal/db/pg/pg.go b/internal/db/pg/pg.go index 7f65055d6..9b6c7a114 100644 --- a/internal/db/pg/pg.go +++ b/internal/db/pg/pg.go @@ -1138,6 +1138,35 @@ func (ps *postgresService) GetHomeTimelineForAccount(accountID string, maxID str return statuses, nil } +func (ps *postgresService) GetNotificationsForAccount(accountID string, limit int, maxID string) ([]*gtsmodel.Notification, error) { + notifications := []*gtsmodel.Notification{} + + q := ps.conn.Model(¬ifications).Where("target_account_id = ?", accountID) + + + if maxID != "" { + n := >smodel.Notification{} + if err := ps.conn.Model(n).Where("id = ?", maxID).Select(); err != nil { + return nil, err + } + q = q.Where("created_at < ?", n.CreatedAt) + } + + if limit != 0 { + q = q.Limit(limit) + } + + q = q.Order("created_at DESC") + + if err := q.Select(); err != nil { + if err != pg.ErrNoRows { + return nil, err + } + + } + return notifications, nil +} + /* CONVERSION FUNCTIONS */ -- cgit v1.2.3