mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-01-26 16:11:55 +00:00
Merge branch 'main' into delivery_recipient_pre_sort
This commit is contained in:
commit
28a54b6253
|
@ -0,0 +1,82 @@
|
|||
// GoToSocial
|
||||
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gtsmodel "github.com/superseriousbusiness/gotosocial/internal/db/bundb/migrations/20241022153016_domain_permission_subscriptions"
|
||||
"github.com/uptrace/bun"
|
||||
)
|
||||
|
||||
// This file exists because tobi is a silly billy and named two migration files
|
||||
// with the same date part, so the latter migration didn't always run properly.
|
||||
// The file just repeats migrations in 20250119112745_domain_permission_subscriptions.go,
|
||||
// which will be a noop in most cases, but will fix some issues for those who
|
||||
// were running snapshots between GtS v0.17.0 and GtS v0.18.0.
|
||||
//
|
||||
// See https://github.com/superseriousbusiness/gotosocial/pull/3679.
|
||||
func init() {
|
||||
up := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
// Create `domain_permission_subscriptions`.
|
||||
if _, err := tx.
|
||||
NewCreateTable().
|
||||
Model((*gtsmodel.DomainPermissionSubscription)(nil)).
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create indexes. Indices. Indie sexes.
|
||||
if _, err := tx.
|
||||
NewCreateIndex().
|
||||
Table("domain_permission_subscriptions").
|
||||
// Filter on permission type.
|
||||
Index("domain_permission_subscriptions_permission_type_idx").
|
||||
Column("permission_type").
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tx.
|
||||
NewCreateIndex().
|
||||
Table("domain_permission_subscriptions").
|
||||
// Sort by priority DESC.
|
||||
Index("domain_permission_subscriptions_priority_order_idx").
|
||||
ColumnExpr("? DESC", bun.Ident("priority")).
|
||||
IfNotExists().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
down := func(ctx context.Context, db *bun.DB) error {
|
||||
return db.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
if err := Migrations.Register(up, down); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@
|
|||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||
)
|
||||
|
||||
func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo) error {
|
||||
|
@ -89,6 +90,18 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
|
|||
return err
|
||||
}
|
||||
|
||||
// UNDO ANNOUNCE
|
||||
case ap.ActivityAnnounce:
|
||||
if err := f.undoAnnounce(
|
||||
ctx,
|
||||
receivingAcct,
|
||||
requestingAcct,
|
||||
undo,
|
||||
asType,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// UNHANDLED
|
||||
default:
|
||||
log.Debugf(ctx, "unhandled object type: %s", name)
|
||||
|
@ -323,3 +336,72 @@ func (f *federatingDB) undoBlock(
|
|||
log.Debug(ctx, "Block undone")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *federatingDB) undoAnnounce(
|
||||
ctx context.Context,
|
||||
receivingAcct *gtsmodel.Account,
|
||||
requestingAcct *gtsmodel.Account,
|
||||
undo vocab.ActivityStreamsUndo,
|
||||
t vocab.Type,
|
||||
) error {
|
||||
asAnnounce, ok := t.(vocab.ActivityStreamsAnnounce)
|
||||
if !ok {
|
||||
err := fmt.Errorf("%T not parseable as vocab.ActivityStreamsAnnounce", t)
|
||||
return gtserror.SetMalformed(err)
|
||||
}
|
||||
|
||||
// Make sure the Undo actor owns the
|
||||
// Announce they're trying to undo.
|
||||
if !sameActor(
|
||||
undo.GetActivityStreamsActor(),
|
||||
asAnnounce.GetActivityStreamsActor(),
|
||||
) {
|
||||
// Ignore this Activity.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Convert AS Announce to *gtsmodel.Status,
|
||||
// retrieving origin account + target status.
|
||||
boost, isNew, err := f.converter.ASAnnounceToStatus(
|
||||
// Use barebones as we don't
|
||||
// need to populate attachments
|
||||
// on boosted status, mentions, etc.
|
||||
gtscontext.SetBarebones(ctx),
|
||||
asAnnounce,
|
||||
)
|
||||
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||
err := gtserror.Newf("error converting AS Announce to boost: %w", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if boost == nil {
|
||||
// We were missing origin or
|
||||
// target(s) for this Announce,
|
||||
// so we cannot Undo anything.
|
||||
return nil
|
||||
}
|
||||
|
||||
if isNew {
|
||||
// We hadn't seen this boost
|
||||
// before anyway, so there's
|
||||
// nothing to Undo.
|
||||
return nil
|
||||
}
|
||||
|
||||
// Ensure requester == announcer.
|
||||
if boost.AccountID != requestingAcct.ID {
|
||||
const text = "requestingAcct was not Block origin"
|
||||
return gtserror.NewErrorForbidden(errors.New(text), text)
|
||||
}
|
||||
|
||||
// Looks valid. Process side effects asynchronously.
|
||||
f.state.Workers.Federator.Queue.Push(&messages.FromFediAPI{
|
||||
APObjectType: ap.ActivityAnnounce,
|
||||
APActivityType: ap.ActivityUndo,
|
||||
GTSModel: boost,
|
||||
Receiving: receivingAcct,
|
||||
Requesting: requestingAcct,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -189,6 +189,14 @@ func (p *Processor) ProcessFromFediAPI(ctx context.Context, fMsg *messages.FromF
|
|||
if fMsg.APObjectType == ap.ActorPerson {
|
||||
return p.fediAPI.MoveAccount(ctx, fMsg)
|
||||
}
|
||||
|
||||
// UNDO SOMETHING
|
||||
case ap.ActivityUndo:
|
||||
|
||||
// UNDO ANNOUNCE
|
||||
if fMsg.APObjectType == ap.ActivityAnnounce {
|
||||
return p.fediAPI.UndoAnnounce(ctx, fMsg)
|
||||
}
|
||||
}
|
||||
|
||||
return gtserror.Newf("unhandled: %s %s", fMsg.APActivityType, fMsg.APObjectType)
|
||||
|
@ -1159,3 +1167,34 @@ func (p *fediAPI) RejectAnnounce(ctx context.Context, fMsg *messages.FromFediAPI
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *fediAPI) UndoAnnounce(
|
||||
ctx context.Context,
|
||||
fMsg *messages.FromFediAPI,
|
||||
) error {
|
||||
boost, ok := fMsg.GTSModel.(*gtsmodel.Status)
|
||||
if !ok {
|
||||
return gtserror.Newf("%T not parseable as *gtsmodel.Status", fMsg.GTSModel)
|
||||
}
|
||||
|
||||
// Delete the boost wrapper itself.
|
||||
if err := p.state.DB.DeleteStatusByID(ctx, boost.ID); err != nil {
|
||||
return gtserror.Newf("db error deleting boost: %w", err)
|
||||
}
|
||||
|
||||
// Update statuses count for the requesting account.
|
||||
if err := p.utils.decrementStatusesCount(ctx, fMsg.Requesting, boost); err != nil {
|
||||
log.Errorf(ctx, "error updating account stats: %v", err)
|
||||
}
|
||||
|
||||
// Remove the boost wrapper from all timelines.
|
||||
if err := p.surface.deleteStatusFromTimelines(ctx, boost.ID); err != nil {
|
||||
log.Errorf(ctx, "error removing timelined boost: %v", err)
|
||||
}
|
||||
|
||||
// Interaction counts changed on the boosted status;
|
||||
// uncache the prepared version from all timelines.
|
||||
p.surface.invalidateStatusFromTimelines(ctx, boost.BoostOfID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
@ -29,6 +30,7 @@
|
|||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/stream"
|
||||
|
@ -679,6 +681,60 @@ func (suite *FromFediAPITestSuite) TestMoveAccount() {
|
|||
suite.WithinDuration(time.Now(), move.SucceededAt, 1*time.Minute)
|
||||
}
|
||||
|
||||
func (suite *FromFediAPITestSuite) TestUndoAnnounce() {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
testStructs = testrig.SetupTestStructs(rMediaPath, rTemplatePath)
|
||||
requestingAcct = suite.testAccounts["remote_account_1"]
|
||||
receivingAcct = suite.testAccounts["local_account_1"]
|
||||
boostedStatus = suite.testStatuses["admin_account_status_1"]
|
||||
)
|
||||
defer testrig.TearDownTestStructs(testStructs)
|
||||
|
||||
// Have remote_account_1 boost admin_account.
|
||||
boost, err := testStructs.TypeConverter.StatusToBoost(
|
||||
ctx,
|
||||
boostedStatus,
|
||||
requestingAcct,
|
||||
"",
|
||||
)
|
||||
if err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
// Set the boost URI + URL to
|
||||
// fossbros-anonymous.io.
|
||||
boost.URI = "https://fossbros-anonymous.io/users/foss_satan/" + boost.ID
|
||||
boost.URL = boost.URI
|
||||
|
||||
// Store the boost.
|
||||
if err := testStructs.State.DB.PutStatus(ctx, boost); err != nil {
|
||||
suite.FailNow(err.Error())
|
||||
}
|
||||
|
||||
// Process the Undo.
|
||||
err = testStructs.Processor.Workers().ProcessFromFediAPI(ctx, &messages.FromFediAPI{
|
||||
APObjectType: ap.ActivityAnnounce,
|
||||
APActivityType: ap.ActivityUndo,
|
||||
GTSModel: boost,
|
||||
Receiving: receivingAcct,
|
||||
Requesting: requestingAcct,
|
||||
})
|
||||
suite.NoError(err)
|
||||
|
||||
// Wait for side effects to trigger:
|
||||
// the boost should be deleted.
|
||||
if !testrig.WaitFor(func() bool {
|
||||
_, err := testStructs.State.DB.GetStatusByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
boost.ID,
|
||||
)
|
||||
return errors.Is(err, db.ErrNoEntries)
|
||||
}) {
|
||||
suite.FailNow("timed out waiting for boost to be removed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFromFederatorTestSuite(t *testing.T) {
|
||||
suite.Run(t, &FromFediAPITestSuite{})
|
||||
}
|
||||
|
|
|
@ -436,6 +436,10 @@ main {
|
|||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
column-gap: 1rem;
|
||||
|
||||
.edited-at {
|
||||
font-style: italic;
|
||||
}
|
||||
}
|
||||
|
||||
.stats-item {
|
||||
|
@ -443,7 +447,7 @@ main {
|
|||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.stats-item:not(.published-at) {
|
||||
.stats-item:not(.published-at):not(.edited-at) {
|
||||
z-index: 1;
|
||||
user-select: none;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,14 @@
|
|||
<time datetime="{{- .CreatedAt -}}">{{- .CreatedAt | timestampPrecise -}}</time>
|
||||
</dd>
|
||||
</div>
|
||||
{{- if .EditedAt -}}
|
||||
<div class="stats-item edited-at text-cutoff">
|
||||
<dt class="sr-only">Edited</dt>
|
||||
<dd>
|
||||
(last edited <time datetime="{{- .EditedAt -}}">{{- .EditedAt | timestampPrecise -}}</time>)
|
||||
</dd>
|
||||
</div>
|
||||
{{ end }}
|
||||
<div class="stats-grouping">
|
||||
<div class="stats-item" title="Replies">
|
||||
<dt>
|
||||
|
|
Loading…
Reference in a new issue