gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit b3fd9c39a3a6ecdac87b27684e7dbc54ce19b312
parent c7cfbe2702913a6d6e7c962992546c96aa512068
Author: tobi <31960611+tsmethurst@users.noreply.github.com>
Date:   Mon, 27 Sep 2021 17:42:20 +0200

Weird notif issue (#248)

* start working on weird issue

* go fmt ./...

* more tests
Diffstat:
Minternal/processing/fromclientapi.go | 2+-
Minternal/processing/fromcommon.go | 13+++++++++++--
Minternal/processing/fromfederator.go | 2+-
Minternal/processing/fromfederator_test.go | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 138 insertions(+), 4 deletions(-)

diff --git a/internal/processing/fromclientapi.go b/internal/processing/fromclientapi.go @@ -73,7 +73,7 @@ func (p *processor) ProcessFromClientAPI(ctx context.Context, clientMsg messages return errors.New("fave was not parseable as *gtsmodel.StatusFave") } - if err := p.notifyFave(ctx, fave, clientMsg.TargetAccount); err != nil { + if err := p.notifyFave(ctx, fave); err != nil { return err } diff --git a/internal/processing/fromcommon.go b/internal/processing/fromcommon.go @@ -190,8 +190,17 @@ func (p *processor) notifyFollow(ctx context.Context, follow *gtsmodel.Follow, t return nil } -func (p *processor) notifyFave(ctx context.Context, fave *gtsmodel.StatusFave, targetAccount *gtsmodel.Account) error { - // return if this isn't a local account +func (p *processor) notifyFave(ctx context.Context, fave *gtsmodel.StatusFave) error { + if fave.TargetAccount == nil { + a, err := p.db.GetAccountByID(ctx, fave.TargetAccountID) + if err != nil { + return err + } + fave.TargetAccount = a + } + targetAccount := fave.TargetAccount + + // just return if target isn't a local account if targetAccount.Domain != "" { return nil } diff --git a/internal/processing/fromfederator.go b/internal/processing/fromfederator.go @@ -73,7 +73,7 @@ func (p *processor) ProcessFromFederator(ctx context.Context, federatorMsg messa return errors.New("like was not parseable as *gtsmodel.StatusFave") } - if err := p.notifyFave(ctx, incomingFave, federatorMsg.ReceivingAccount); err != nil { + if err := p.notifyFave(ctx, incomingFave); err != nil { return err } case ap.ActivityFollow: diff --git a/internal/processing/fromfederator_test.go b/internal/processing/fromfederator_test.go @@ -151,6 +151,131 @@ func (suite *FromFederatorTestSuite) TestProcessReplyMention() { suite.False(notif.Read) } +func (suite *FromFederatorTestSuite) TestProcessFave() { + favedAccount := suite.testAccounts["local_account_1"] + favedStatus := suite.testStatuses["local_account_1_status_1"] + favingAccount := suite.testAccounts["remote_account_1"] + + stream, errWithCode := suite.processor.OpenStreamForAccount(context.Background(), favedAccount, "user") + suite.NoError(errWithCode) + + fave := &gtsmodel.StatusFave{ + ID: "01FGKJPXFTVQPG9YSSZ95ADS7Q", + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + AccountID: favingAccount.ID, + Account: favingAccount, + TargetAccountID: favedAccount.ID, + TargetAccount: favedAccount, + StatusID: favedStatus.ID, + Status: favedStatus, + URI: favingAccount.URI + "/faves/aaaaaaaaaaaa", + } + + err := suite.db.Put(context.Background(), fave) + suite.NoError(err) + + err = suite.processor.ProcessFromFederator(context.Background(), messages.FromFederator{ + APObjectType: ap.ActivityLike, + APActivityType: ap.ActivityCreate, + GTSModel: fave, + ReceivingAccount: favedAccount, + }) + suite.NoError(err) + + // side effects should be triggered + // 1. a notification should exist for the fave + where := []db.Where{ + { + Key: "status_id", + Value: favedStatus.ID, + }, + { + Key: "origin_account_id", + Value: favingAccount.ID, + }, + } + + notif := &gtsmodel.Notification{} + err = suite.db.GetWhere(context.Background(), where, notif) + suite.NoError(err) + suite.Equal(gtsmodel.NotificationFave, notif.NotificationType) + suite.Equal(fave.TargetAccountID, notif.TargetAccountID) + suite.Equal(fave.AccountID, notif.OriginAccountID) + suite.Equal(fave.StatusID, notif.StatusID) + suite.False(notif.Read) + + // 2. a notification should be streamed + msg := <-stream.Messages + suite.Equal("notification", msg.Event) + suite.NotEmpty(msg.Payload) + suite.EqualValues([]string{"user"}, msg.Stream) +} + +// TestProcessFaveWithDifferentReceivingAccount ensures that when an account receives a fave that's for +// another account in their AP inbox, a notification isn't streamed to the receiving account. +// +// This tests for an issue we were seeing where Misskey sends out faves to inboxes of people that don't own +// the fave, but just follow the actor who received the fave. +func (suite *FromFederatorTestSuite) TestProcessFaveWithDifferentReceivingAccount() { + receivingAccount := suite.testAccounts["local_account_2"] + favedAccount := suite.testAccounts["local_account_1"] + favedStatus := suite.testStatuses["local_account_1_status_1"] + favingAccount := suite.testAccounts["remote_account_1"] + + stream, errWithCode := suite.processor.OpenStreamForAccount(context.Background(), receivingAccount, "user") + suite.NoError(errWithCode) + + fave := &gtsmodel.StatusFave{ + ID: "01FGKJPXFTVQPG9YSSZ95ADS7Q", + CreatedAt: time.Now(), + UpdatedAt: time.Now(), + AccountID: favingAccount.ID, + Account: favingAccount, + TargetAccountID: favedAccount.ID, + TargetAccount: favedAccount, + StatusID: favedStatus.ID, + Status: favedStatus, + URI: favingAccount.URI + "/faves/aaaaaaaaaaaa", + } + + err := suite.db.Put(context.Background(), fave) + suite.NoError(err) + + err = suite.processor.ProcessFromFederator(context.Background(), messages.FromFederator{ + APObjectType: ap.ActivityLike, + APActivityType: ap.ActivityCreate, + GTSModel: fave, + ReceivingAccount: receivingAccount, + }) + suite.NoError(err) + + // side effects should be triggered + // 1. a notification should exist for the fave + where := []db.Where{ + { + Key: "status_id", + Value: favedStatus.ID, + }, + { + Key: "origin_account_id", + Value: favingAccount.ID, + }, + } + + notif := &gtsmodel.Notification{} + err = suite.db.GetWhere(context.Background(), where, notif) + suite.NoError(err) + suite.Equal(gtsmodel.NotificationFave, notif.NotificationType) + suite.Equal(fave.TargetAccountID, notif.TargetAccountID) + suite.Equal(fave.AccountID, notif.OriginAccountID) + suite.Equal(fave.StatusID, notif.StatusID) + suite.False(notif.Read) + + // 2. no notification should be streamed to the account that received the fave message, because they weren't the target + suite.Empty(stream.Messages) +} + func TestFromFederatorTestSuite(t *testing.T) { suite.Run(t, &FromFederatorTestSuite{}) }