diff options
author | Alex Auvolat <alex@adnab.me> | 2020-02-17 09:41:08 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-02-17 09:41:08 +0100 |
commit | 400c67f7352371f570e38531d7e033cfe6c87898 (patch) | |
tree | 2e02b25a086ceed75930ba2b4248b463bfca7226 /connector/xmpp | |
parent | c3b941841e193c1d5c32f9d6226a95475d627249 (diff) | |
download | easybridge-400c67f7352371f570e38531d7e033cfe6c87898.tar.gz easybridge-400c67f7352371f570e38531d7e033cfe6c87898.zip |
Logging; fix xmpp a bit
Diffstat (limited to 'connector/xmpp')
-rw-r--r-- | connector/xmpp/xmpp.go | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go index 2b2977e..5b1c71a 100644 --- a/connector/xmpp/xmpp.go +++ b/connector/xmpp/xmpp.go @@ -1,16 +1,16 @@ package xmpp import ( - "log" "time" //"os" "strings" "fmt" "crypto/tls" - . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" - + log "github.com/sirupsen/logrus" gxmpp "github.com/mattn/go-xmpp" + + . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector" ) // User id format: username@server (= JID) @@ -34,6 +34,8 @@ type XMPP struct { nickname string conn *gxmpp.Client + + isMUC map[string]bool } func (xm *XMPP) SetHandler(h Handler) { @@ -87,6 +89,10 @@ func (xm *XMPP) Configure(c Configuration) error { } // Try to connect + if xm.isMUC == nil { + xm.isMUC = make(map[string]bool) + } + xm.connectorLoopNum += 1 go xm.connectLoop(xm.connectorLoopNum) @@ -171,10 +177,23 @@ func (xm *XMPP) handleXMPP() error { return err } + fmt.Printf("XMPP: %#v\n", m) + switch v := m.(type) { case gxmpp.Chat: log.Printf("== Receiving %#v\n", v) + if v.Text == "" && v.Type == "groupchat" && !strings.Contains(v.Remote, "/") { + // Empty message when we joined group chat + xm.handler.Joined(RoomID(v.Remote)) + if v.Subject != "" { + xm.handler.RoomInfoUpdated(RoomID(v.Remote), &RoomInfo{ + Description: v.Subject, + }) + } + continue + } + if v.Text == "" || v.Remote == xm.jid { continue } @@ -212,6 +231,18 @@ func (xm *XMPP) handleXMPP() error { xm.handler.Event(event) } case gxmpp.Presence: + remote := strings.Split(v.From, "/") + if muc, ok := xm.isMUC[remote[0]]; ok && muc && len(remote) == 2 { + event := &Event{ + Type: EVENT_JOIN, + Room: RoomID(remote[0]), + Author: UserID(remote[1] + "@" + remote[0]), + } + if v.Type == "unavailable" { + event.Type = EVENT_LEAVE + } + xm.handler.Event(event) + } // Do nothing. } } @@ -232,6 +263,8 @@ func (xm *XMPP) SetRoomInfo(roomId RoomID, info *RoomInfo) error { } func (xm *XMPP) Join(roomId RoomID) error { + xm.isMUC[string(roomId)] = true + fmt.Printf("Join %s with nick %s\n", roomId, xm.nickname) _, err := xm.conn.JoinMUCNoHistory(string(roomId), xm.nickname) return err |