additional faffing around with streaming

This commit is contained in:
tsmethurst 2021-06-17 22:51:50 +02:00
commit 42b8333d1b
9 changed files with 171 additions and 28 deletions

View file

@ -0,0 +1,37 @@
package streaming
import (
"errors"
"github.com/sirupsen/logrus"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
func (p *processor) StreamStatusForAccount(s *apimodel.Status, account *gtsmodel.Account) error {
l := p.log.WithFields(logrus.Fields{
"func": "StreamStatusForAccount",
"account": account.ID,
})
v, ok := p.streamMap.Load(account.ID)
if !ok {
// no open connections so nothing to stream
return nil
}
streams, ok := v.(*streamsForAccount)
if !ok {
return errors.New("stream map error")
}
streams.Lock()
defer streams.Unlock()
for _, stream := range streams.s {
l.Debugf("streaming status to stream id %s", stream.streamID)
if err := stream.conn.WriteJSON(s); err != nil {
return err
}
}
return nil
}