summaryrefslogtreecommitdiff
path: root/internal/processing/conversations
diff options
context:
space:
mode:
Diffstat (limited to 'internal/processing/conversations')
-rw-r--r--internal/processing/conversations/conversations.go38
-rw-r--r--internal/processing/conversations/conversations_test.go3
-rw-r--r--internal/processing/conversations/get.go24
-rw-r--r--internal/processing/conversations/read.go16
-rw-r--r--internal/processing/conversations/update.go53
5 files changed, 76 insertions, 58 deletions
diff --git a/internal/processing/conversations/conversations.go b/internal/processing/conversations/conversations.go
index 70fafa437..b80ba659a 100644
--- a/internal/processing/conversations/conversations.go
+++ b/internal/processing/conversations/conversations.go
@@ -23,6 +23,7 @@ import (
"code.superseriousbusiness.org/gotosocial/internal/db"
"code.superseriousbusiness.org/gotosocial/internal/filter/mutes"
+ "code.superseriousbusiness.org/gotosocial/internal/filter/status"
"code.superseriousbusiness.org/gotosocial/internal/filter/visibility"
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
@@ -31,10 +32,11 @@ import (
)
type Processor struct {
- state *state.State
- converter *typeutils.Converter
- visFilter *visibility.Filter
- muteFilter *mutes.Filter
+ state *state.State
+ converter *typeutils.Converter
+ visFilter *visibility.Filter
+ muteFilter *mutes.Filter
+ statusFilter *status.Filter
}
func New(
@@ -42,12 +44,14 @@ func New(
converter *typeutils.Converter,
visFilter *visibility.Filter,
muteFilter *mutes.Filter,
+ statusFilter *status.Filter,
) Processor {
return Processor{
- state: state,
- converter: converter,
- visFilter: visFilter,
- muteFilter: muteFilter,
+ state: state,
+ converter: converter,
+ visFilter: visFilter,
+ muteFilter: muteFilter,
+ statusFilter: statusFilter,
}
}
@@ -95,21 +99,3 @@ func (p *Processor) getConversationOwnedBy(
return conversation, nil
}
-
-// getFiltersAndMutes gets the given account's filters and compiled mute list.
-func (p *Processor) getFilters(
- ctx context.Context,
- requestingAccount *gtsmodel.Account,
-) ([]*gtsmodel.Filter, gtserror.WithCode) {
- filters, err := p.state.DB.GetFiltersByAccountID(ctx, requestingAccount.ID)
- if err != nil {
- return nil, gtserror.NewErrorInternalError(
- gtserror.Newf(
- "DB error getting filters for account %s: %w",
- requestingAccount.ID,
- err,
- ),
- )
- }
- return filters, nil
-}
diff --git a/internal/processing/conversations/conversations_test.go b/internal/processing/conversations/conversations_test.go
index 383938564..407623964 100644
--- a/internal/processing/conversations/conversations_test.go
+++ b/internal/processing/conversations/conversations_test.go
@@ -28,6 +28,7 @@ import (
"code.superseriousbusiness.org/gotosocial/internal/email"
"code.superseriousbusiness.org/gotosocial/internal/federation"
"code.superseriousbusiness.org/gotosocial/internal/filter/mutes"
+ "code.superseriousbusiness.org/gotosocial/internal/filter/status"
"code.superseriousbusiness.org/gotosocial/internal/filter/visibility"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
"code.superseriousbusiness.org/gotosocial/internal/log"
@@ -118,7 +119,7 @@ func (suite *ConversationsTestSuite) SetupTest() {
suite.sentEmails = make(map[string]string)
suite.emailSender = testrig.NewEmailSender("../../../web/template/", suite.sentEmails)
- suite.conversationsProcessor = conversations.New(&suite.state, suite.tc, suite.visFilter, suite.muteFilter)
+ suite.conversationsProcessor = conversations.New(&suite.state, suite.tc, suite.visFilter, suite.muteFilter, status.NewFilter(&suite.state))
testrig.StandardDBSetup(suite.db, nil)
testrig.StandardStorageSetup(suite.storage, "../../../testrig/media")
diff --git a/internal/processing/conversations/get.go b/internal/processing/conversations/get.go
index 5324466c9..cdc0756c3 100644
--- a/internal/processing/conversations/get.go
+++ b/internal/processing/conversations/get.go
@@ -64,17 +64,26 @@ func (p *Processor) GetAll(
items := make([]interface{}, 0, count)
- filters, errWithCode := p.getFilters(ctx, requestingAccount)
- if errWithCode != nil {
- return nil, errWithCode
- }
-
for _, conversation := range conversations {
+ // Check whether status if filtered by local participant in context.
+ filtered, hide, err := p.statusFilter.StatusFilterResultsInContext(ctx,
+ requestingAccount,
+ conversation.LastStatus,
+ gtsmodel.FilterContextNotifications,
+ )
+ if err != nil {
+ log.Errorf(ctx, "error filtering status: %v", err)
+ continue
+ }
+
+ if hide {
+ continue
+ }
+
// Convert conversation to frontend API model.
apiConversation, err := p.converter.ConversationToAPIConversation(ctx,
conversation,
requestingAccount,
- filters,
)
if err != nil {
log.Errorf(ctx,
@@ -85,6 +94,9 @@ func (p *Processor) GetAll(
continue
}
+ // Set filter results on attached status model.
+ apiConversation.LastStatus.Filtered = filtered
+
// Append conversation to return items.
items = append(items, apiConversation)
}
diff --git a/internal/processing/conversations/read.go b/internal/processing/conversations/read.go
index 4d16a4eeb..c7e4f1acd 100644
--- a/internal/processing/conversations/read.go
+++ b/internal/processing/conversations/read.go
@@ -23,6 +23,7 @@ import (
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
"code.superseriousbusiness.org/gotosocial/internal/gtserror"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
+ "code.superseriousbusiness.org/gotosocial/internal/log"
"code.superseriousbusiness.org/gotosocial/internal/util"
)
@@ -44,20 +45,27 @@ func (p *Processor) Read(
return nil, gtserror.NewErrorInternalError(err)
}
- filters, errWithCode := p.getFilters(ctx, requestingAccount)
- if errWithCode != nil {
- return nil, errWithCode
+ // Check whether status if filtered by local participant in context.
+ filtered, _, err := p.statusFilter.StatusFilterResultsInContext(ctx,
+ requestingAccount,
+ conversation.LastStatus,
+ gtsmodel.FilterContextNotifications,
+ )
+ if err != nil {
+ log.Errorf(ctx, "error filtering status: %v", err)
}
apiConversation, err := p.converter.ConversationToAPIConversation(ctx,
conversation,
requestingAccount,
- filters,
)
if err != nil {
err = gtserror.Newf("error converting conversation %s to API representation: %w", id, err)
return nil, gtserror.NewErrorInternalError(err)
}
+ // Set filter results on attached status model.
+ apiConversation.LastStatus.Filtered = filtered
+
return apiConversation, nil
}
diff --git a/internal/processing/conversations/update.go b/internal/processing/conversations/update.go
index cf81d6906..21f1cf915 100644
--- a/internal/processing/conversations/update.go
+++ b/internal/processing/conversations/update.go
@@ -27,7 +27,6 @@ import (
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
"code.superseriousbusiness.org/gotosocial/internal/id"
"code.superseriousbusiness.org/gotosocial/internal/log"
- "code.superseriousbusiness.org/gotosocial/internal/typeutils"
"code.superseriousbusiness.org/gotosocial/internal/util"
)
@@ -158,26 +157,6 @@ func (p *Processor) UpdateConversationsForStatus(ctx context.Context, status *gt
continue
}
- // Convert the conversation to API representation.
- apiConversation, err := p.converter.ConversationToAPIConversation(ctx,
- conversation,
- localAccount,
- nil,
- )
- if err != nil {
- // If the conversation's last status matched a hide filter, skip it.
- // If there was another kind of error, log that and skip it anyway.
- if !errors.Is(err, typeutils.ErrHideStatus) {
- log.Errorf(ctx,
- "error converting conversation %s to API representation for account %s: %v",
- status.ID,
- localAccount.ID,
- err,
- )
- }
- continue
- }
-
// If status was authored by this participant,
// don't bother notifying, they already know!
if status.AccountID == localAccount.ID {
@@ -198,6 +177,38 @@ func (p *Processor) UpdateConversationsForStatus(ctx context.Context, status *gt
continue
}
+ // Check whether status if filtered by local participant in context.
+ filtered, hide, err := p.statusFilter.StatusFilterResultsInContext(ctx,
+ localAccount,
+ status,
+ gtsmodel.FilterContextNotifications,
+ )
+ if err != nil {
+ log.Errorf(ctx, "error filtering status: %v", err)
+ continue
+ }
+
+ if hide {
+ continue
+ }
+
+ // Convert the conversation to API representation.
+ apiConversation, err := p.converter.ConversationToAPIConversation(ctx,
+ conversation,
+ localAccount,
+ )
+ if err != nil {
+ log.Errorf(ctx, "error converting conversation %s to API representation for account %s: %v",
+ status.ID,
+ localAccount.ID,
+ err,
+ )
+ continue
+ }
+
+ // Set filter results on attached status model.
+ apiConversation.LastStatus.Filtered = filtered
+
// Generate a notification,
notifications = append(notifications, ConversationNotification{
AccountID: localAccount.ID,