diff options
Diffstat (limited to 'internal/processing/streaming')
-rw-r--r-- | internal/processing/streaming/notification.go | 2 | ||||
-rw-r--r-- | internal/processing/streaming/openstream.go | 6 | ||||
-rw-r--r-- | internal/processing/streaming/streamdelete.go | 2 | ||||
-rw-r--r-- | internal/processing/streaming/streaming.go | 4 | ||||
-rw-r--r-- | internal/processing/streaming/streamtoaccount.go | 18 | ||||
-rw-r--r-- | internal/processing/streaming/update.go | 4 |
6 files changed, 21 insertions, 15 deletions
diff --git a/internal/processing/streaming/notification.go b/internal/processing/streaming/notification.go index 870490be4..7f8cfb8ac 100644 --- a/internal/processing/streaming/notification.go +++ b/internal/processing/streaming/notification.go @@ -33,5 +33,5 @@ func (p *processor) StreamNotificationToAccount(n *apimodel.Notification, accoun return fmt.Errorf("error marshalling notification to json: %s", err) } - return p.streamToAccount(string(bytes), stream.EventTypeNotification, account.ID) + return p.streamToAccount(string(bytes), stream.EventTypeNotification, []string{stream.TimelineNotifications, stream.TimelineHome}, account.ID) } diff --git a/internal/processing/streaming/openstream.go b/internal/processing/streaming/openstream.go index 706cc0675..c256842a4 100644 --- a/internal/processing/streaming/openstream.go +++ b/internal/processing/streaming/openstream.go @@ -30,11 +30,11 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/stream" ) -func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*stream.Stream, gtserror.WithCode) { +func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamTimeline string) (*stream.Stream, gtserror.WithCode) { l := logrus.WithFields(logrus.Fields{ "func": "OpenStreamForAccount", "account": account.ID, - "streamType": streamType, + "streamType": streamTimeline, }) l.Debug("received open stream request") @@ -46,7 +46,7 @@ func (p *processor) OpenStreamForAccount(ctx context.Context, account *gtsmodel. thisStream := &stream.Stream{ ID: streamID, - Type: streamType, + Timeline: streamTimeline, Messages: make(chan *stream.Message, 100), Hangup: make(chan interface{}, 1), Connected: true, diff --git a/internal/processing/streaming/streamdelete.go b/internal/processing/streaming/streamdelete.go index 8332c37dc..6eb271bff 100644 --- a/internal/processing/streaming/streamdelete.go +++ b/internal/processing/streaming/streamdelete.go @@ -37,7 +37,7 @@ func (p *processor) StreamDelete(statusID string) error { // stream the delete to every account for _, accountID := range accountIDs { - if err := p.streamToAccount(statusID, stream.EventTypeDelete, accountID); err != nil { + if err := p.streamToAccount(statusID, stream.EventTypeDelete, stream.AllStatusTimelines, accountID); err != nil { errs = append(errs, err.Error()) } } diff --git a/internal/processing/streaming/streaming.go b/internal/processing/streaming/streaming.go index 604ec1267..296c07f09 100644 --- a/internal/processing/streaming/streaming.go +++ b/internal/processing/streaming/streaming.go @@ -35,9 +35,9 @@ type Processor interface { // AuthorizeStreamingRequest returns an oauth2 token info in response to an access token query from the streaming API AuthorizeStreamingRequest(ctx context.Context, accessToken string) (*gtsmodel.Account, error) // OpenStreamForAccount returns a new Stream for the given account, which will contain a channel for passing messages back to the caller. - OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*stream.Stream, gtserror.WithCode) + OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, timeline string) (*stream.Stream, gtserror.WithCode) // StreamUpdateToAccount streams the given update to any open, appropriate streams belonging to the given account. - StreamUpdateToAccount(s *apimodel.Status, account *gtsmodel.Account) error + StreamUpdateToAccount(s *apimodel.Status, account *gtsmodel.Account, timeline string) error // StreamNotificationToAccount streams the given notification to any open, appropriate streams belonging to the given account. StreamNotificationToAccount(n *apimodel.Notification, account *gtsmodel.Account) error // StreamDelete streams the delete of the given statusID to *ALL* open streams. diff --git a/internal/processing/streaming/streamtoaccount.go b/internal/processing/streaming/streamtoaccount.go index 140910ab7..b950eecca 100644 --- a/internal/processing/streaming/streamtoaccount.go +++ b/internal/processing/streaming/streamtoaccount.go @@ -25,7 +25,7 @@ import ( ) // streamToAccount streams the given payload with the given event type to any streams currently open for the given account ID. -func (p *processor) streamToAccount(payload string, event stream.EventType, accountID string) error { +func (p *processor) streamToAccount(payload string, event string, timelines []string, accountID string) error { v, ok := p.streamMap.Load(accountID) if !ok { // no open connections so nothing to stream @@ -42,11 +42,17 @@ func (p *processor) streamToAccount(payload string, event stream.EventType, acco for _, s := range streamsForAccount.Streams { s.Lock() defer s.Unlock() - if s.Connected { - s.Messages <- &stream.Message{ - Stream: []string{s.Type}, - Event: string(event), - Payload: payload, + if !s.Connected { + continue + } + + for _, t := range timelines { + if s.Timeline == string(t) { + s.Messages <- &stream.Message{ + Stream: []string{string(t)}, + Event: string(event), + Payload: payload, + } } } } diff --git a/internal/processing/streaming/update.go b/internal/processing/streaming/update.go index da7dcb6ce..bd7bb0b12 100644 --- a/internal/processing/streaming/update.go +++ b/internal/processing/streaming/update.go @@ -27,11 +27,11 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/stream" ) -func (p *processor) StreamUpdateToAccount(s *apimodel.Status, account *gtsmodel.Account) error { +func (p *processor) StreamUpdateToAccount(s *apimodel.Status, account *gtsmodel.Account, timeline string) error { bytes, err := json.Marshal(s) if err != nil { return fmt.Errorf("error marshalling status to json: %s", err) } - return p.streamToAccount(string(bytes), stream.EventTypeUpdate, account.ID) + return p.streamToAccount(string(bytes), stream.EventTypeUpdate, []string{timeline}, account.ID) } |