groupme/groupmeext/subscription.go

60 lines
1.3 KiB
Go
Raw Normal View History

package groupmeext
2021-05-08 20:59:10 +00:00
import (
log "maunium.net/go/maulogger/v2"
"github.com/karmanyaahm/wray"
"github.com/beeper/groupme-lib"
2021-05-08 20:59:10 +00:00
)
type fayeLogger struct {
log.Logger
}
func (f fayeLogger) Debugf(i string, a ...interface{}) {
f.Logger.Debugfln(i, a...)
}
func (f fayeLogger) Errorf(i string, a ...interface{}) {
f.Logger.Errorfln(i, a...)
}
func (f fayeLogger) Warnf(i string, a ...interface{}) {
f.Logger.Warnfln(i, a...)
}
func (f fayeLogger) Infof(i string, a ...interface{}) {
f.Logger.Infofln(i, a...)
}
type FayeClient struct {
*wray.FayeClient
}
func (fc FayeClient) WaitSubscribe(channel string, msgChannel chan groupme.PushMessage) {
c_new := make(chan wray.Message)
fc.FayeClient.WaitSubscribe(channel, c_new)
//converting between types because channels don't support interfaces well
go func() {
for i := range c_new {
msgChannel <- i
}
}()
}
// for authentication, specific implementation will vary based on faye library
2021-05-08 20:59:10 +00:00
type AuthExt struct{}
func (a *AuthExt) In(wray.Message) {}
func (a *AuthExt) Out(m wray.Message) {
groupme.OutMsgProc(m)
}
func NewFayeClient(logger log.Logger) *FayeClient {
fc := &FayeClient{wray.NewFayeClient(groupme.PushServer)}
fc.SetLogger(fayeLogger{logger.Sub("FayeClient")})
fc.AddExtension(&AuthExt{})
2023-09-06 01:10:24 +00:00
fc.AddExtension(fc.FayeClient)
2021-05-08 20:59:10 +00:00
return fc
}