summaryrefslogtreecommitdiff
path: root/internal/processing/workers/fromclientapi_test.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-10-25 16:04:53 +0200
committerLibravatar GitHub <noreply@github.com>2023-10-25 15:04:53 +0100
commitc7b6cd7770cad9bfdc23decffa7c4068752dbbbd (patch)
tree0f039fd34fb0287860fce06ff1c30dedd1882136 /internal/processing/workers/fromclientapi_test.go
parent[bugfix] allow store smaller PNG image than 261 bytes (#2263) (#2298) (diff)
downloadgotosocial-c7b6cd7770cad9bfdc23decffa7c4068752dbbbd.tar.xz
[feature] Status thread mute/unmute functionality (#2278)
* add db models + functions for keeping track of threads * give em the old linty testy * create, remove, check mutes * swagger * testerino * test mute/unmute via api * add info log about new index creation * thread + allow muting of any remote statuses that mention a local account * IsStatusThreadMutedBy -> IsThreadMutedByAccount * use common processing functions in status processor * set = NULL * favee! * get rekt darlings, darlings get rekt * testrig please, have mercy muy liege
Diffstat (limited to 'internal/processing/workers/fromclientapi_test.go')
-rw-r--r--internal/processing/workers/fromclientapi_test.go109
1 files changed, 109 insertions, 0 deletions
diff --git a/internal/processing/workers/fromclientapi_test.go b/internal/processing/workers/fromclientapi_test.go
index e5a098c31..05526f437 100644
--- a/internal/processing/workers/fromclientapi_test.go
+++ b/internal/processing/workers/fromclientapi_test.go
@@ -75,6 +75,7 @@ func (suite *FromClientAPITestSuite) newStatus(
newStatus.InReplyToAccountID = replyToStatus.AccountID
newStatus.InReplyToID = replyToStatus.ID
newStatus.InReplyToURI = replyToStatus.URI
+ newStatus.ThreadID = replyToStatus.ThreadID
// Mention the replied-to account.
mention := &gtsmodel.Mention{
@@ -324,6 +325,114 @@ func (suite *FromClientAPITestSuite) TestProcessCreateStatusReply() {
)
}
+func (suite *FromClientAPITestSuite) TestProcessCreateStatusReplyMuted() {
+ var (
+ ctx = context.Background()
+ postingAccount = suite.testAccounts["admin_account"]
+ receivingAccount = suite.testAccounts["local_account_1"]
+
+ // Admin account posts a reply to zork.
+ // Normally zork would get a notification
+ // for this, but zork mutes this thread.
+ status = suite.newStatus(
+ ctx,
+ postingAccount,
+ gtsmodel.VisibilityPublic,
+ suite.testStatuses["local_account_1_status_1"],
+ nil,
+ )
+ threadMute = &gtsmodel.ThreadMute{
+ ID: "01HD3KRMBB1M85QRWHD912QWRE",
+ ThreadID: suite.testStatuses["local_account_1_status_1"].ThreadID,
+ AccountID: receivingAccount.ID,
+ }
+ )
+
+ // Store the thread mute before processing new status.
+ if err := suite.db.PutThreadMute(ctx, threadMute); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // Process the new status.
+ if err := suite.processor.Workers().ProcessFromClientAPI(
+ ctx,
+ messages.FromClientAPI{
+ APObjectType: ap.ObjectNote,
+ APActivityType: ap.ActivityCreate,
+ GTSModel: status,
+ OriginAccount: postingAccount,
+ },
+ ); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // Ensure no notification received.
+ notif, err := suite.db.GetNotification(
+ ctx,
+ gtsmodel.NotificationMention,
+ receivingAccount.ID,
+ postingAccount.ID,
+ status.ID,
+ )
+
+ suite.ErrorIs(err, db.ErrNoEntries)
+ suite.Nil(notif)
+}
+
+func (suite *FromClientAPITestSuite) TestProcessCreateStatusBoostMuted() {
+ var (
+ ctx = context.Background()
+ postingAccount = suite.testAccounts["admin_account"]
+ receivingAccount = suite.testAccounts["local_account_1"]
+
+ // Admin account boosts a status by zork.
+ // Normally zork would get a notification
+ // for this, but zork mutes this thread.
+ status = suite.newStatus(
+ ctx,
+ postingAccount,
+ gtsmodel.VisibilityPublic,
+ nil,
+ suite.testStatuses["local_account_1_status_1"],
+ )
+ threadMute = &gtsmodel.ThreadMute{
+ ID: "01HD3KRMBB1M85QRWHD912QWRE",
+ ThreadID: suite.testStatuses["local_account_1_status_1"].ThreadID,
+ AccountID: receivingAccount.ID,
+ }
+ )
+
+ // Store the thread mute before processing new status.
+ if err := suite.db.PutThreadMute(ctx, threadMute); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // Process the new status.
+ if err := suite.processor.Workers().ProcessFromClientAPI(
+ ctx,
+ messages.FromClientAPI{
+ APObjectType: ap.ActivityAnnounce,
+ APActivityType: ap.ActivityCreate,
+ GTSModel: status,
+ OriginAccount: postingAccount,
+ },
+ ); err != nil {
+ suite.FailNow(err.Error())
+ }
+
+ // Ensure no notification received.
+ notif, err := suite.db.GetNotification(
+ ctx,
+ gtsmodel.NotificationReblog,
+ receivingAccount.ID,
+ postingAccount.ID,
+ status.ID,
+ )
+
+ suite.ErrorIs(err, db.ErrNoEntries)
+ suite.Nil(notif)
+}
+
func (suite *FromClientAPITestSuite) TestProcessCreateStatusListRepliesPolicyListOnlyOK() {
// We're modifying the test list so take a copy.
testList := new(gtsmodel.List)