aboutsummaryrefslogtreecommitdiff
path: root/connector
diff options
context:
space:
mode:
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