diff options
Diffstat (limited to 'internal/db/bundb/status.go')
-rw-r--r-- | internal/db/bundb/status.go | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/internal/db/bundb/status.go b/internal/db/bundb/status.go index 26f0c1f38..0bd4ba1a9 100644 --- a/internal/db/bundb/status.go +++ b/internal/db/bundb/status.go @@ -324,6 +324,23 @@ func (s *statusDB) PutStatus(ctx context.Context, status *gtsmodel.Status) error } } + // If the status is threaded, create + // link between thread and status. + if status.ThreadID != "" { + if _, err := tx. + NewInsert(). + Model(>smodel.ThreadToStatus{ + ThreadID: status.ThreadID, + StatusID: status.ID, + }). + On("CONFLICT (?, ?) DO NOTHING", bun.Ident("thread_id"), bun.Ident("status_id")). + Exec(ctx); err != nil { + if !errors.Is(err, db.ErrAlreadyExists) { + return err + } + } + } + // Finally, insert the status _, err := tx.NewInsert().Model(status).Exec(ctx) return err @@ -390,6 +407,23 @@ func (s *statusDB) UpdateStatus(ctx context.Context, status *gtsmodel.Status, co } } + // If the status is threaded, create + // link between thread and status. + if status.ThreadID != "" { + if _, err := tx. + NewInsert(). + Model(>smodel.ThreadToStatus{ + ThreadID: status.ThreadID, + StatusID: status.ID, + }). + On("CONFLICT (?, ?) DO NOTHING", bun.Ident("thread_id"), bun.Ident("status_id")). + Exec(ctx); err != nil { + if !errors.Is(err, db.ErrAlreadyExists) { + return err + } + } + } + // Finally, update the status _, err := tx. NewUpdate(). @@ -439,6 +473,17 @@ func (s *statusDB) DeleteStatusByID(ctx context.Context, id string) error { return err } + // Delete links between this status + // and any threads it was a part of. + _, err = tx. + NewDelete(). + TableExpr("? AS ?", bun.Ident("thread_to_statuses"), bun.Ident("thread_to_status")). + Where("? = ?", bun.Ident("thread_to_status.status_id"), id). + Exec(ctx) + if err != nil { + return err + } + // delete the status itself if _, err := tx. NewDelete(). @@ -634,16 +679,6 @@ func (s *statusDB) getStatusBoostIDs(ctx context.Context, statusID string) ([]st }) } -func (s *statusDB) IsStatusMutedBy(ctx context.Context, status *gtsmodel.Status, accountID string) (bool, error) { - q := s.db. - NewSelect(). - TableExpr("? AS ?", bun.Ident("status_mutes"), bun.Ident("status_mute")). - Where("? = ?", bun.Ident("status_mute.status_id"), status.ID). - Where("? = ?", bun.Ident("status_mute.account_id"), accountID) - - return s.db.Exists(ctx, q) -} - func (s *statusDB) IsStatusBookmarkedBy(ctx context.Context, status *gtsmodel.Status, accountID string) (bool, error) { q := s.db. NewSelect(). |