diff options
| author | 2025-05-11 13:38:13 +0000 | |
|---|---|---|
| committer | 2025-05-11 13:38:13 +0000 | |
| commit | 8480a758081e84384a366a29ecee3c3103687512 (patch) | |
| tree | d35f56a4b88905fb5f9c3a9f788ac2cf628c92fe /internal/db/bundb/status.go | |
| parent | [bugfix] Fix a11y property warning from authorization page (#4166) (diff) | |
| download | gotosocial-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/status.go')
| -rw-r--r-- | internal/db/bundb/status.go | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/internal/db/bundb/status.go b/internal/db/bundb/status.go index f33362a3d..cf4a2549a 100644 --- a/internal/db/bundb/status.go +++ b/internal/db/bundb/status.go @@ -732,3 +732,105 @@ func (s *statusDB) GetDirectStatusIDsBatch(ctx context.Context, minID string, ma } return statusIDs, nil } + +func (s *statusDB) GetStatusInteractions( + ctx context.Context, + statusID string, + localOnly bool, +) ([]gtsmodel.Interaction, error) { + // Prepare to get interactions. + interactions := []gtsmodel.Interaction{} + + // Gather faves. + faves, err := s.state.DB.GetStatusFaves(ctx, statusID) + if err != nil && !errors.Is(err, db.ErrNoEntries) { + return nil, err + } + + for _, fave := range faves { + // Get account at least. + if fave.Account == nil { + fave.Account, err = s.state.DB.GetAccountByID(ctx, fave.AccountID) + if err != nil { + log.Errorf(ctx, "error getting account for fave: %v", err) + continue + } + } + + if localOnly && !fave.Account.IsLocal() { + // Skip not local. + continue + } + + interactions = append(interactions, fave) + } + + // Gather replies. + replies, err := s.state.DB.GetStatusReplies(ctx, statusID) + if err != nil && !errors.Is(err, db.ErrNoEntries) { + return nil, err + } + + for _, reply := range replies { + // Get account at least. + if reply.Account == nil { + reply.Account, err = s.state.DB.GetAccountByID(ctx, reply.AccountID) + if err != nil { + log.Errorf(ctx, "error getting account for reply: %v", err) + continue + } + } + + if localOnly && !reply.Account.IsLocal() { + // Skip not local. + continue + } + + interactions = append(interactions, reply) + } + + // Gather boosts. + boosts, err := s.state.DB.GetStatusBoosts(ctx, statusID) + if err != nil && !errors.Is(err, db.ErrNoEntries) { + return nil, err + } + + for _, boost := range boosts { + // Get account at least. + if boost.Account == nil { + boost.Account, err = s.state.DB.GetAccountByID(ctx, boost.AccountID) + if err != nil { + log.Errorf(ctx, "error getting account for boost: %v", err) + continue + } + } + + if localOnly && !boost.Account.IsLocal() { + // Skip not local. + continue + } + + interactions = append(interactions, boost) + } + + if len(interactions) == 0 { + return nil, db.ErrNoEntries + } + + return interactions, nil +} + +func (s *statusDB) GetStatusByEditID( + ctx context.Context, + editID string, +) (*gtsmodel.Status, error) { + edit, err := s.state.DB.GetStatusEditByID( + gtscontext.SetBarebones(ctx), + editID, + ) + if err != nil { + return nil, err + } + + return s.GetStatusByID(ctx, edit.StatusID) +} |
