update xmpp lib
This commit is contained in:
parent
ea9b107109
commit
c38379e37e
|
@ -2,6 +2,7 @@ package component
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp"
|
||||||
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -23,8 +24,8 @@ func (c *Config) Start() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
router := xmpp.NewRouter()
|
router := xmpp.NewRouter()
|
||||||
router.NewRoute().IQNamespaces(xmpp.NSDiscoInfo).HandlerFunc(c.handleDiscoInfo)
|
router.NewRoute().IQNamespaces(stanza.NSDiscoInfo).HandlerFunc(c.handleDiscoInfo)
|
||||||
router.NewRoute().IQNamespaces(xmpp.NSDiscoItems).HandlerFunc(c.handleDiscoItems)
|
router.NewRoute().IQNamespaces(stanza.NSDiscoItems).HandlerFunc(c.handleDiscoItems)
|
||||||
router.HandleFunc("iq", c.handleIQ)
|
router.HandleFunc("iq", c.handleIQ)
|
||||||
router.HandleFunc("message", c.handleMessage)
|
router.HandleFunc("message", c.handleMessage)
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,12 @@ package component
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bdlm/log"
|
"github.com/bdlm/log"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Component interface {
|
type Component interface {
|
||||||
Connect() (chan xmpp.Packet, error)
|
Connect() (chan stanza.Packet, error)
|
||||||
Send(xmpp.Packet)
|
Send(stanza.Packet)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect function with config to get DB connection interface
|
// Connect function with config to get DB connection interface
|
||||||
|
|
|
@ -5,39 +5,40 @@ import (
|
||||||
|
|
||||||
"github.com/bdlm/log"
|
"github.com/bdlm/log"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp"
|
||||||
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Config) handleDiscoInfo(s xmpp.Sender, p xmpp.Packet) {
|
func (c *Config) handleDiscoInfo(s xmpp.Sender, p stanza.Packet) {
|
||||||
iq, ok := p.(xmpp.IQ)
|
iq, ok := p.(stanza.IQ)
|
||||||
if !ok || iq.Type != "get" {
|
if !ok || iq.Type != "get" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
discoInfo, ok := iq.Payload.(*xmpp.DiscoInfo)
|
discoInfo, ok := iq.Payload.(*stanza.DiscoInfo)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
attrs := iq.PacketAttrs
|
attrs := iq.Attrs
|
||||||
iq = xmpp.NewIQ("result", attrs.To, attrs.From, attrs.Id, "en")
|
iq = stanza.NewIQ(stanza.Attrs{Type: stanza.IQTypeResult, To: attrs.From, From: attrs.To, Id: attrs.Id})
|
||||||
|
|
||||||
payload := xmpp.DiscoInfo{
|
payload := stanza.DiscoInfo{
|
||||||
XMLName: xml.Name{
|
XMLName: xml.Name{
|
||||||
Space: xmpp.NSDiscoInfo,
|
Space: stanza.NSDiscoInfo,
|
||||||
Local: "query",
|
Local: "query",
|
||||||
},
|
},
|
||||||
Features: []xmpp.Feature{
|
Features: []stanza.Feature{
|
||||||
{Var: xmpp.NSDiscoInfo},
|
{Var: stanza.NSDiscoInfo},
|
||||||
{Var: xmpp.NSDiscoItems},
|
{Var: stanza.NSDiscoItems},
|
||||||
{Var: xmpp.NSMsgReceipts},
|
{Var: stanza.NSMsgReceipts},
|
||||||
{Var: xmpp.NSMsgChatMarkers},
|
{Var: stanza.NSMsgChatMarkers},
|
||||||
{Var: xmpp.NSMsgChatStateNotifications},
|
{Var: stanza.NSMsgChatStateNotifications},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if discoInfo.Node == "" {
|
if discoInfo.Node == "" {
|
||||||
payload.Identity = xmpp.Identity{
|
payload.Identity = append(payload.Identity, stanza.Identity{
|
||||||
Name: c.Type,
|
Name: c.Type,
|
||||||
Category: "gateway",
|
Category: "gateway",
|
||||||
Type: "service",
|
Type: "service",
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
iq.Payload = &payload
|
iq.Payload = &payload
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]interface{}{
|
||||||
|
@ -48,21 +49,21 @@ func (c *Config) handleDiscoInfo(s xmpp.Sender, p xmpp.Packet) {
|
||||||
s.Send(iq)
|
s.Send(iq)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) handleDiscoItems(s xmpp.Sender, p xmpp.Packet) {
|
func (c *Config) handleDiscoItems(s xmpp.Sender, p stanza.Packet) {
|
||||||
iq, ok := p.(xmpp.IQ)
|
iq, ok := p.(stanza.IQ)
|
||||||
if !ok || iq.Type != "get" {
|
if !ok || iq.Type != "get" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
discoItems, ok := iq.Payload.(*xmpp.DiscoItems)
|
discoItems, ok := iq.Payload.(*stanza.DiscoItems)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
attrs := iq.PacketAttrs
|
attrs := iq.Attrs
|
||||||
iq = xmpp.NewIQ("result", attrs.To, attrs.From, attrs.Id, "en")
|
iq = stanza.NewIQ(stanza.Attrs{Type: stanza.IQTypeResult, To: attrs.From, From: attrs.To, Id: attrs.Id})
|
||||||
|
|
||||||
payload := xmpp.DiscoItems{}
|
payload := stanza.DiscoItems{}
|
||||||
if discoItems.Node == "" {
|
if discoItems.Node == "" {
|
||||||
payload.Items = []xmpp.DiscoItem{
|
payload.Items = []stanza.DiscoItem{
|
||||||
{Name: c.Type, JID: c.Host, Node: "node1"},
|
{Name: c.Type, JID: c.Host, Node: "node1"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,18 +76,18 @@ func (c *Config) handleDiscoItems(s xmpp.Sender, p xmpp.Packet) {
|
||||||
}).Debug("disco items")
|
}).Debug("disco items")
|
||||||
s.Send(iq)
|
s.Send(iq)
|
||||||
}
|
}
|
||||||
func (c *Config) handleIQ(s xmpp.Sender, p xmpp.Packet) {
|
func (c *Config) handleIQ(s xmpp.Sender, p stanza.Packet) {
|
||||||
iq, ok := p.(xmpp.IQ)
|
iq, ok := p.(stanza.IQ)
|
||||||
if !ok || iq.Type != "get" {
|
if !ok || iq.Type != "get" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
xError := xmpp.Err{
|
xError := stanza.Err{
|
||||||
Code: 501,
|
Code: 501,
|
||||||
Reason: "feature-not-implemented",
|
Reason: "feature-not-implemented",
|
||||||
Type: "cancel",
|
Type: "cancel",
|
||||||
}
|
}
|
||||||
resp := iq.MakeError(xError)
|
resp := iq.MakeError(xError)
|
||||||
attrs := iq.PacketAttrs
|
attrs := iq.Attrs
|
||||||
|
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]interface{}{
|
||||||
"type": c.Type,
|
"type": c.Type,
|
||||||
|
@ -95,8 +96,8 @@ func (c *Config) handleIQ(s xmpp.Sender, p xmpp.Packet) {
|
||||||
}).Debugf("ignore: %s", iq.Payload)
|
}).Debugf("ignore: %s", iq.Payload)
|
||||||
s.Send(resp)
|
s.Send(resp)
|
||||||
}
|
}
|
||||||
func (c *Config) handleMessage(s xmpp.Sender, p xmpp.Packet) {
|
func (c *Config) handleMessage(s xmpp.Sender, p stanza.Packet) {
|
||||||
msg, ok := p.(xmpp.Message)
|
msg, ok := p.(stanza.Message)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -104,8 +105,8 @@ func (c *Config) handleMessage(s xmpp.Sender, p xmpp.Packet) {
|
||||||
log.WithFields(map[string]interface{}{
|
log.WithFields(map[string]interface{}{
|
||||||
"type": c.Type,
|
"type": c.Type,
|
||||||
"from": s,
|
"from": s,
|
||||||
"to": msg.PacketAttrs.To,
|
"to": msg.To,
|
||||||
"id": msg.PacketAttrs.Id,
|
"id": msg.Id,
|
||||||
}).Debug(msg.XMPPFormat())
|
}).Debug(msg.XMPPFormat())
|
||||||
}
|
}
|
||||||
c.comp.Send(p)
|
c.comp.Send(p)
|
||||||
|
|
|
@ -5,26 +5,27 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp"
|
||||||
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
type dummyComp struct {
|
type dummyComp struct {
|
||||||
Component
|
Component
|
||||||
LastPacket xmpp.Packet
|
LastPacket stanza.Packet
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dummyComp) Connect() (chan xmpp.Packet, error) {
|
func (d *dummyComp) Connect() (chan stanza.Packet, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
func (d *dummyComp) Send(a xmpp.Packet) {
|
func (d *dummyComp) Send(a stanza.Packet) {
|
||||||
d.LastPacket = a
|
d.LastPacket = a
|
||||||
}
|
}
|
||||||
|
|
||||||
type dummyXMPP struct {
|
type dummyXMPP struct {
|
||||||
xmpp.Sender
|
xmpp.Sender
|
||||||
LastPacket xmpp.Packet
|
LastPacket stanza.Packet
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dummyXMPP) Send(a xmpp.Packet) error {
|
func (d *dummyXMPP) Send(a stanza.Packet) error {
|
||||||
d.LastPacket = a
|
d.LastPacket = a
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -42,67 +43,67 @@ func TestReceive(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// message
|
// message
|
||||||
c.handleMessage(s, xmpp.IQ{})
|
c.handleMessage(s, stanza.IQ{})
|
||||||
assert.Nil(comp.LastPacket)
|
assert.Nil(comp.LastPacket)
|
||||||
|
|
||||||
c.handleMessage(s, xmpp.Message{})
|
c.handleMessage(s, stanza.Message{})
|
||||||
_, ok := comp.LastPacket.(xmpp.Message)
|
_, ok := comp.LastPacket.(stanza.Message)
|
||||||
assert.True(ok)
|
assert.True(ok)
|
||||||
|
|
||||||
// unsupported iq
|
// unsupported iq
|
||||||
c.handleIQ(s, xmpp.IQ{})
|
c.handleIQ(s, stanza.IQ{})
|
||||||
assert.Nil(s.LastPacket)
|
assert.Nil(s.LastPacket)
|
||||||
|
|
||||||
c.handleIQ(s, xmpp.IQ{
|
c.handleIQ(s, stanza.IQ{
|
||||||
PacketAttrs: xmpp.PacketAttrs{Type: "get"},
|
Attrs: stanza.Attrs{Type: stanza.IQTypeGet},
|
||||||
})
|
})
|
||||||
assert.NotNil(s.LastPacket)
|
assert.NotNil(s.LastPacket)
|
||||||
iq := s.LastPacket.(xmpp.IQ)
|
iq := s.LastPacket.(stanza.IQ)
|
||||||
assert.Equal("error", iq.Type)
|
assert.Equal(stanza.IQTypeError, iq.Type)
|
||||||
assert.Equal("feature-not-implemented", iq.Error.Reason)
|
assert.Equal("feature-not-implemented", iq.Error.Reason)
|
||||||
s.LastPacket = nil
|
s.LastPacket = nil
|
||||||
|
|
||||||
// iq disco info
|
// iq disco info
|
||||||
c.handleDiscoInfo(s, xmpp.IQ{
|
c.handleDiscoInfo(s, stanza.IQ{
|
||||||
Payload: &xmpp.DiscoInfo{},
|
Payload: &stanza.DiscoInfo{},
|
||||||
})
|
})
|
||||||
assert.Nil(s.LastPacket)
|
assert.Nil(s.LastPacket)
|
||||||
|
|
||||||
c.handleDiscoInfo(s, xmpp.IQ{
|
c.handleDiscoInfo(s, stanza.IQ{
|
||||||
PacketAttrs: xmpp.PacketAttrs{Type: "get"},
|
Attrs: stanza.Attrs{Type: stanza.IQTypeGet},
|
||||||
})
|
})
|
||||||
assert.Nil(s.LastPacket)
|
assert.Nil(s.LastPacket)
|
||||||
|
|
||||||
c.handleDiscoInfo(s, xmpp.IQ{
|
c.handleDiscoInfo(s, stanza.IQ{
|
||||||
PacketAttrs: xmpp.PacketAttrs{Type: "get"},
|
Attrs: stanza.Attrs{Type: stanza.IQTypeGet},
|
||||||
Payload: &xmpp.DiscoInfo{},
|
Payload: &stanza.DiscoInfo{},
|
||||||
})
|
})
|
||||||
assert.NotNil(s.LastPacket)
|
assert.NotNil(s.LastPacket)
|
||||||
iq = s.LastPacket.(xmpp.IQ)
|
iq = s.LastPacket.(stanza.IQ)
|
||||||
assert.Equal("result", iq.Type)
|
assert.Equal(stanza.IQTypeResult, iq.Type)
|
||||||
dinfo := iq.Payload.(*xmpp.DiscoInfo)
|
dinfo := iq.Payload.(*stanza.DiscoInfo)
|
||||||
assert.Equal("monkeyservice", dinfo.Identity.Name)
|
assert.Equal("monkeyservice", dinfo.Identity[0].Name)
|
||||||
s.LastPacket = nil
|
s.LastPacket = nil
|
||||||
|
|
||||||
// iq disco items
|
// iq disco items
|
||||||
c.handleDiscoItems(s, xmpp.IQ{
|
c.handleDiscoItems(s, stanza.IQ{
|
||||||
Payload: &xmpp.DiscoItems{},
|
Payload: &stanza.DiscoItems{},
|
||||||
})
|
})
|
||||||
assert.Nil(s.LastPacket)
|
assert.Nil(s.LastPacket)
|
||||||
|
|
||||||
c.handleDiscoItems(s, xmpp.IQ{
|
c.handleDiscoItems(s, stanza.IQ{
|
||||||
PacketAttrs: xmpp.PacketAttrs{Type: "get"},
|
Attrs: stanza.Attrs{Type: stanza.IQTypeGet},
|
||||||
})
|
})
|
||||||
assert.Nil(s.LastPacket)
|
assert.Nil(s.LastPacket)
|
||||||
|
|
||||||
c.handleDiscoItems(s, xmpp.IQ{
|
c.handleDiscoItems(s, stanza.IQ{
|
||||||
PacketAttrs: xmpp.PacketAttrs{Type: "get"},
|
Attrs: stanza.Attrs{Type: stanza.IQTypeGet},
|
||||||
Payload: &xmpp.DiscoItems{},
|
Payload: &stanza.DiscoItems{},
|
||||||
})
|
})
|
||||||
assert.NotNil(s.LastPacket)
|
assert.NotNil(s.LastPacket)
|
||||||
iq = s.LastPacket.(xmpp.IQ)
|
iq = s.LastPacket.(stanza.IQ)
|
||||||
assert.Equal("result", iq.Type)
|
assert.Equal(stanza.IQTypeResult, iq.Type)
|
||||||
ditems := iq.Payload.(*xmpp.DiscoItems)
|
ditems := iq.Payload.(*stanza.DiscoItems)
|
||||||
assert.Equal("monkeyservice", ditems.Items[0].Name)
|
assert.Equal("monkeyservice", ditems.Items[0].Name)
|
||||||
s.LastPacket = nil
|
s.LastPacket = nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@ package component
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bdlm/log"
|
"github.com/bdlm/log"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Config) sender(packets chan xmpp.Packet) {
|
func (c *Config) sender(packets chan stanza.Packet) {
|
||||||
for packet := range packets {
|
for packet := range packets {
|
||||||
if p := c.sending(packet); p != nil {
|
if p := c.sending(packet); p != nil {
|
||||||
c.xmpp.Send(p)
|
c.xmpp.Send(p)
|
||||||
|
@ -13,20 +13,20 @@ func (c *Config) sender(packets chan xmpp.Packet) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) sending(packet xmpp.Packet) xmpp.Packet {
|
func (c *Config) sending(packet stanza.Packet) stanza.Packet {
|
||||||
logger := log.WithField("type", c.Type)
|
logger := log.WithField("type", c.Type)
|
||||||
switch p := packet.(type) {
|
switch p := packet.(type) {
|
||||||
case xmpp.Message:
|
case stanza.Message:
|
||||||
if p.PacketAttrs.From == "" {
|
if p.From == "" {
|
||||||
p.PacketAttrs.From = c.Host
|
p.From = c.Host
|
||||||
} else {
|
} else {
|
||||||
p.PacketAttrs.From += "@" + c.Host
|
p.From += "@" + c.Host
|
||||||
}
|
}
|
||||||
if c.XMPPDebug {
|
if c.XMPPDebug {
|
||||||
logger.WithFields(map[string]interface{}{
|
logger.WithFields(map[string]interface{}{
|
||||||
"from": p.PacketAttrs.From,
|
"from": p.From,
|
||||||
"to": p.PacketAttrs.To,
|
"to": p.To,
|
||||||
"id": p.PacketAttrs.Id,
|
"id": p.Id,
|
||||||
}).Debug(p.XMPPFormat())
|
}).Debug(p.XMPPFormat())
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSend(t *testing.T) {
|
func TestSend(t *testing.T) {
|
||||||
|
@ -13,18 +13,18 @@ func TestSend(t *testing.T) {
|
||||||
c := Config{Host: "example.org", XMPPDebug: true}
|
c := Config{Host: "example.org", XMPPDebug: true}
|
||||||
|
|
||||||
// ignoring packet
|
// ignoring packet
|
||||||
p := c.sending(xmpp.IQ{})
|
p := c.sending(stanza.IQ{})
|
||||||
assert.Nil(p)
|
assert.Nil(p)
|
||||||
|
|
||||||
// send by component host
|
// send by component host
|
||||||
p = c.sending(xmpp.Message{})
|
p = c.sending(stanza.Message{})
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
msg := p.(xmpp.Message)
|
msg := p.(stanza.Message)
|
||||||
assert.Equal("example.org", msg.PacketAttrs.From)
|
assert.Equal("example.org", msg.From)
|
||||||
|
|
||||||
// send by a user of component
|
// send by a user of component
|
||||||
p = c.sending(xmpp.Message{PacketAttrs: xmpp.PacketAttrs{From: "threemaid"}})
|
p = c.sending(stanza.Message{Attrs: stanza.Attrs{From: "threemaid"}})
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
msg = p.(xmpp.Message)
|
msg = p.(stanza.Message)
|
||||||
assert.Equal("threemaid@example.org", msg.PacketAttrs.From)
|
assert.Equal("threemaid@example.org", msg.From)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,13 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *Account) FileToXMPP(from string, msgID uint64, ext string, data []byte) (xmpp.Message, error) {
|
func (a *Account) FileToXMPP(from string, msgID uint64, ext string, data []byte) (stanza.Message, error) {
|
||||||
msgIDStr := strconv.FormatUint(msgID, 10)
|
msgIDStr := strconv.FormatUint(msgID, 10)
|
||||||
msg := xmpp.Message{
|
msg := stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{
|
Attrs: stanza.Attrs{
|
||||||
Id: msgIDStr,
|
Id: msgIDStr,
|
||||||
From: from,
|
From: from,
|
||||||
To: a.XMPP.String(),
|
To: a.XMPP.String(),
|
||||||
|
@ -24,6 +24,6 @@ func (a *Account) FileToXMPP(from string, msgID uint64, ext string, data []byte)
|
||||||
return msg, err
|
return msg, err
|
||||||
}
|
}
|
||||||
msg.Body = url
|
msg.Body = url
|
||||||
msg.Extensions = append(msg.Extensions, xmpp.OOB{URL: url})
|
msg.Extensions = append(msg.Extensions, stanza.OOB{URL: url})
|
||||||
return msg, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package threema
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp/stanza"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -19,7 +19,7 @@ func TestFileToXMPP(t *testing.T) {
|
||||||
|
|
||||||
msg, err := a.FileToXMPP("", 1, "jpg", []byte("hallo"))
|
msg, err := a.FileToXMPP("", 1, "jpg", []byte("hallo"))
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
oob := msg.Extensions[0].(xmpp.OOB)
|
oob := msg.Extensions[0].(stanza.OOB)
|
||||||
assert.Equal("a/1.jpg", oob.URL)
|
assert.Equal("a/1.jpg", oob.URL)
|
||||||
|
|
||||||
a.threema.httpUploadPath = "/gibt/es/nicht"
|
a.threema.httpUploadPath = "/gibt/es/nicht"
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bdlm/log"
|
"github.com/bdlm/log"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp/stanza"
|
||||||
|
|
||||||
"dev.sum7.eu/genofire/golang-lib/database"
|
"dev.sum7.eu/genofire/golang-lib/database"
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
type Threema struct {
|
type Threema struct {
|
||||||
component.Component
|
component.Component
|
||||||
out chan xmpp.Packet
|
out chan stanza.Packet
|
||||||
accountJID map[string]*Account
|
accountJID map[string]*Account
|
||||||
bot map[string]*Bot
|
bot map[string]*Bot
|
||||||
httpUploadPath string
|
httpUploadPath string
|
||||||
|
@ -24,7 +24,7 @@ type Threema struct {
|
||||||
|
|
||||||
func NewThreema(config map[string]interface{}) (component.Component, error) {
|
func NewThreema(config map[string]interface{}) (component.Component, error) {
|
||||||
t := &Threema{
|
t := &Threema{
|
||||||
out: make(chan xmpp.Packet),
|
out: make(chan stanza.Packet),
|
||||||
accountJID: make(map[string]*Account),
|
accountJID: make(map[string]*Account),
|
||||||
bot: make(map[string]*Bot),
|
bot: make(map[string]*Bot),
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func NewThreema(config map[string]interface{}) (component.Component, error) {
|
||||||
return t, nil
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Threema) Connect() (chan xmpp.Packet, error) {
|
func (t *Threema) Connect() (chan stanza.Packet, error) {
|
||||||
var jids []*models.JID
|
var jids []*models.JID
|
||||||
database.Read.Find(&jids)
|
database.Read.Find(&jids)
|
||||||
for _, jid := range jids {
|
for _, jid := range jids {
|
||||||
|
@ -60,37 +60,37 @@ func (t *Threema) Connect() (chan xmpp.Packet, error) {
|
||||||
}
|
}
|
||||||
return t.out, nil
|
return t.out, nil
|
||||||
}
|
}
|
||||||
func (t *Threema) Send(packet xmpp.Packet) {
|
func (t *Threema) Send(packet stanza.Packet) {
|
||||||
if p := t.send(packet); p != nil {
|
if p := t.send(packet); p != nil {
|
||||||
t.out <- p
|
t.out <- p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (t *Threema) send(packet xmpp.Packet) xmpp.Packet {
|
func (t *Threema) send(packet stanza.Packet) stanza.Packet {
|
||||||
switch p := packet.(type) {
|
switch p := packet.(type) {
|
||||||
case xmpp.Message:
|
case stanza.Message:
|
||||||
from := models.ParseJID(p.PacketAttrs.From)
|
from := models.ParseJID(p.Attrs.From)
|
||||||
to := models.ParseJID(p.PacketAttrs.To)
|
to := models.ParseJID(p.Attrs.To)
|
||||||
|
|
||||||
if to.IsDomain() {
|
if to.IsDomain() {
|
||||||
if from == nil {
|
if from == nil {
|
||||||
log.Warn("receive message without sender")
|
log.Warn("receive message without sender")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
msg := xmpp.NewMessage("chat", "", from.String(), "", "en")
|
msg := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, To: from.String()})
|
||||||
msg.Body = t.getBot(from).Handle(p.Body)
|
msg.Body = t.getBot(from).Handle(p.Body)
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
account, err := t.getAccount(from)
|
account, err := t.getAccount(from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := xmpp.NewMessage("chat", "", from.String(), "", "en")
|
msg := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, To: from.String()})
|
||||||
msg.Body = "It was not possible to send, because we have no account for you.\nPlease generate one, by sending `generate` to this gateway"
|
msg.Body = "It was not possible to send, because we have no account for you.\nPlease generate one, by sending `generate` to this gateway"
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
threemaID := strings.ToUpper(to.Local)
|
threemaID := strings.ToUpper(to.Local)
|
||||||
if err := account.Send(threemaID, p); err != nil {
|
if err := account.Send(threemaID, p); err != nil {
|
||||||
msg := xmpp.NewMessage("chat", "", from.String(), "", "en")
|
msg := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, To: from.String()})
|
||||||
msg.Body = err.Error()
|
msg.Body = err.Error()
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp/stanza"
|
||||||
|
|
||||||
"dev.sum7.eu/genofire/golang-lib/database"
|
"dev.sum7.eu/genofire/golang-lib/database"
|
||||||
"dev.sum7.eu/genofire/thrempp/models"
|
"dev.sum7.eu/genofire/thrempp/models"
|
||||||
|
@ -72,44 +72,44 @@ func TestSend(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
// test channel
|
// test channel
|
||||||
out := make(chan xmpp.Packet)
|
out := make(chan stanza.Packet)
|
||||||
tr := Threema{
|
tr := Threema{
|
||||||
out: out,
|
out: out,
|
||||||
accountJID: make(map[string]*Account),
|
accountJID: make(map[string]*Account),
|
||||||
bot: make(map[string]*Bot),
|
bot: make(map[string]*Bot),
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
tr.Send(xmpp.Message{
|
tr.Send(stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{From: "a@example.org"},
|
Attrs: stanza.Attrs{From: "a@example.org"},
|
||||||
})
|
})
|
||||||
}()
|
}()
|
||||||
p := <-out
|
p := <-out
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
// no account. generate one
|
// no account. generate one
|
||||||
msg := p.(xmpp.Message)
|
msg := p.(stanza.Message)
|
||||||
assert.Contains(msg.Body, "generate")
|
assert.Contains(msg.Body, "generate")
|
||||||
|
|
||||||
// test no answer
|
// test no answer
|
||||||
p = tr.send(xmpp.IQ{})
|
p = tr.send(stanza.IQ{})
|
||||||
assert.Nil(p)
|
assert.Nil(p)
|
||||||
|
|
||||||
// chat with bot without sender
|
// chat with bot without sender
|
||||||
p = tr.send(xmpp.Message{
|
p = tr.send(stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{
|
Attrs: stanza.Attrs{
|
||||||
To: "example.org",
|
To: "example.org",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.Nil(p)
|
assert.Nil(p)
|
||||||
|
|
||||||
// chat with bot
|
// chat with bot
|
||||||
p = tr.send(xmpp.Message{
|
p = tr.send(stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{
|
Attrs: stanza.Attrs{
|
||||||
From: "a@example.com",
|
From: "a@example.com",
|
||||||
To: "example.org",
|
To: "example.org",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
msg = p.(xmpp.Message)
|
msg = p.(stanza.Message)
|
||||||
assert.Contains(msg.Body, "command not found")
|
assert.Contains(msg.Body, "command not found")
|
||||||
|
|
||||||
// chat with delivier error
|
// chat with delivier error
|
||||||
|
@ -134,14 +134,14 @@ func TestSend(t *testing.T) {
|
||||||
_, err := tr.getAccount(&jid)
|
_, err := tr.getAccount(&jid)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
p = tr.send(xmpp.Message{
|
p = tr.send(stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{
|
Attrs: stanza.Attrs{
|
||||||
From: "a@example.org",
|
From: "a@example.org",
|
||||||
To: "12345678@threema.example.org",
|
To: "12345678@threema.example.org",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
msg = p.(xmpp.Message)
|
msg = p.(stanza.Message)
|
||||||
assert.Equal("command not supported", msg.Body)
|
assert.Equal("command not supported", msg.Body)
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,14 @@ import (
|
||||||
|
|
||||||
"github.com/bdlm/log"
|
"github.com/bdlm/log"
|
||||||
"github.com/o3ma/o3"
|
"github.com/o3ma/o3"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *Account) receiver(out chan<- xmpp.Packet) {
|
func (a *Account) receiver(out chan<- stanza.Packet) {
|
||||||
for receivedMessage := range a.receive {
|
for receivedMessage := range a.receive {
|
||||||
if receivedMessage.Err != nil {
|
if receivedMessage.Err != nil {
|
||||||
log.Warnf("Error Receiving Message: %s\n", receivedMessage.Err)
|
log.Warnf("Error Receiving Message: %s\n", receivedMessage.Err)
|
||||||
xMSG := xmpp.NewMessage("chat", "", a.XMPP.String(), "", "en")
|
xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, To: a.XMPP.String()})
|
||||||
xMSG.Body = fmt.Sprintf("error on decoding message:\n%v", receivedMessage.Err)
|
xMSG.Body = fmt.Sprintf("error on decoding message:\n%v", receivedMessage.Err)
|
||||||
out <- xMSG
|
out <- xMSG
|
||||||
continue
|
continue
|
||||||
|
@ -24,7 +24,7 @@ func (a *Account) receiver(out chan<- xmpp.Packet) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if p, err := a.receiving(receivedMessage.Msg); err != nil {
|
if p, err := a.receiving(receivedMessage.Msg); err != nil {
|
||||||
xMSG := xmpp.NewMessage("chat", sender, a.XMPP.String(), "", "en")
|
xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, From: sender, To: a.XMPP.String()})
|
||||||
xMSG.Body = fmt.Sprintf("error on decoding message: %s\n%v", err, receivedMessage.Msg.Serialize())
|
xMSG.Body = fmt.Sprintf("error on decoding message: %s\n%v", err, receivedMessage.Msg.Serialize())
|
||||||
out <- xMSG
|
out <- xMSG
|
||||||
} else if p != nil {
|
} else if p != nil {
|
||||||
|
@ -33,13 +33,13 @@ func (a *Account) receiver(out chan<- xmpp.Packet) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func requestExtensions(xMSG *xmpp.Message) {
|
func requestExtensions(xMSG *stanza.Message) {
|
||||||
xMSG.Extensions = append(xMSG.Extensions, xmpp.ReceiptRequest{})
|
xMSG.Extensions = append(xMSG.Extensions, stanza.ReceiptRequest{})
|
||||||
xMSG.Extensions = append(xMSG.Extensions, xmpp.Markable{})
|
xMSG.Extensions = append(xMSG.Extensions, stanza.Markable{})
|
||||||
xMSG.Extensions = append(xMSG.Extensions, xmpp.StateActive{})
|
xMSG.Extensions = append(xMSG.Extensions, stanza.StateActive{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Account) receiving(receivedMessage o3.Message) (xmpp.Packet, error) {
|
func (a *Account) receiving(receivedMessage o3.Message) (stanza.Packet, error) {
|
||||||
logger := log.WithFields(map[string]interface{}{
|
logger := log.WithFields(map[string]interface{}{
|
||||||
"from": receivedMessage.Sender().String(),
|
"from": receivedMessage.Sender().String(),
|
||||||
"to": a.XMPP.String(),
|
"to": a.XMPP.String(),
|
||||||
|
@ -47,7 +47,7 @@ func (a *Account) receiving(receivedMessage o3.Message) (xmpp.Packet, error) {
|
||||||
switch msg := receivedMessage.(type) {
|
switch msg := receivedMessage.(type) {
|
||||||
case o3.TextMessage:
|
case o3.TextMessage:
|
||||||
sender := msg.Sender().String()
|
sender := msg.Sender().String()
|
||||||
xMSG := xmpp.NewMessage("chat", sender, a.XMPP.String(), strconv.FormatUint(msg.ID(), 10), "en")
|
xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, From: sender, To: a.XMPP.String(), Id: strconv.FormatUint(msg.ID(), 10)})
|
||||||
xMSG.Body = msg.Text()
|
xMSG.Body = msg.Text()
|
||||||
requestExtensions(&xMSG)
|
requestExtensions(&xMSG)
|
||||||
logger.WithField("text", xMSG.Body).Debug("send text")
|
logger.WithField("text", xMSG.Body).Debug("send text")
|
||||||
|
@ -93,14 +93,14 @@ func (a *Account) receiving(receivedMessage o3.Message) (xmpp.Packet, error) {
|
||||||
|
|
||||||
case o3.DeliveryReceiptMessage:
|
case o3.DeliveryReceiptMessage:
|
||||||
msgID := msg.MsgID()
|
msgID := msg.MsgID()
|
||||||
xMSG := xmpp.NewMessage("chat", msg.Sender().String(), a.XMPP.String(), "", "en")
|
xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, From: msg.Sender().String(), To: a.XMPP.String()})
|
||||||
state := ""
|
state := ""
|
||||||
|
|
||||||
if msg.Status() == o3.MSGDELIVERED {
|
if msg.Status() == o3.MSGDELIVERED {
|
||||||
state = "delivered"
|
state = "delivered"
|
||||||
if id, ok := a.deliveredMSG[msgID]; ok {
|
if id, ok := a.deliveredMSG[msgID]; ok {
|
||||||
xMSG.Extensions = append(xMSG.Extensions, xmpp.ReceiptReceived{ID: id})
|
xMSG.Extensions = append(xMSG.Extensions, stanza.ReceiptReceived{ID: id})
|
||||||
xMSG.Extensions = append(xMSG.Extensions, xmpp.MarkReceived{ID: id})
|
xMSG.Extensions = append(xMSG.Extensions, stanza.MarkReceived{ID: id})
|
||||||
delete(a.deliveredMSG, msgID)
|
delete(a.deliveredMSG, msgID)
|
||||||
} else {
|
} else {
|
||||||
logger.Warnf("found not id in cache to announce received on xmpp side")
|
logger.Warnf("found not id in cache to announce received on xmpp side")
|
||||||
|
@ -109,7 +109,7 @@ func (a *Account) receiving(receivedMessage o3.Message) (xmpp.Packet, error) {
|
||||||
if msg.Status() == o3.MSGREAD {
|
if msg.Status() == o3.MSGREAD {
|
||||||
state = "displayed"
|
state = "displayed"
|
||||||
if id, ok := a.readedMSG[msgID]; ok {
|
if id, ok := a.readedMSG[msgID]; ok {
|
||||||
xMSG.Extensions = append(xMSG.Extensions, xmpp.MarkDisplayed{ID: id})
|
xMSG.Extensions = append(xMSG.Extensions, stanza.MarkDisplayed{ID: id})
|
||||||
delete(a.readedMSG, msgID)
|
delete(a.readedMSG, msgID)
|
||||||
} else {
|
} else {
|
||||||
logger.Warnf("found not id in cache to announce readed on xmpp side")
|
logger.Warnf("found not id in cache to announce readed on xmpp side")
|
||||||
|
@ -122,13 +122,13 @@ func (a *Account) receiving(receivedMessage o3.Message) (xmpp.Packet, error) {
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
case o3.TypingNotificationMessage:
|
case o3.TypingNotificationMessage:
|
||||||
xMSG := xmpp.NewMessage("chat", msg.Sender().String(), a.XMPP.String(), strconv.FormatUint(msg.ID(), 10), "en")
|
xMSG := stanza.NewMessage(stanza.Attrs{Type: stanza.MessageTypeChat, From: msg.Sender().String(), To: a.XMPP.String(), Id: strconv.FormatUint(msg.ID(), 10)})
|
||||||
if msg.OnOff != 0 {
|
if msg.OnOff != 0 {
|
||||||
logger.Debug("composing")
|
logger.Debug("composing")
|
||||||
xMSG.Extensions = append(xMSG.Extensions, xmpp.StateComposing{})
|
xMSG.Extensions = append(xMSG.Extensions, stanza.StateComposing{})
|
||||||
} else {
|
} else {
|
||||||
logger.Debug("inactive")
|
logger.Debug("inactive")
|
||||||
xMSG.Extensions = append(xMSG.Extensions, xmpp.StateInactive{})
|
xMSG.Extensions = append(xMSG.Extensions, stanza.StateInactive{})
|
||||||
}
|
}
|
||||||
return xMSG, nil
|
return xMSG, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/o3ma/o3"
|
"github.com/o3ma/o3"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
const threemaID = "87654321"
|
const threemaID = "87654321"
|
||||||
|
@ -55,7 +55,7 @@ func TestReceiveText(t *testing.T) {
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
p, err := a.receiving(txtMsg)
|
p, err := a.receiving(txtMsg)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
xMSG, ok := p.(xmpp.Message)
|
xMSG, ok := p.(stanza.Message)
|
||||||
assert.True(ok)
|
assert.True(ok)
|
||||||
assert.Equal("Oojoh0Ah", xMSG.Body)
|
assert.Equal("Oojoh0Ah", xMSG.Body)
|
||||||
}
|
}
|
||||||
|
@ -125,9 +125,9 @@ func TestReceiveDeliveryReceipt(t *testing.T) {
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
p, err := a.receiving(drm)
|
p, err := a.receiving(drm)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
xMSG, ok := p.(xmpp.Message)
|
xMSG, ok := p.(stanza.Message)
|
||||||
assert.True(ok)
|
assert.True(ok)
|
||||||
rr := xMSG.Extensions[0].(xmpp.ReceiptReceived)
|
rr := xMSG.Extensions[0].(stanza.ReceiptReceived)
|
||||||
assert.Equal("im4aeseeh1IbaQui", rr.ID)
|
assert.Equal("im4aeseeh1IbaQui", rr.ID)
|
||||||
|
|
||||||
// receiving delivered -> not in cache
|
// receiving delivered -> not in cache
|
||||||
|
@ -140,9 +140,9 @@ func TestReceiveDeliveryReceipt(t *testing.T) {
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
p, err = a.receiving(drm)
|
p, err = a.receiving(drm)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
xMSG, ok = p.(xmpp.Message)
|
xMSG, ok = p.(stanza.Message)
|
||||||
assert.True(ok)
|
assert.True(ok)
|
||||||
cmdd := xMSG.Extensions[0].(xmpp.MarkDisplayed)
|
cmdd := xMSG.Extensions[0].(stanza.MarkDisplayed)
|
||||||
assert.Equal("im4aeseeh1IbaQui", cmdd.ID)
|
assert.Equal("im4aeseeh1IbaQui", cmdd.ID)
|
||||||
|
|
||||||
// receiving delivered -> not in cache
|
// receiving delivered -> not in cache
|
||||||
|
@ -159,16 +159,16 @@ func TestReceiveTyping(t *testing.T) {
|
||||||
tnm := o3.TypingNotificationMessage{}
|
tnm := o3.TypingNotificationMessage{}
|
||||||
p, err := a.receiving(tnm)
|
p, err := a.receiving(tnm)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
xMSG, ok := p.(xmpp.Message)
|
xMSG, ok := p.(stanza.Message)
|
||||||
assert.True(ok)
|
assert.True(ok)
|
||||||
assert.IsType(xmpp.StateInactive{}, xMSG.Extensions[0])
|
assert.IsType(stanza.StateInactive{}, xMSG.Extensions[0])
|
||||||
|
|
||||||
// receiving composing
|
// receiving composing
|
||||||
tnm = o3.TypingNotificationMessage{}
|
tnm = o3.TypingNotificationMessage{}
|
||||||
tnm.OnOff = 0x1
|
tnm.OnOff = 0x1
|
||||||
p, err = a.receiving(tnm)
|
p, err = a.receiving(tnm)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
xMSG, ok = p.(xmpp.Message)
|
xMSG, ok = p.(stanza.Message)
|
||||||
assert.True(ok)
|
assert.True(ok)
|
||||||
assert.IsType(xmpp.StateComposing{}, xMSG.Extensions[0])
|
assert.IsType(stanza.StateComposing{}, xMSG.Extensions[0])
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,10 @@ import (
|
||||||
|
|
||||||
"github.com/bdlm/log"
|
"github.com/bdlm/log"
|
||||||
"github.com/o3ma/o3"
|
"github.com/o3ma/o3"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *Account) Send(to string, msg xmpp.Message) error {
|
func (a *Account) Send(to string, msg stanza.Message) error {
|
||||||
m, err := a.sending(to, msg)
|
m, err := a.sending(to, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -18,7 +18,7 @@ func (a *Account) Send(to string, msg xmpp.Message) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (a *Account) sending(to string, msg xmpp.Message) (o3.Message, error) {
|
func (a *Account) sending(to string, msg stanza.Message) (o3.Message, error) {
|
||||||
logger := log.WithFields(map[string]interface{}{
|
logger := log.WithFields(map[string]interface{}{
|
||||||
"from": a.XMPP.String(),
|
"from": a.XMPP.String(),
|
||||||
"to": to,
|
"to": to,
|
||||||
|
@ -33,24 +33,24 @@ func (a *Account) sending(to string, msg xmpp.Message) (o3.Message, error) {
|
||||||
for _, el := range msg.Extensions {
|
for _, el := range msg.Extensions {
|
||||||
switch ex := el.(type) {
|
switch ex := el.(type) {
|
||||||
|
|
||||||
case *xmpp.StateActive:
|
case *stanza.StateActive:
|
||||||
chatState = true
|
chatState = true
|
||||||
case *xmpp.StateComposing:
|
case *stanza.StateComposing:
|
||||||
chatState = true
|
chatState = true
|
||||||
chatStateComposing = true
|
chatStateComposing = true
|
||||||
case *xmpp.StateGone:
|
case *stanza.StateGone:
|
||||||
chatState = true
|
chatState = true
|
||||||
case *xmpp.StateInactive:
|
case *stanza.StateInactive:
|
||||||
chatState = true
|
chatState = true
|
||||||
case *xmpp.StatePaused:
|
case *stanza.StatePaused:
|
||||||
chatState = true
|
chatState = true
|
||||||
|
|
||||||
case *xmpp.ReceiptReceived:
|
case *stanza.ReceiptReceived:
|
||||||
msgStateID = ex.ID
|
msgStateID = ex.ID
|
||||||
case *xmpp.MarkReceived:
|
case *stanza.MarkReceived:
|
||||||
msgStateID = ex.ID
|
msgStateID = ex.ID
|
||||||
|
|
||||||
case *xmpp.MarkDisplayed:
|
case *stanza.MarkDisplayed:
|
||||||
msgStateRead = true
|
msgStateRead = true
|
||||||
msgStateID = ex.ID
|
msgStateID = ex.ID
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
|
|
||||||
"github.com/o3ma/o3"
|
"github.com/o3ma/o3"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"gosrc.io/xmpp"
|
"gosrc.io/xmpp/stanza"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccountSend(t *testing.T) {
|
func TestAccountSend(t *testing.T) {
|
||||||
|
@ -20,9 +20,9 @@ func TestAccountSend(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
a.Send("a", xmpp.Message{
|
a.Send("a", stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{From: "a@example.org"},
|
Attrs: stanza.Attrs{From: "a@example.org"},
|
||||||
Body: "ohz8kai0ohNgohth",
|
Body: "ohz8kai0ohNgohth",
|
||||||
})
|
})
|
||||||
}()
|
}()
|
||||||
p := <-send
|
p := <-send
|
||||||
|
@ -31,10 +31,10 @@ func TestAccountSend(t *testing.T) {
|
||||||
assert.Contains(msg.Text(), "ohz8kai0ohNgohth")
|
assert.Contains(msg.Text(), "ohz8kai0ohNgohth")
|
||||||
|
|
||||||
// test error
|
// test error
|
||||||
err := a.Send("a", xmpp.Message{
|
err := a.Send("a", stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{From: "a@example.org"},
|
Attrs: stanza.Attrs{From: "a@example.org"},
|
||||||
Extensions: []xmpp.MsgExtension{
|
Extensions: []stanza.MsgExtension{
|
||||||
&xmpp.ReceiptReceived{ID: "blub"},
|
&stanza.ReceiptReceived{ID: "blub"},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
@ -48,20 +48,20 @@ func TestAccountSendingDeliviery(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// test error - threema send only int ids
|
// test error - threema send only int ids
|
||||||
msg, err := a.sending("a", xmpp.Message{
|
msg, err := a.sending("a", stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{From: "a@example.org"},
|
Attrs: stanza.Attrs{From: "a@example.org"},
|
||||||
Extensions: []xmpp.MsgExtension{
|
Extensions: []stanza.MsgExtension{
|
||||||
&xmpp.ReceiptReceived{ID: "blub"},
|
&stanza.ReceiptReceived{ID: "blub"},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.Nil(msg)
|
assert.Nil(msg)
|
||||||
|
|
||||||
// test delivered
|
// test delivered
|
||||||
msg, err = a.sending("a", xmpp.Message{
|
msg, err = a.sending("a", stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{From: "a@example.org"},
|
Attrs: stanza.Attrs{From: "a@example.org"},
|
||||||
Extensions: []xmpp.MsgExtension{
|
Extensions: []stanza.MsgExtension{
|
||||||
&xmpp.MarkReceived{ID: "3"},
|
&stanza.MarkReceived{ID: "3"},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
@ -70,10 +70,10 @@ func TestAccountSendingDeliviery(t *testing.T) {
|
||||||
assert.Equal(o3.MSGDELIVERED, drm.Status())
|
assert.Equal(o3.MSGDELIVERED, drm.Status())
|
||||||
|
|
||||||
// test read
|
// test read
|
||||||
msg, err = a.sending("a", xmpp.Message{
|
msg, err = a.sending("a", stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{From: "a@example.org"},
|
Attrs: stanza.Attrs{From: "a@example.org"},
|
||||||
Extensions: []xmpp.MsgExtension{
|
Extensions: []stanza.MsgExtension{
|
||||||
&xmpp.MarkDisplayed{ID: "5"},
|
&stanza.MarkDisplayed{ID: "5"},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
@ -91,37 +91,37 @@ func TestSendTyping(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip typing messae
|
// skip typing messae
|
||||||
msg, err := a.sending("a", xmpp.Message{
|
msg, err := a.sending("a", stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{From: "a@example.org"},
|
Attrs: stanza.Attrs{From: "a@example.org"},
|
||||||
Extensions: []xmpp.MsgExtension{
|
Extensions: []stanza.MsgExtension{
|
||||||
&xmpp.StateComposing{},
|
&stanza.StateComposing{},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Nil(msg)
|
assert.Nil(msg)
|
||||||
|
|
||||||
// skip gone
|
// skip gone
|
||||||
msg, err = a.sending("a", xmpp.Message{
|
msg, err = a.sending("a", stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{From: "a@example.org"},
|
Attrs: stanza.Attrs{From: "a@example.org"},
|
||||||
Extensions: []xmpp.MsgExtension{
|
Extensions: []stanza.MsgExtension{
|
||||||
&xmpp.StateActive{},
|
&stanza.StateActive{},
|
||||||
&xmpp.StateGone{},
|
&stanza.StateGone{},
|
||||||
&xmpp.StateInactive{},
|
&stanza.StateInactive{},
|
||||||
&xmpp.StatePaused{},
|
&stanza.StatePaused{},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Nil(msg)
|
assert.Nil(msg)
|
||||||
|
|
||||||
// skip gone
|
// skip gone
|
||||||
msg, err = a.sending("a", xmpp.Message{
|
msg, err = a.sending("a", stanza.Message{
|
||||||
PacketAttrs: xmpp.PacketAttrs{From: "a@example.org"},
|
Attrs: stanza.Attrs{From: "a@example.org"},
|
||||||
Extensions: []xmpp.MsgExtension{
|
Extensions: []stanza.MsgExtension{
|
||||||
&xmpp.StateActive{},
|
&stanza.StateActive{},
|
||||||
&xmpp.StateComposing{},
|
&stanza.StateComposing{},
|
||||||
&xmpp.StateGone{},
|
&stanza.StateGone{},
|
||||||
&xmpp.StateInactive{},
|
&stanza.StateInactive{},
|
||||||
&xmpp.StatePaused{},
|
&stanza.StatePaused{},
|
||||||
},
|
},
|
||||||
Body: "hi",
|
Body: "hi",
|
||||||
})
|
})
|
||||||
|
|
Reference in New Issue