2022-12-14 18:53:55 +00:00
|
|
|
package pubsub
|
|
|
|
|
|
|
|
// The channel which has V3* payloads
|
|
|
|
const ChanV3 = "v3ch"
|
|
|
|
|
2023-05-15 11:27:03 +01:00
|
|
|
// V3Listener describes the messages that incoming sliding sync requests will publish.
|
2022-12-14 18:53:55 +00:00
|
|
|
type V3Listener interface {
|
|
|
|
EnsurePolling(p *V3EnsurePolling)
|
|
|
|
}
|
|
|
|
|
|
|
|
type V3EnsurePolling struct {
|
2023-04-28 12:47:13 +01:00
|
|
|
// TODO: we only really need to provide the access token hash here.
|
|
|
|
// Passing through a user means we can log something sensible though.
|
2023-04-28 12:20:46 +01:00
|
|
|
UserID string
|
|
|
|
DeviceID string
|
|
|
|
AccessTokenHash string
|
2022-12-14 18:53:55 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 10:52:08 +00:00
|
|
|
func (*V3EnsurePolling) Type() string { return "V3EnsurePolling" }
|
2022-12-14 18:53:55 +00:00
|
|
|
|
|
|
|
type V3Sub struct {
|
|
|
|
listener Listener
|
|
|
|
receiver V3Listener
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewV3Sub(l Listener, recv V3Listener) *V3Sub {
|
|
|
|
return &V3Sub{
|
|
|
|
listener: l,
|
|
|
|
receiver: recv,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *V3Sub) Teardown() {
|
|
|
|
v.listener.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *V3Sub) onMessage(p Payload) {
|
2022-12-16 10:52:08 +00:00
|
|
|
switch pl := p.(type) {
|
|
|
|
case *V3EnsurePolling:
|
|
|
|
v.receiver.EnsurePolling(pl)
|
|
|
|
default:
|
|
|
|
logger.Warn().Str("type", p.Type()).Msg("V3Sub: unhandled payload type")
|
2022-12-14 18:53:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *V3Sub) Listen() error {
|
|
|
|
return v.listener.Listen(ChanV3, v.onMessage)
|
|
|
|
}
|