aboutsummaryrefslogtreecommitdiff
path: root/connector/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'connector/xmpp')
-rw-r--r--connector/xmpp/xmpp.go39
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