diff --git a/component/config.go b/component/config.go index b72927d..ebd29d3 100644 --- a/component/config.go +++ b/component/config.go @@ -29,6 +29,7 @@ func (c *Config) Start() error { router.NewRoute().IQNamespaces(stanza.NSDiscoItems).HandlerFunc(c.handleDiscoItems) router.HandleFunc("iq", c.handleIQ) router.HandleFunc("message", c.handleMessage) + router.HandleFunc("presence", c.handleMessage) c.xmpp, err = xmpp.NewComponent(xmpp.ComponentOptions{ Domain: c.Host, diff --git a/component/receiver.go b/component/receiver.go index 29a20c8..0c8558e 100644 --- a/component/receiver.go +++ b/component/receiver.go @@ -31,6 +31,7 @@ func (c *Config) handleDiscoInfo(s xmpp.Sender, p stanza.Packet) { {Var: stanza.NSMsgReceipts}, {Var: stanza.NSMsgChatMarkers}, {Var: stanza.NSMsgChatStateNotifications}, + {Var: "http://jabber.org/protocol/muc"}, }, } if discoInfo.Node == "" { @@ -98,15 +99,20 @@ func (c *Config) handleIQ(s xmpp.Sender, p stanza.Packet) { } func (c *Config) handleMessage(s xmpp.Sender, p stanza.Packet) { msg, ok := p.(stanza.Message) + attr := msg.Attrs if !ok { - return + pr, ok := p.(stanza.Message) + attr = pr.Attrs + if !ok { + return + } } if c.XMPPDebug { log.WithFields(map[string]interface{}{ "type": c.Type, "from": s, - "to": msg.To, - "id": msg.Id, + "to": attr.To, + "id": attr.Id, }).Debug(msg.XMPPFormat()) } c.comp.Send(p) diff --git a/component/threema/bot.go b/component/threema/bot.go index ab1c76a..ade9b31 100644 --- a/component/threema/bot.go +++ b/component/threema/bot.go @@ -26,8 +26,8 @@ func (t *Threema) getBot(jid *models.JID) *Bot { if db := database.Read; db != nil && db.DB().Ping() == nil { if err := db.Where(jid).First(jid); err.RecordNotFound() { database.Write.Create(jid) - } else if err != nil { - log.Errorf("error getting jid %s from datatbase: %s", jid.String(), err.Error) + } else if err.Error != nil { + log.Errorf("error getting jid %s from database: %s", jid.String(), err.Error) } } bot := &Bot{ diff --git a/component/threema/main.go b/component/threema/main.go index 1b237bd..43406ef 100644 --- a/component/threema/main.go +++ b/component/threema/main.go @@ -67,6 +67,9 @@ func (t *Threema) Send(packet stanza.Packet) { } func (t *Threema) send(packet stanza.Packet) stanza.Packet { switch p := packet.(type) { + case stanza.Presence: + log.Debug(p) + return nil case stanza.Message: from := models.ParseJID(p.Attrs.From) to := models.ParseJID(p.Attrs.To) diff --git a/component/threema/send.go b/component/threema/send.go index defaa2c..54743d0 100644 --- a/component/threema/send.go +++ b/component/threema/send.go @@ -1,7 +1,9 @@ package threema import ( + "encoding/base32" "strconv" + "strings" "github.com/bdlm/log" "github.com/o3ma/o3" @@ -32,6 +34,18 @@ func (a *Account) sending(to string, msg stanza.Message) (o3.Message, error) { Recipient: o3.NewIDString(to), PubNick: a.ThreemaID.Nick, } + var groupHeader *o3.GroupMessageHeader + if msg.Type == stanza.MessageTypeGroupchat { + toA := strings.SplitN(to, "-", 2) + gid, err := base32.StdEncoding.DecodeString(toA[1]) + if err != nil { + return nil, err + } + groupHeader = &o3.GroupMessageHeader{ + CreatorID: o3.NewIDString(toA[0]), + } + copy(groupHeader.GroupID[:], gid) + } chatState := false chatStateComposing := false @@ -102,12 +116,21 @@ func (a *Account) sending(to string, msg stanza.Message) (o3.Message, error) { MessageHeader: header, Body: msg.Body, } - a.deliveredMSG[msg3ID] = msg.Id - a.readedMSG[msg3ID] = msg.Id - logger.WithFields(map[string]interface{}{ + logger = logger.WithFields(map[string]interface{}{ "x_id": msg.Id, "t_id": msg3ID, "text": msg.Body, - }).Debug("send text") + }) + if groupHeader != nil { + logger.Debug("send grouptext") + // TODO iterate of all occupants + return &o3.GroupTextMessage{ + GroupMessageHeader: groupHeader, + TextMessage: msg3, + }, nil + } + a.deliveredMSG[msg3ID] = msg.Id + a.readedMSG[msg3ID] = msg.Id + logger.Debug("send text") return msg3, nil }