aboutsummaryrefslogtreecommitdiff
path: root/connector/xmpp/xmpp.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-17 18:11:34 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-17 18:11:34 +0100
commit4d16a3e43603c6456f9137fca8bcfe3059069108 (patch)
tree91439c2458037b604360c3d0ec64aa6a9e7e834c /connector/xmpp/xmpp.go
parent86942a34a2aa086dee76c9e4e0b6942848e1b979 (diff)
downloadeasybridge-wip_xmpp_avatar.tar.gz
easybridge-wip_xmpp_avatar.zip
WIP IQ for avatarswip_xmpp_avatar
Diffstat (limited to 'connector/xmpp/xmpp.go')
-rw-r--r--connector/xmpp/xmpp.go63
1 files changed, 59 insertions, 4 deletions
diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go
index e50bb58..a62cdc4 100644
--- a/connector/xmpp/xmpp.go
+++ b/connector/xmpp/xmpp.go
@@ -6,9 +6,11 @@ import (
"strings"
"fmt"
"crypto/tls"
+ "encoding/xml"
log "github.com/sirupsen/logrus"
- gxmpp "github.com/mattn/go-xmpp"
+ //gxmpp "github.com/mattn/go-xmpp"
+ gxmpp "git.deuxfleurs.fr/lx/go-xmpp"
. "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
)
@@ -177,10 +179,10 @@ func (xm *XMPP) handleXMPP() error {
return err
}
- fmt.Printf("XMPP: %#v\n", m)
switch v := m.(type) {
case gxmpp.Chat:
+ fmt.Printf("XMPP chat: %#v\n", v)
remote_sp := strings.Split(v.Remote, "/")
// Skip self-sent events
@@ -228,6 +230,8 @@ func (xm *XMPP) handleXMPP() error {
}
}
case gxmpp.Presence:
+ fmt.Printf("XMPP presence: %#v\n", v)
+
remote := strings.Split(v.From, "/")
if ismuc, ok := xm.isMUC[remote[0]]; ok && ismuc {
// skip presence with no user and self-presence
@@ -248,8 +252,59 @@ func (xm *XMPP) handleXMPP() error {
xm.handler.UserInfoUpdated(user, &UserInfo{
DisplayName: remote[1],
})
+ } else {
+ // Send discovery query
+ iq, err := xml.Marshal(&DiscoQuery{})
+ if err != nil {
+ fmt.Printf("XML marshall error: %s\n", err)
+ } else {
+ xm.conn.SendIQ(gxmpp.IQ{
+ Type: "get",
+ To: remote[0],
+ ID: "items1",
+ Query: iq,
+ })
+ }
+ }
+ case gxmpp.IQ:
+ fmt.Printf("XMPP iq: from=%s to=%s id=%s type=%s\n", v.From, v.To, v.ID, v.Type)
+ if len(v.Query) > 0 {
+ fmt.Printf("Query data: %s\n", string(v.Query))
+ }
+
+ if v.Type == "result" && v.ID == "items1" {
+ var q DiscoQuery
+ err := xml.Unmarshal(v.Query, &q)
+ if err != nil {
+ fmt.Printf("XML unmarshall error: %s\n", err)
+ continue
+ }
+
+ for _, item := range q.Items {
+ if item.Node == "urn:xmpp:avatar:metadata" || item.Node == "urn:xmpp:avatar:data" {
+ sub := &PubSub{
+ Subscribe: []Subscribe{
+ Subscribe{
+ Jid: xm.jid,
+ Node: item.Node,
+ },
+ },
+ }
+ iq, err := xml.Marshal(sub)
+ if err != nil {
+ fmt.Printf("XML marshall error: %s\n", err)
+ } else {
+ fmt.Printf("IQ AVATAR SUB: %s\n", iq)
+ xm.conn.SendIQ(gxmpp.IQ{
+ To: v.From,
+ Type: "set",
+ ID: "sub1",
+ Query: iq,
+ })
+ }
+ }
+ }
}
- // Do nothing.
}
}
}
@@ -297,7 +352,7 @@ func (xm *XMPP) Invite(userId UserID, roomId RoomID) error {
}
func (xm *XMPP) Leave(roomId RoomID) {
- // TODO
+ xm.conn.LeaveMUC(string(roomId))
}
func (xm *XMPP) Send(event *Event) error {