aboutsummaryrefslogtreecommitdiff
path: root/connector
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-17 09:41:08 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-17 09:41:08 +0100
commit400c67f7352371f570e38531d7e033cfe6c87898 (patch)
tree2e02b25a086ceed75930ba2b4248b463bfca7226 /connector
parentc3b941841e193c1d5c32f9d6226a95475d627249 (diff)
downloadeasybridge-400c67f7352371f570e38531d7e033cfe6c87898.tar.gz
easybridge-400c67f7352371f570e38531d7e033cfe6c87898.zip
Logging; fix xmpp a bit
Diffstat (limited to 'connector')
-rw-r--r--connector/irc/irc.go4
-rw-r--r--connector/xmpp/xmpp.go39
2 files changed, 38 insertions, 5 deletions
diff --git a/connector/irc/irc.go b/connector/irc/irc.go
index 77359d0..8e5cdb0 100644
--- a/connector/irc/irc.go
+++ b/connector/irc/irc.go
@@ -6,9 +6,9 @@ import (
"strings"
"fmt"
- . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
-
"github.com/lrstanley/girc"
+
+ . "git.deuxfleurs.fr/Deuxfleurs/easybridge/connector"
)
// User id format: nickname@server
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