summaryrefslogtreecommitdiff
path: root/internal/db/bundb/notification.go
diff options
context:
space:
mode:
authorLibravatar tobi <tobi.smethurst@protonmail.com>2025-05-11 13:38:13 +0000
committerLibravatar kim <gruf@noreply.codeberg.org>2025-05-11 13:38:13 +0000
commit8480a758081e84384a366a29ecee3c3103687512 (patch)
treed35f56a4b88905fb5f9c3a9f788ac2cf628c92fe /internal/db/bundb/notification.go
parent[bugfix] Fix a11y property warning from authorization page (#4166) (diff)
downloadgotosocial-8480a758081e84384a366a29ecee3c3103687512.tar.xz
[feature] Notify accounts when a status they've interacted with has been edited (#4157)
This pull request adds sending notifications to local accounts that have interacted with a status, if we receive or create a new edit for that status. closes https://codeberg.org/superseriousbusiness/gotosocial/issues/3991 Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4157 Co-authored-by: tobi <tobi.smethurst@protonmail.com> Co-committed-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/db/bundb/notification.go')
-rw-r--r--internal/db/bundb/notification.go49
1 files changed, 34 insertions, 15 deletions
diff --git a/internal/db/bundb/notification.go b/internal/db/bundb/notification.go
index 77d4861b2..2f4989c33 100644
--- a/internal/db/bundb/notification.go
+++ b/internal/db/bundb/notification.go
@@ -54,24 +54,28 @@ func (n *notificationDB) GetNotificationByID(ctx context.Context, id string) (*g
func (n *notificationDB) GetNotification(
ctx context.Context,
- notificationType gtsmodel.NotificationType,
- targetAccountID string,
- originAccountID string,
- statusID string,
+ notifType gtsmodel.NotificationType,
+ targetAcctID string,
+ originAcctID string,
+ statusOrEditID string,
) (*gtsmodel.Notification, error) {
return n.getNotification(
ctx,
- "NotificationType,TargetAccountID,OriginAccountID,StatusID",
+ "NotificationType,TargetAccountID,OriginAccountID,StatusOrEditID",
func(notif *gtsmodel.Notification) error {
- return n.db.NewSelect().
+ q := n.db.NewSelect().
Model(notif).
- Where("? = ?", bun.Ident("notification_type"), notificationType).
- Where("? = ?", bun.Ident("target_account_id"), targetAccountID).
- Where("? = ?", bun.Ident("origin_account_id"), originAccountID).
- Where("? = ?", bun.Ident("status_id"), statusID).
- Scan(ctx)
+ Where("? = ?", bun.Ident("notification_type"), notifType).
+ Where("? = ?", bun.Ident("target_account_id"), targetAcctID).
+ Where("? = ?", bun.Ident("origin_account_id"), originAcctID)
+
+ if statusOrEditID != "" {
+ q = q.Where("? = ?", bun.Ident("status_id"), statusOrEditID)
+ }
+
+ return q.Scan(ctx)
},
- notificationType, targetAccountID, originAccountID, statusID,
+ notifType, targetAcctID, originAcctID, statusOrEditID,
)
}
@@ -176,14 +180,29 @@ func (n *notificationDB) PopulateNotification(ctx context.Context, notif *gtsmod
}
}
- if notif.StatusID != "" && notif.Status == nil {
+ if notif.StatusOrEditID != "" && notif.Status == nil {
+ // Try getting status by ID first.
notif.Status, err = n.state.DB.GetStatusByID(
gtscontext.SetBarebones(ctx),
- notif.StatusID,
+ notif.StatusOrEditID,
)
- if err != nil {
+ if err != nil && !errors.Is(err, db.ErrNoEntries) {
+ // Only append real db error. It might be an edit ID.
errs.Appendf("error populating notif status: %w", err)
}
+
+ if notif.Status == nil {
+ // If it's still not set, try
+ // getting status by edit ID.
+ notif.Status, err = n.state.DB.GetStatusByEditID(
+ gtscontext.SetBarebones(ctx),
+ notif.StatusOrEditID,
+ )
+ if err != nil {
+ // Append any error here as it's an issue.
+ errs.Appendf("error populating notif status: %w", err)
+ }
+ }
}
return errs.Combine()