From f5c004d67d4ed66b6c6df100afec47174aa14ae0 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Thu, 25 May 2023 10:37:38 +0200 Subject: [feature] Add List functionality (#1802) * start working on lists * further list work * test list db functions nicely * more work on lists * peepoopeepoo * poke * start list timeline func * we're getting there lads * couldn't be me working on stuff... could it? * hook up handlers * fiddling * weeee * woah * screaming, pissing * fix streaming being a whiny baby * lint, small test fix, swagger * tidying up, testing * fucked! by the linter * move timelines to state like a boss * add timeline start to tests using state * invalidate lists --- internal/processing/stream/stream.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'internal/processing/stream/stream.go') diff --git a/internal/processing/stream/stream.go b/internal/processing/stream/stream.go index 4a4c92a00..bd49a330c 100644 --- a/internal/processing/stream/stream.go +++ b/internal/processing/stream/stream.go @@ -18,7 +18,6 @@ package stream import ( - "errors" "sync" "github.com/superseriousbusiness/gotosocial/internal/oauth" @@ -40,37 +39,38 @@ func New(state *state.State, oauthServer oauth.Server) Processor { } // toAccount streams the given payload with the given event type to any streams currently open for the given account ID. -func (p *Processor) toAccount(payload string, event string, timelines []string, accountID string) error { +func (p *Processor) toAccount(payload string, event string, streamTypes []string, accountID string) error { + // Load all streams open for this account. v, ok := p.streamMap.Load(accountID) if !ok { - // no open connections so nothing to stream - return nil - } - - streamsForAccount, ok := v.(*stream.StreamsForAccount) - if !ok { - return errors.New("stream map error") + return nil // No entry = nothing to stream. } + streamsForAccount := v.(*stream.StreamsForAccount) //nolint:forcetypeassert streamsForAccount.Lock() defer streamsForAccount.Unlock() + for _, s := range streamsForAccount.Streams { s.Lock() defer s.Unlock() + if !s.Connected { continue } - for _, t := range timelines { - if _, found := s.Timelines[t]; found { + typeLoop: + for _, streamType := range streamTypes { + if _, found := s.StreamTypes[streamType]; found { s.Messages <- &stream.Message{ - Stream: []string{string(t)}, + Stream: []string{streamType}, Event: string(event), Payload: payload, } - // break out to the outer loop, to avoid sending duplicates - // of the same event to the same stream - break + + // Break out to the outer loop, + // to avoid sending duplicates of + // the same event to the same stream. + break typeLoop } } } -- cgit v1.2.3