Merge pull request 'also use xmpp JID as part of settings persistence' (#17) from karmanyaahm/unified-push-xmpp:smth into main

Reviewed-on: genofire/unified-push-xmpp#17
This commit is contained in:
genofire 2021-09-17 18:09:46 +02:00
commit 4b06d6886a
1 changed files with 4 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import (
"encoding/xml" "encoding/xml"
"errors" "errors"
"io" "io"
"strings"
"time" "time"
"github.com/bdlm/log" "github.com/bdlm/log"
@ -112,7 +113,7 @@ func (s *XMPPService) message(msgHead stanza.Message, t xmlstream.TokenReadEncod
return nil return nil
} }
from := msgHead.From.String() from := msgHead.From.String()
if from != conn.Settings { if settings := strings.Split(conn.Settings, ":"); len(settings) > 1 && settings[0] == from {
log.WithField("from", from).Info("message not from gateway, that is no notification") log.WithField("from", from).Info("message not from gateway, that is no notification")
return nil return nil
} }
@ -178,7 +179,7 @@ func (s *XMPPService) selectGateway() {
if s.KeepGateway { if s.KeepGateway {
return return
} }
conns := s.store.GetUnequalSettings(s.gateway.String()) conns := s.store.GetUnequalSettings(s.gateway.String() + ":" + s.session.LocalAddr().Bare().String())
if len(conns) <= 0 { if len(conns) <= 0 {
return return
} }
@ -242,7 +243,7 @@ func (s *XMPPService) Register(appID, appToken string) (string, string, error) {
"appID": appID, "appID": appID,
"appToken": appToken, "appToken": appToken,
}) })
conn := s.store.NewConnection(appID, appToken, s.gateway.String()) conn := s.store.NewConnection(appID, appToken, s.gateway.String()+":"+s.session.LocalAddr().Bare().String())
if conn == nil { if conn == nil {
errStr := "error to store public token" errStr := "error to store public token"
err := errors.New(errStr) err := errors.New(errStr)