mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-03 00:02:25 -06:00
additional faffing around with streaming
This commit is contained in:
parent
0cee5aa569
commit
42b8333d1b
9 changed files with 171 additions and 28 deletions
37
internal/processing/synchronous/streaming/streamstatus.go
Normal file
37
internal/processing/synchronous/streaming/streamstatus.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue