summaryrefslogtreecommitdiff
path: root/internal/processing/fromclientapi.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-06-11 11:18:44 +0200
committerLibravatar GitHub <noreply@github.com>2023-06-11 10:18:44 +0100
commit5e2897e35cd2bea889fa37a2a857f4dcc076dafc (patch)
treeb1ac6203ffa20f5fff1c460fed942854a6e5c6bd /internal/processing/fromclientapi.go
parent[docs] Revamp the installation guide (#1877) (diff)
downloadgotosocial-5e2897e35cd2bea889fa37a2a857f4dcc076dafc.tar.xz
[bugfix] Invalidate timeline entries for status when stats change (#1879)
Diffstat (limited to 'internal/processing/fromclientapi.go')
-rw-r--r--internal/processing/fromclientapi.go124
1 files changed, 89 insertions, 35 deletions
diff --git a/internal/processing/fromclientapi.go b/internal/processing/fromclientapi.go
index 41bf6ee40..159f09d1b 100644
--- a/internal/processing/fromclientapi.go
+++ b/internal/processing/fromclientapi.go
@@ -28,6 +28,7 @@ import (
"github.com/superseriousbusiness/activity/pub"
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/gotosocial/internal/ap"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/messages"
@@ -157,14 +158,24 @@ func (p *Processor) processCreateAccountFromClientAPI(ctx context.Context, clien
func (p *Processor) processCreateStatusFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
status, ok := clientMsg.GTSModel.(*gtsmodel.Status)
if !ok {
- return errors.New("note was not parseable as *gtsmodel.Status")
+ return gtserror.New("status was not parseable as *gtsmodel.Status")
}
if err := p.timelineAndNotifyStatus(ctx, status); err != nil {
- return err
+ return gtserror.Newf("error timelining status: %w", err)
+ }
+
+ if status.InReplyToID != "" {
+ // Interaction counts changed on the replied status;
+ // uncache the prepared version from all timelines.
+ p.invalidateStatusFromTimelines(ctx, status.InReplyToID)
+ }
+
+ if err := p.federateStatus(ctx, status); err != nil {
+ return gtserror.Newf("error federating status: %w", err)
}
- return p.federateStatus(ctx, status)
+ return nil
}
func (p *Processor) processCreateFollowRequestFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
@@ -181,33 +192,50 @@ func (p *Processor) processCreateFollowRequestFromClientAPI(ctx context.Context,
}
func (p *Processor) processCreateFaveFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
- fave, ok := clientMsg.GTSModel.(*gtsmodel.StatusFave)
+ statusFave, ok := clientMsg.GTSModel.(*gtsmodel.StatusFave)
if !ok {
- return errors.New("fave was not parseable as *gtsmodel.StatusFave")
+ return gtserror.New("statusFave was not parseable as *gtsmodel.StatusFave")
}
- if err := p.notifyFave(ctx, fave); err != nil {
- return err
+ if err := p.notifyFave(ctx, statusFave); err != nil {
+ return gtserror.Newf("error notifying status fave: %w", err)
+ }
+
+ // Interaction counts changed on the faved status;
+ // uncache the prepared version from all timelines.
+ p.invalidateStatusFromTimelines(ctx, statusFave.StatusID)
+
+ if err := p.federateFave(ctx, statusFave, clientMsg.OriginAccount, clientMsg.TargetAccount); err != nil {
+ return gtserror.Newf("error federating status fave: %w", err)
}
- return p.federateFave(ctx, fave, clientMsg.OriginAccount, clientMsg.TargetAccount)
+ return nil
}
func (p *Processor) processCreateAnnounceFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
- boostWrapperStatus, ok := clientMsg.GTSModel.(*gtsmodel.Status)
+ status, ok := clientMsg.GTSModel.(*gtsmodel.Status)
if !ok {
return errors.New("boost was not parseable as *gtsmodel.Status")
}
- if err := p.timelineAndNotifyStatus(ctx, boostWrapperStatus); err != nil {
- return err
+ // Timeline and notify.
+ if err := p.timelineAndNotifyStatus(ctx, status); err != nil {
+ return gtserror.Newf("error timelining boost: %w", err)
}
- if err := p.notifyAnnounce(ctx, boostWrapperStatus); err != nil {
- return err
+ if err := p.notifyAnnounce(ctx, status); err != nil {
+ return gtserror.Newf("error notifying boost: %w", err)
}
- return p.federateAnnounce(ctx, boostWrapperStatus, clientMsg.OriginAccount, clientMsg.TargetAccount)
+ // Interaction counts changed on the boosted status;
+ // uncache the prepared version from all timelines.
+ p.invalidateStatusFromTimelines(ctx, status.BoostOfID)
+
+ if err := p.federateAnnounce(ctx, status, clientMsg.OriginAccount, clientMsg.TargetAccount); err != nil {
+ return gtserror.Newf("error federating boost: %w", err)
+ }
+
+ return nil
}
func (p *Processor) processCreateBlockFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
@@ -293,50 +321,76 @@ func (p *Processor) processUndoBlockFromClientAPI(ctx context.Context, clientMsg
}
func (p *Processor) processUndoFaveFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
- fave, ok := clientMsg.GTSModel.(*gtsmodel.StatusFave)
+ statusFave, ok := clientMsg.GTSModel.(*gtsmodel.StatusFave)
if !ok {
- return errors.New("undo was not parseable as *gtsmodel.StatusFave")
+ return gtserror.New("statusFave was not parseable as *gtsmodel.StatusFave")
}
- return p.federateUnfave(ctx, fave, clientMsg.OriginAccount, clientMsg.TargetAccount)
+
+ // Interaction counts changed on the faved status;
+ // uncache the prepared version from all timelines.
+ p.invalidateStatusFromTimelines(ctx, statusFave.StatusID)
+
+ if err := p.federateUnfave(ctx, statusFave, clientMsg.OriginAccount, clientMsg.TargetAccount); err != nil {
+ return gtserror.Newf("error federating status unfave: %w", err)
+ }
+
+ return nil
}
func (p *Processor) processUndoAnnounceFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
- boost, ok := clientMsg.GTSModel.(*gtsmodel.Status)
+ status, ok := clientMsg.GTSModel.(*gtsmodel.Status)
if !ok {
- return errors.New("undo was not parseable as *gtsmodel.Status")
+ return errors.New("boost was not parseable as *gtsmodel.Status")
}
- if err := p.state.DB.DeleteStatusByID(ctx, boost.ID); err != nil {
- return err
+ if err := p.state.DB.DeleteStatusByID(ctx, status.ID); err != nil {
+ return gtserror.Newf("db error deleting boost: %w", err)
}
- if err := p.deleteStatusFromTimelines(ctx, boost); err != nil {
- return err
+ if err := p.deleteStatusFromTimelines(ctx, status.ID); err != nil {
+ return gtserror.Newf("error removing boost from timelines: %w", err)
}
- return p.federateUnannounce(ctx, boost, clientMsg.OriginAccount, clientMsg.TargetAccount)
+ // Interaction counts changed on the boosted status;
+ // uncache the prepared version from all timelines.
+ p.invalidateStatusFromTimelines(ctx, status.BoostOfID)
+
+ if err := p.federateUnannounce(ctx, status, clientMsg.OriginAccount, clientMsg.TargetAccount); err != nil {
+ return gtserror.Newf("error federating status unboost: %w", err)
+ }
+
+ return nil
}
func (p *Processor) processDeleteStatusFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {
- statusToDelete, ok := clientMsg.GTSModel.(*gtsmodel.Status)
+ status, ok := clientMsg.GTSModel.(*gtsmodel.Status)
if !ok {
- return errors.New("note was not parseable as *gtsmodel.Status")
+ return gtserror.New("status was not parseable as *gtsmodel.Status")
}
- if statusToDelete.Account == nil {
- statusToDelete.Account = clientMsg.OriginAccount
+ if err := p.state.DB.PopulateStatus(ctx, status); err != nil {
+ return gtserror.Newf("db error populating status: %w", err)
}
- // don't delete attachments, just unattach them;
- // since this request comes from the client API
- // and the poster might want to use the attachments
- // again in a new post
+ // Don't delete attachments, just unattach them: this
+ // request comes from the client API and the poster
+ // may want to use attachments again in a new post.
deleteAttachments := false
- if err := p.wipeStatus(ctx, statusToDelete, deleteAttachments); err != nil {
- return err
+ if err := p.wipeStatus(ctx, status, deleteAttachments); err != nil {
+ return gtserror.Newf("error wiping status: %w", err)
}
- return p.federateStatusDelete(ctx, statusToDelete)
+ if status.InReplyToID != "" {
+ // Interaction counts changed on the replied status;
+ // uncache the prepared version from all timelines.
+ p.invalidateStatusFromTimelines(ctx, status.InReplyToID)
+ }
+
+ if err := p.federateStatusDelete(ctx, status); err != nil {
+ return gtserror.Newf("error federating status delete: %w", err)
+ }
+
+ return nil
}
func (p *Processor) processDeleteAccountFromClientAPI(ctx context.Context, clientMsg messages.FromClientAPI) error {