summaryrefslogtreecommitdiff
path: root/internal/distributor
diff options
context:
space:
mode:
Diffstat (limited to 'internal/distributor')
-rw-r--r--internal/distributor/distributor.go58
-rw-r--r--internal/distributor/mock_Distributor.go38
2 files changed, 54 insertions, 42 deletions
diff --git a/internal/distributor/distributor.go b/internal/distributor/distributor.go
index ab092907f..74b69c5b0 100644
--- a/internal/distributor/distributor.go
+++ b/internal/distributor/distributor.go
@@ -19,8 +19,8 @@
package distributor
import (
- "github.com/go-fed/activity/pub"
"github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel"
)
// Distributor should be passed to api modules (see internal/apimodule/...). It is used for
@@ -30,10 +30,10 @@ import (
// fire messages into the distributor and not wait for a reply before proceeding with other work. This allows
// for clean distribution of messages without slowing down the client API and harming the user experience.
type Distributor interface {
- // ClientAPIIn returns a channel for accepting messages that come from the gts client API.
- ClientAPIIn() chan interface{}
+ // FromClientAPI returns a channel for accepting messages that come from the gts client API.
+ FromClientAPI() chan FromClientAPI
// ClientAPIOut returns a channel for putting in messages that need to go to the gts client API.
- ClientAPIOut() chan interface{}
+ ToClientAPI() chan ToClientAPI
// Start starts the Distributor, reading from its channels and passing messages back and forth.
Start() error
// Stop stops the distributor cleanly, finishing handling any remaining messages before closing down.
@@ -42,32 +42,32 @@ type Distributor interface {
// distributor just implements the Distributor interface
type distributor struct {
- federator pub.FederatingActor
- clientAPIIn chan interface{}
- clientAPIOut chan interface{}
- stop chan interface{}
- log *logrus.Logger
+ // federator pub.FederatingActor
+ fromClientAPI chan FromClientAPI
+ toClientAPI chan ToClientAPI
+ stop chan interface{}
+ log *logrus.Logger
}
// New returns a new Distributor that uses the given federator and logger
-func New(federator pub.FederatingActor, log *logrus.Logger) Distributor {
+func New(log *logrus.Logger) Distributor {
return &distributor{
- federator: federator,
- clientAPIIn: make(chan interface{}, 100),
- clientAPIOut: make(chan interface{}, 100),
- stop: make(chan interface{}),
- log: log,
+ // federator: federator,
+ fromClientAPI: make(chan FromClientAPI, 100),
+ toClientAPI: make(chan ToClientAPI, 100),
+ stop: make(chan interface{}),
+ log: log,
}
}
// ClientAPIIn returns a channel for accepting messages that come from the gts client API.
-func (d *distributor) ClientAPIIn() chan interface{} {
- return d.clientAPIIn
+func (d *distributor) FromClientAPI() chan FromClientAPI {
+ return d.fromClientAPI
}
// ClientAPIOut returns a channel for putting in messages that need to go to the gts client API.
-func (d *distributor) ClientAPIOut() chan interface{} {
- return d.clientAPIOut
+func (d *distributor) ToClientAPI() chan ToClientAPI {
+ return d.toClientAPI
}
// Start starts the Distributor, reading from its channels and passing messages back and forth.
@@ -76,10 +76,10 @@ func (d *distributor) Start() error {
DistLoop:
for {
select {
- case clientMsgIn := <-d.clientAPIIn:
- d.log.Infof("received clientMsgIn: %+v", clientMsgIn)
- case clientMsgOut := <-d.clientAPIOut:
- d.log.Infof("received clientMsgOut: %+v", clientMsgOut)
+ case clientMsg := <-d.fromClientAPI:
+ d.log.Infof("received message FROM client API: %+v", clientMsg)
+ case clientMsg := <-d.toClientAPI:
+ d.log.Infof("received message TO client API: %+v", clientMsg)
case <-d.stop:
break DistLoop
}
@@ -94,3 +94,15 @@ func (d *distributor) Stop() error {
close(d.stop)
return nil
}
+
+type FromClientAPI struct {
+ APObjectType gtsmodel.ActivityStreamsObject
+ APActivityType gtsmodel.ActivityStreamsActivity
+ Activity interface{}
+}
+
+type ToClientAPI struct {
+ APObjectType gtsmodel.ActivityStreamsObject
+ APActivityType gtsmodel.ActivityStreamsActivity
+ Activity interface{}
+}
diff --git a/internal/distributor/mock_Distributor.go b/internal/distributor/mock_Distributor.go
index 93d7dd8d2..42248c3f2 100644
--- a/internal/distributor/mock_Distributor.go
+++ b/internal/distributor/mock_Distributor.go
@@ -9,40 +9,38 @@ type MockDistributor struct {
mock.Mock
}
-// ClientAPIIn provides a mock function with given fields:
-func (_m *MockDistributor) ClientAPIIn() chan interface{} {
+// FromClientAPI provides a mock function with given fields:
+func (_m *MockDistributor) FromClientAPI() chan FromClientAPI {
ret := _m.Called()
- var r0 chan interface{}
- if rf, ok := ret.Get(0).(func() chan interface{}); ok {
+ var r0 chan FromClientAPI
+ if rf, ok := ret.Get(0).(func() chan FromClientAPI); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
- r0 = ret.Get(0).(chan interface{})
+ r0 = ret.Get(0).(chan FromClientAPI)
}
}
return r0
}
-// ClientAPIOut provides a mock function with given fields:
-func (_m *MockDistributor) ClientAPIOut() chan interface{} {
+// Start provides a mock function with given fields:
+func (_m *MockDistributor) Start() error {
ret := _m.Called()
- var r0 chan interface{}
- if rf, ok := ret.Get(0).(func() chan interface{}); ok {
+ var r0 error
+ if rf, ok := ret.Get(0).(func() error); ok {
r0 = rf()
} else {
- if ret.Get(0) != nil {
- r0 = ret.Get(0).(chan interface{})
- }
+ r0 = ret.Error(0)
}
return r0
}
-// Start provides a mock function with given fields:
-func (_m *MockDistributor) Start() error {
+// Stop provides a mock function with given fields:
+func (_m *MockDistributor) Stop() error {
ret := _m.Called()
var r0 error
@@ -55,15 +53,17 @@ func (_m *MockDistributor) Start() error {
return r0
}
-// Stop provides a mock function with given fields:
-func (_m *MockDistributor) Stop() error {
+// ToClientAPI provides a mock function with given fields:
+func (_m *MockDistributor) ToClientAPI() chan ToClientAPI {
ret := _m.Called()
- var r0 error
- if rf, ok := ret.Get(0).(func() error); ok {
+ var r0 chan ToClientAPI
+ if rf, ok := ret.Get(0).(func() chan ToClientAPI); ok {
r0 = rf()
} else {
- r0 = ret.Error(0)
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(chan ToClientAPI)
+ }
}
return r0