distributor: check server for msgoffline support XEP-0160

with discovery XEP-0030 ;)

wip #8
This commit is contained in:
Geno 2021-09-15 17:04:06 +02:00
parent 29cf678106
commit 63aa921252
2 changed files with 27 additions and 0 deletions

View File

@ -35,3 +35,5 @@ require (
) )
replace dev.sum7.eu/genofire/unified-push-xmpp/messages => ../messages replace dev.sum7.eu/genofire/unified-push-xmpp/messages => ../messages
replace mellium.im/xmpp => ../../../../mellium.im/xmpp

View File

@ -12,6 +12,7 @@ import (
"mellium.im/sasl" "mellium.im/sasl"
"mellium.im/xmlstream" "mellium.im/xmlstream"
"mellium.im/xmpp" "mellium.im/xmpp"
"mellium.im/xmpp/disco"
"mellium.im/xmpp/jid" "mellium.im/xmpp/jid"
"mellium.im/xmpp/mux" "mellium.im/xmpp/mux"
"mellium.im/xmpp/stanza" "mellium.im/xmpp/stanza"
@ -62,7 +63,9 @@ func (s *XMPPService) Run(dbus *distributor.DBus, store *storage.Storage) error
if err != nil { if err != nil {
return err return err
} }
go s.checkServer()
s.session.Serve(mux.New( s.session.Serve(mux.New(
// disco.Handle(),
mux.MessageFunc("", xml.Name{Local: "subject"}, s.message), mux.MessageFunc("", xml.Name{Local: "subject"}, s.message),
)) ))
return nil return nil
@ -116,6 +119,28 @@ func (s *XMPPService) message(msgHead stanza.Message, t xmlstream.TokenReadEncod
return nil return nil
} }
// checkServer - background job
func (s *XMPPService) checkServer() error {
domain := s.session.LocalAddr().Domain()
log.Infof("your instant is %s - check running", domain)
info, err := disco.GetInfo(context.TODO(), "", domain, s.session)
if err != nil {
return err
}
// check if server support msgoffline
supportMSGOffline := false
for _, f := range info.Features {
if f.Var == "msgoffline" {
supportMSGOffline = true
break
}
}
if !supportMSGOffline {
log.Warn("your server does not support offline messages (XEP-0160) - it is need to deliever messages later, if this distributer has current no connection")
}
return nil
}
// Register handler of DBUS Distribution // Register handler of DBUS Distribution
func (s *XMPPService) Register(appID, appToken string) (string, string, error) { func (s *XMPPService) Register(appID, appToken string) (string, string, error) {
publicToken := uuid.New().String() publicToken := uuid.New().String()