summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
authorLibravatar Vyr Cossont <VyrCossont@users.noreply.github.com>2024-06-07 01:51:13 -0700
committerLibravatar GitHub <noreply@github.com>2024-06-07 10:51:13 +0200
commitafcfa48a7dfc87e35ba32c42b1f37405565a5087 (patch)
tree2639a14b80046914e83f8a7f08f041e6cdfc19d4 /internal/processing
parent[bugfix] Filter fixes (#2971) (diff)
downloadgotosocial-afcfa48a7dfc87e35ba32c42b1f37405565a5087.tar.xz
[feature] Implement filters_changed stream event (#2972)
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/filters/v1/create.go10
-rw-r--r--internal/processing/filters/v1/delete.go3
-rw-r--r--internal/processing/filters/v1/filters.go5
-rw-r--r--internal/processing/filters/v1/update.go10
-rw-r--r--internal/processing/filters/v2/create.go10
-rw-r--r--internal/processing/filters/v2/delete.go3
-rw-r--r--internal/processing/filters/v2/filters.go5
-rw-r--r--internal/processing/filters/v2/keywordcreate.go3
-rw-r--r--internal/processing/filters/v2/keyworddelete.go3
-rw-r--r--internal/processing/filters/v2/keywordupdate.go3
-rw-r--r--internal/processing/filters/v2/statuscreate.go3
-rw-r--r--internal/processing/filters/v2/statusdelete.go3
-rw-r--r--internal/processing/filters/v2/update.go10
-rw-r--r--internal/processing/processor.go4
-rw-r--r--internal/processing/stream/filterschanged.go36
15 files changed, 103 insertions, 8 deletions
diff --git a/internal/processing/filters/v1/create.go b/internal/processing/filters/v1/create.go
index e36d6800a..4d8ffc3e1 100644
--- a/internal/processing/filters/v1/create.go
+++ b/internal/processing/filters/v1/create.go
@@ -83,5 +83,13 @@ func (p *Processor) Create(ctx context.Context, account *gtsmodel.Account, form
return nil, gtserror.NewErrorInternalError(err)
}
- return p.apiFilter(ctx, filterKeyword)
+ apiFilter, errWithCode := p.apiFilter(ctx, filterKeyword)
+ if errWithCode != nil {
+ return nil, errWithCode
+ }
+
+ // Send a filters changed event.
+ p.stream.FiltersChanged(ctx, account)
+
+ return apiFilter, nil
}
diff --git a/internal/processing/filters/v1/delete.go b/internal/processing/filters/v1/delete.go
index f2312f039..89282c65d 100644
--- a/internal/processing/filters/v1/delete.go
+++ b/internal/processing/filters/v1/delete.go
@@ -63,5 +63,8 @@ func (p *Processor) Delete(
}
}
+ // Send a filters changed event.
+ p.stream.FiltersChanged(ctx, account)
+
return nil
}
diff --git a/internal/processing/filters/v1/filters.go b/internal/processing/filters/v1/filters.go
index d46c9e72c..daa9087a9 100644
--- a/internal/processing/filters/v1/filters.go
+++ b/internal/processing/filters/v1/filters.go
@@ -18,6 +18,7 @@
package v1
import (
+ "github.com/superseriousbusiness/gotosocial/internal/processing/stream"
"github.com/superseriousbusiness/gotosocial/internal/state"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
)
@@ -25,11 +26,13 @@ import (
type Processor struct {
state *state.State
converter *typeutils.Converter
+ stream *stream.Processor
}
-func New(state *state.State, converter *typeutils.Converter) Processor {
+func New(state *state.State, converter *typeutils.Converter, stream *stream.Processor) Processor {
return Processor{
state: state,
converter: converter,
+ stream: stream,
}
}
diff --git a/internal/processing/filters/v1/update.go b/internal/processing/filters/v1/update.go
index 0421dc786..2c2fe5574 100644
--- a/internal/processing/filters/v1/update.go
+++ b/internal/processing/filters/v1/update.go
@@ -163,5 +163,13 @@ func (p *Processor) Update(
return nil, gtserror.NewErrorInternalError(err)
}
- return p.apiFilter(ctx, filterKeyword)
+ apiFilter, errWithCode := p.apiFilter(ctx, filterKeyword)
+ if errWithCode != nil {
+ return nil, errWithCode
+ }
+
+ // Send a filters changed event.
+ p.stream.FiltersChanged(ctx, account)
+
+ return apiFilter, nil
}
diff --git a/internal/processing/filters/v2/create.go b/internal/processing/filters/v2/create.go
index c7b500e9e..d429e1139 100644
--- a/internal/processing/filters/v2/create.go
+++ b/internal/processing/filters/v2/create.go
@@ -71,5 +71,13 @@ func (p *Processor) Create(ctx context.Context, account *gtsmodel.Account, form
return nil, gtserror.NewErrorInternalError(err)
}
- return p.apiFilter(ctx, filter)
+ apiFilter, errWithCode := p.apiFilter(ctx, filter)
+ if errWithCode != nil {
+ return nil, errWithCode
+ }
+
+ // Send a filters changed event.
+ p.stream.FiltersChanged(ctx, account)
+
+ return apiFilter, nil
}
diff --git a/internal/processing/filters/v2/delete.go b/internal/processing/filters/v2/delete.go
index b1bebdcb6..a312180b8 100644
--- a/internal/processing/filters/v2/delete.go
+++ b/internal/processing/filters/v2/delete.go
@@ -49,5 +49,8 @@ func (p *Processor) Delete(
return gtserror.NewErrorInternalError(err)
}
+ // Send a filters changed event.
+ p.stream.FiltersChanged(ctx, account)
+
return nil
}
diff --git a/internal/processing/filters/v2/filters.go b/internal/processing/filters/v2/filters.go
index dfb6a8992..85da4df6b 100644
--- a/internal/processing/filters/v2/filters.go
+++ b/internal/processing/filters/v2/filters.go
@@ -18,6 +18,7 @@
package v2
import (
+ "github.com/superseriousbusiness/gotosocial/internal/processing/stream"
"github.com/superseriousbusiness/gotosocial/internal/state"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
)
@@ -25,11 +26,13 @@ import (
type Processor struct {
state *state.State
converter *typeutils.Converter
+ stream *stream.Processor
}
-func New(state *state.State, converter *typeutils.Converter) Processor {
+func New(state *state.State, converter *typeutils.Converter, stream *stream.Processor) Processor {
return Processor{
state: state,
converter: converter,
+ stream: stream,
}
}
diff --git a/internal/processing/filters/v2/keywordcreate.go b/internal/processing/filters/v2/keywordcreate.go
index 711b855fa..92d9e5dfd 100644
--- a/internal/processing/filters/v2/keywordcreate.go
+++ b/internal/processing/filters/v2/keywordcreate.go
@@ -63,5 +63,8 @@ func (p *Processor) KeywordCreate(ctx context.Context, account *gtsmodel.Account
return nil, gtserror.NewErrorInternalError(err)
}
+ // Send a filters changed event.
+ p.stream.FiltersChanged(ctx, account)
+
return p.converter.FilterKeywordToAPIFilterKeyword(ctx, filterKeyword), nil
}
diff --git a/internal/processing/filters/v2/keyworddelete.go b/internal/processing/filters/v2/keyworddelete.go
index edf57167d..024991109 100644
--- a/internal/processing/filters/v2/keyworddelete.go
+++ b/internal/processing/filters/v2/keyworddelete.go
@@ -49,5 +49,8 @@ func (p *Processor) KeywordDelete(
return gtserror.NewErrorInternalError(err)
}
+ // Send a filters changed event.
+ p.stream.FiltersChanged(ctx, account)
+
return nil
}
diff --git a/internal/processing/filters/v2/keywordupdate.go b/internal/processing/filters/v2/keywordupdate.go
index 9a4058c23..9492e7b3a 100644
--- a/internal/processing/filters/v2/keywordupdate.go
+++ b/internal/processing/filters/v2/keywordupdate.go
@@ -62,5 +62,8 @@ func (p *Processor) KeywordUpdate(
return nil, gtserror.NewErrorInternalError(err)
}
+ // Send a filters changed event.
+ p.stream.FiltersChanged(ctx, account)
+
return p.converter.FilterKeywordToAPIFilterKeyword(ctx, filterKeyword), nil
}
diff --git a/internal/processing/filters/v2/statuscreate.go b/internal/processing/filters/v2/statuscreate.go
index a211dec2e..7d4469eef 100644
--- a/internal/processing/filters/v2/statuscreate.go
+++ b/internal/processing/filters/v2/statuscreate.go
@@ -62,5 +62,8 @@ func (p *Processor) StatusCreate(ctx context.Context, account *gtsmodel.Account,
return nil, gtserror.NewErrorInternalError(err)
}
+ // Send a filters changed event.
+ p.stream.FiltersChanged(ctx, account)
+
return p.converter.FilterStatusToAPIFilterStatus(ctx, filterStatus), nil
}
diff --git a/internal/processing/filters/v2/statusdelete.go b/internal/processing/filters/v2/statusdelete.go
index a428e7409..706ca691d 100644
--- a/internal/processing/filters/v2/statusdelete.go
+++ b/internal/processing/filters/v2/statusdelete.go
@@ -49,5 +49,8 @@ func (p *Processor) StatusDelete(
return gtserror.NewErrorInternalError(err)
}
+ // Send a filters changed event.
+ p.stream.FiltersChanged(ctx, account)
+
return nil
}
diff --git a/internal/processing/filters/v2/update.go b/internal/processing/filters/v2/update.go
index aecb53337..5322f63d9 100644
--- a/internal/processing/filters/v2/update.go
+++ b/internal/processing/filters/v2/update.go
@@ -121,5 +121,13 @@ func (p *Processor) Update(
filter.Keywords = filterKeywords
filter.Statuses = filterStatuses
- return p.apiFilter(ctx, filter)
+ apiFilter, errWithCode := p.apiFilter(ctx, filter)
+ if errWithCode != nil {
+ return nil, errWithCode
+ }
+
+ // Send a filters changed event.
+ p.stream.FiltersChanged(ctx, account)
+
+ return apiFilter, nil
}
diff --git a/internal/processing/processor.go b/internal/processing/processor.go
index 1e7997b8f..8765819d3 100644
--- a/internal/processing/processor.go
+++ b/internal/processing/processor.go
@@ -189,8 +189,8 @@ func NewProcessor(
processor.account = account.New(&common, state, converter, mediaManager, federator, filter, parseMentionFunc)
processor.admin = admin.New(state, cleaner, converter, mediaManager, federator.TransportController(), emailSender)
processor.fedi = fedi.New(state, &common, converter, federator, filter)
- processor.filtersv1 = filtersv1.New(state, converter)
- processor.filtersv2 = filtersv2.New(state, converter)
+ processor.filtersv1 = filtersv1.New(state, converter, &processor.stream)
+ processor.filtersv2 = filtersv2.New(state, converter, &processor.stream)
processor.list = list.New(state, converter)
processor.markers = markers.New(state, converter)
processor.polls = polls.New(&common, state, converter)
diff --git a/internal/processing/stream/filterschanged.go b/internal/processing/stream/filterschanged.go
new file mode 100644
index 000000000..b98506b9f
--- /dev/null
+++ b/internal/processing/stream/filterschanged.go
@@ -0,0 +1,36 @@
+// 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 stream
+
+import (
+ "context"
+
+ "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
+ "github.com/superseriousbusiness/gotosocial/internal/stream"
+)
+
+// FiltersChanged streams a filters changed event to any open, appropriate streams belonging to the given account.
+// Filter changes have no payload.
+func (p *Processor) FiltersChanged(ctx context.Context, account *gtsmodel.Account) {
+ p.streams.Post(ctx, account.ID, stream.Message{
+ Event: stream.EventTypeFiltersChanged,
+ Stream: []string{
+ stream.TimelineHome,
+ },
+ })
+}