mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[feature] add support for polls + receiving federated status edits (#2330)
This commit is contained in:
@ -114,6 +114,10 @@ func (p *Processor) ProcessFromFediAPI(ctx context.Context, fMsg messages.FromFe
|
||||
// CREATE FLAG/REPORT
|
||||
case ap.ActivityFlag:
|
||||
return p.fediAPI.CreateFlag(ctx, fMsg)
|
||||
|
||||
// CREATE QUESTION
|
||||
case ap.ActivityQuestion:
|
||||
return p.fediAPI.CreatePollVote(ctx, fMsg)
|
||||
}
|
||||
|
||||
// UPDATE SOMETHING
|
||||
@ -170,7 +174,7 @@ func (p *fediAPI) CreateStatus(ctx context.Context, fMsg messages.FromFediAPI) e
|
||||
// Both situations we need to parse account URI to fetch it.
|
||||
accountURI, err := url.Parse(status.AccountURI)
|
||||
if err != nil {
|
||||
return err
|
||||
return gtserror.Newf("error parsing account uri: %w", err)
|
||||
}
|
||||
|
||||
// Ensure that account for this status has been deref'd.
|
||||
@ -180,7 +184,7 @@ func (p *fediAPI) CreateStatus(ctx context.Context, fMsg messages.FromFediAPI) e
|
||||
accountURI,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
return gtserror.Newf("error getting account by uri: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +196,48 @@ func (p *fediAPI) CreateStatus(ctx context.Context, fMsg messages.FromFediAPI) e
|
||||
}
|
||||
|
||||
if err := p.surface.timelineAndNotifyStatus(ctx, status); err != nil {
|
||||
return gtserror.Newf("error timelining status: %w", err)
|
||||
log.Errorf(ctx, "error timelining and notifying status: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *fediAPI) CreatePollVote(ctx context.Context, fMsg messages.FromFediAPI) error {
|
||||
// Cast poll vote type from the worker message.
|
||||
vote, ok := fMsg.GTSModel.(*gtsmodel.PollVote)
|
||||
if !ok {
|
||||
return gtserror.Newf("cannot cast %T -> *gtsmodel.PollVote", fMsg.GTSModel)
|
||||
}
|
||||
|
||||
// Insert the new poll vote in the database.
|
||||
if err := p.state.DB.PutPollVote(ctx, vote); err != nil {
|
||||
return gtserror.Newf("error inserting poll vote in db: %w", err)
|
||||
}
|
||||
|
||||
// Ensure the poll vote is fully populated at this point.
|
||||
if err := p.state.DB.PopulatePollVote(ctx, vote); err != nil {
|
||||
return gtserror.Newf("error populating poll vote from db: %w", err)
|
||||
}
|
||||
|
||||
// Ensure the poll on the vote is fully populated to get origin status.
|
||||
if err := p.state.DB.PopulatePoll(ctx, vote.Poll); err != nil {
|
||||
return gtserror.Newf("error populating poll from db: %w", err)
|
||||
}
|
||||
|
||||
// Get the origin status,
|
||||
// (also set the poll on it).
|
||||
status := vote.Poll.Status
|
||||
status.Poll = vote.Poll
|
||||
|
||||
// Interaction counts changed on the source status, uncache from timelines.
|
||||
p.surface.invalidateStatusFromTimelines(ctx, vote.Poll.StatusID)
|
||||
|
||||
if *status.Local {
|
||||
// These were poll votes in a local status, we need to
|
||||
// federate the updated status model with latest vote counts.
|
||||
if err := p.federate.UpdateStatus(ctx, status); err != nil {
|
||||
log.Errorf(ctx, "error federating status update: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -269,12 +314,10 @@ func (p *fediAPI) CreateFollowReq(ctx context.Context, fMsg messages.FromFediAPI
|
||||
}
|
||||
|
||||
if *followRequest.TargetAccount.Locked {
|
||||
// Account on our instance is locked:
|
||||
// just notify the follow request.
|
||||
// Account on our instance is locked: just notify the follow request.
|
||||
if err := p.surface.notifyFollowRequest(ctx, followRequest); err != nil {
|
||||
return gtserror.Newf("error notifying follow request: %w", err)
|
||||
log.Errorf(ctx, "error notifying follow request: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -291,11 +334,11 @@ func (p *fediAPI) CreateFollowReq(ctx context.Context, fMsg messages.FromFediAPI
|
||||
}
|
||||
|
||||
if err := p.federate.AcceptFollow(ctx, follow); err != nil {
|
||||
return gtserror.Newf("error federating accept follow request: %w", err)
|
||||
log.Errorf(ctx, "error federating follow request accept: %v", err)
|
||||
}
|
||||
|
||||
if err := p.surface.notifyFollow(ctx, follow); err != nil {
|
||||
return gtserror.Newf("error notifying follow: %w", err)
|
||||
log.Errorf(ctx, "error notifying follow: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -313,7 +356,7 @@ func (p *fediAPI) CreateLike(ctx context.Context, fMsg messages.FromFediAPI) err
|
||||
}
|
||||
|
||||
if err := p.surface.notifyFave(ctx, fave); err != nil {
|
||||
return gtserror.Newf("error notifying fave: %w", err)
|
||||
log.Errorf(ctx, "error notifying fave: %v", err)
|
||||
}
|
||||
|
||||
// Interaction counts changed on the faved status;
|
||||
@ -354,11 +397,11 @@ func (p *fediAPI) CreateAnnounce(ctx context.Context, fMsg messages.FromFediAPI)
|
||||
|
||||
// Timeline and notify the announce.
|
||||
if err := p.surface.timelineAndNotifyStatus(ctx, status); err != nil {
|
||||
return gtserror.Newf("error timelining status: %w", err)
|
||||
log.Errorf(ctx, "error timelining and notifying status: %v", err)
|
||||
}
|
||||
|
||||
if err := p.surface.notifyAnnounce(ctx, status); err != nil {
|
||||
return gtserror.Newf("error notifying status: %w", err)
|
||||
log.Errorf(ctx, "error notifying announce: %v", err)
|
||||
}
|
||||
|
||||
// Interaction counts changed on the boosted status;
|
||||
@ -382,7 +425,7 @@ func (p *fediAPI) CreateBlock(ctx context.Context, fMsg messages.FromFediAPI) er
|
||||
block.AccountID,
|
||||
block.TargetAccountID,
|
||||
); err != nil {
|
||||
return gtserror.Newf("%w", err)
|
||||
log.Errorf(ctx, "error wiping items from block -> target's home timeline: %v", err)
|
||||
}
|
||||
|
||||
if err := p.state.Timelines.Home.WipeItemsFromAccountID(
|
||||
@ -390,7 +433,7 @@ func (p *fediAPI) CreateBlock(ctx context.Context, fMsg messages.FromFediAPI) er
|
||||
block.TargetAccountID,
|
||||
block.AccountID,
|
||||
); err != nil {
|
||||
return gtserror.Newf("%w", err)
|
||||
log.Errorf(ctx, "error wiping items from target -> block's home timeline: %v", err)
|
||||
}
|
||||
|
||||
// Now list timelines.
|
||||
@ -399,7 +442,7 @@ func (p *fediAPI) CreateBlock(ctx context.Context, fMsg messages.FromFediAPI) er
|
||||
block.AccountID,
|
||||
block.TargetAccountID,
|
||||
); err != nil {
|
||||
return gtserror.Newf("%w", err)
|
||||
log.Errorf(ctx, "error wiping items from block -> target's list timeline(s): %v", err)
|
||||
}
|
||||
|
||||
if err := p.state.Timelines.List.WipeItemsFromAccountID(
|
||||
@ -407,7 +450,7 @@ func (p *fediAPI) CreateBlock(ctx context.Context, fMsg messages.FromFediAPI) er
|
||||
block.TargetAccountID,
|
||||
block.AccountID,
|
||||
); err != nil {
|
||||
return gtserror.Newf("%w", err)
|
||||
log.Errorf(ctx, "error wiping items from target -> block's list timeline(s): %v", err)
|
||||
}
|
||||
|
||||
// Remove any follows that existed between blocker + blockee.
|
||||
@ -416,10 +459,7 @@ func (p *fediAPI) CreateBlock(ctx context.Context, fMsg messages.FromFediAPI) er
|
||||
block.AccountID,
|
||||
block.TargetAccountID,
|
||||
); err != nil {
|
||||
return gtserror.Newf(
|
||||
"db error deleting follow from %s targeting %s: %w",
|
||||
block.AccountID, block.TargetAccountID, err,
|
||||
)
|
||||
log.Errorf(ctx, "error deleting follow from block -> target: %v", err)
|
||||
}
|
||||
|
||||
if err := p.state.DB.DeleteFollow(
|
||||
@ -427,10 +467,7 @@ func (p *fediAPI) CreateBlock(ctx context.Context, fMsg messages.FromFediAPI) er
|
||||
block.TargetAccountID,
|
||||
block.AccountID,
|
||||
); err != nil {
|
||||
return gtserror.Newf(
|
||||
"db error deleting follow from %s targeting %s: %w",
|
||||
block.TargetAccountID, block.AccountID, err,
|
||||
)
|
||||
log.Errorf(ctx, "error deleting follow from target -> block: %v", err)
|
||||
}
|
||||
|
||||
// Remove any follow requests that existed between blocker + blockee.
|
||||
@ -439,10 +476,7 @@ func (p *fediAPI) CreateBlock(ctx context.Context, fMsg messages.FromFediAPI) er
|
||||
block.AccountID,
|
||||
block.TargetAccountID,
|
||||
); err != nil {
|
||||
return gtserror.Newf(
|
||||
"db error deleting follow request from %s targeting %s: %w",
|
||||
block.AccountID, block.TargetAccountID, err,
|
||||
)
|
||||
log.Errorf(ctx, "error deleting follow request from block -> target: %v", err)
|
||||
}
|
||||
|
||||
if err := p.state.DB.DeleteFollowRequest(
|
||||
@ -450,10 +484,7 @@ func (p *fediAPI) CreateBlock(ctx context.Context, fMsg messages.FromFediAPI) er
|
||||
block.TargetAccountID,
|
||||
block.AccountID,
|
||||
); err != nil {
|
||||
return gtserror.Newf(
|
||||
"db error deleting follow request from %s targeting %s: %w",
|
||||
block.TargetAccountID, block.AccountID, err,
|
||||
)
|
||||
log.Errorf(ctx, "error deleting follow request from target -> block: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -469,7 +500,7 @@ func (p *fediAPI) CreateFlag(ctx context.Context, fMsg messages.FromFediAPI) err
|
||||
// - notify admins by dm / notification
|
||||
|
||||
if err := p.surface.emailReportOpened(ctx, incomingReport); err != nil {
|
||||
return gtserror.Newf("error sending report opened email: %w", err)
|
||||
log.Errorf(ctx, "error emailing report opened: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -497,7 +528,7 @@ func (p *fediAPI) UpdateAccount(ctx context.Context, fMsg messages.FromFediAPI)
|
||||
true, // Force refresh.
|
||||
)
|
||||
if err != nil {
|
||||
return gtserror.Newf("error refreshing updated account: %w", err)
|
||||
log.Errorf(ctx, "error refreshing account: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -514,7 +545,7 @@ func (p *fediAPI) UpdateStatus(ctx context.Context, fMsg messages.FromFediAPI) e
|
||||
apStatus, _ := fMsg.APObjectModel.(ap.Statusable)
|
||||
|
||||
// Fetch up-to-date attach status attachments, etc.
|
||||
_, statusable, err := p.federate.RefreshStatus(
|
||||
status, _, err := p.federate.RefreshStatus(
|
||||
ctx,
|
||||
fMsg.ReceivingAccount.Username,
|
||||
existing,
|
||||
@ -522,12 +553,19 @@ func (p *fediAPI) UpdateStatus(ctx context.Context, fMsg messages.FromFediAPI) e
|
||||
true,
|
||||
)
|
||||
if err != nil {
|
||||
return gtserror.Newf("error refreshing updated status: %w", err)
|
||||
log.Errorf(ctx, "error refreshing status: %v", err)
|
||||
}
|
||||
|
||||
if statusable != nil {
|
||||
// Status representation was refetched, uncache from timelines.
|
||||
p.surface.invalidateStatusFromTimelines(ctx, existing.ID)
|
||||
// Status representation was refetched, uncache from timelines.
|
||||
p.surface.invalidateStatusFromTimelines(ctx, status.ID)
|
||||
|
||||
if status.Poll != nil && status.Poll.Closing {
|
||||
|
||||
// If the latest status has a newly closed poll, at least compared
|
||||
// to the existing version, then notify poll close to all voters.
|
||||
if err := p.surface.notifyPollClose(ctx, status); err != nil {
|
||||
log.Errorf(ctx, "error sending poll notification: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -545,7 +583,7 @@ func (p *fediAPI) DeleteStatus(ctx context.Context, fMsg messages.FromFediAPI) e
|
||||
}
|
||||
|
||||
if err := p.wipeStatus(ctx, status, deleteAttachments); err != nil {
|
||||
return gtserror.Newf("error wiping status: %w", err)
|
||||
log.Errorf(ctx, "error wiping status: %v", err)
|
||||
}
|
||||
|
||||
if status.InReplyToID != "" {
|
||||
@ -564,7 +602,7 @@ func (p *fediAPI) DeleteAccount(ctx context.Context, fMsg messages.FromFediAPI)
|
||||
}
|
||||
|
||||
if err := p.account.Delete(ctx, account, account.ID); err != nil {
|
||||
return gtserror.Newf("error deleting account: %w", err)
|
||||
log.Errorf(ctx, "error deleting account: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Reference in New Issue
Block a user