Compare commits
No commits in common. "updatexmppp" and "master" have entirely different histories.
updatexmpp
...
master
@ -14,7 +14,6 @@ import (
|
|||||||
"github.com/42wim/matterbridge/bridge"
|
"github.com/42wim/matterbridge/bridge"
|
||||||
"github.com/42wim/matterbridge/bridge/config"
|
"github.com/42wim/matterbridge/bridge/config"
|
||||||
"github.com/42wim/matterbridge/bridge/helper"
|
"github.com/42wim/matterbridge/bridge/helper"
|
||||||
lru "github.com/hashicorp/golang-lru"
|
|
||||||
"github.com/jpillora/backoff"
|
"github.com/jpillora/backoff"
|
||||||
"github.com/matterbridge/go-xmpp"
|
"github.com/matterbridge/go-xmpp"
|
||||||
"github.com/rs/xid"
|
"github.com/rs/xid"
|
||||||
@ -29,20 +28,13 @@ type Bxmpp struct {
|
|||||||
connected bool
|
connected bool
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
|
||||||
StanzaIDs *lru.Cache
|
|
||||||
OriginIDs *lru.Cache
|
|
||||||
|
|
||||||
avatarAvailability map[string]bool
|
avatarAvailability map[string]bool
|
||||||
avatarMap map[string]string
|
avatarMap map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *bridge.Config) bridge.Bridger {
|
func New(cfg *bridge.Config) bridge.Bridger {
|
||||||
stanzaIDs, _ := lru.New(5000)
|
|
||||||
originIDs, _ := lru.New(5000)
|
|
||||||
return &Bxmpp{
|
return &Bxmpp{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
StanzaIDs: stanzaIDs,
|
|
||||||
OriginIDs: originIDs,
|
|
||||||
xmppMap: make(map[string]string),
|
xmppMap: make(map[string]string),
|
||||||
avatarAvailability: make(map[string]bool),
|
avatarAvailability: make(map[string]bool),
|
||||||
avatarMap: make(map[string]string),
|
avatarMap: make(map[string]string),
|
||||||
@ -132,20 +124,12 @@ func (b *Bxmpp) Send(msg config.Message) (string, error) {
|
|||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if msg.ParentNotFound() {
|
|
||||||
msg.ParentID = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// Post normal message.
|
// Post normal message.
|
||||||
var msgReplaceID string
|
var msgReplaceID string
|
||||||
msgID := xid.New().String()
|
msgID := xid.New().String()
|
||||||
if msg.ID != "" {
|
if msg.ID != "" {
|
||||||
msgReplaceID = msg.ID
|
msgReplaceID = msg.ID
|
||||||
}
|
}
|
||||||
var replyID string
|
|
||||||
if res, ok := b.StanzaIDs.Get(msg.ParentID); ok {
|
|
||||||
replyID, _ = res.(string)
|
|
||||||
}
|
|
||||||
b.Log.Debugf("=> Sending message %#v", msg)
|
b.Log.Debugf("=> Sending message %#v", msg)
|
||||||
if _, err := b.xc.Send(xmpp.Chat{
|
if _, err := b.xc.Send(xmpp.Chat{
|
||||||
Type: "groupchat",
|
Type: "groupchat",
|
||||||
@ -153,7 +137,6 @@ func (b *Bxmpp) Send(msg config.Message) (string, error) {
|
|||||||
Text: msg.Username + msg.Text,
|
Text: msg.Username + msg.Text,
|
||||||
ID: msgID,
|
ID: msgID,
|
||||||
ReplaceID: msgReplaceID,
|
ReplaceID: msgReplaceID,
|
||||||
ReplyID: replyID,
|
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -314,11 +297,6 @@ func (b *Bxmpp) handleXMPP() error {
|
|||||||
if v.Type == "groupchat" {
|
if v.Type == "groupchat" {
|
||||||
b.Log.Debugf("== Receiving %#v", v)
|
b.Log.Debugf("== Receiving %#v", v)
|
||||||
|
|
||||||
if v.ID != "" && v.StanzaID != "" {
|
|
||||||
b.StanzaIDs.Add(v.ID, v.StanzaID)
|
|
||||||
b.OriginIDs.Add(v.StanzaID, v.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip invalid messages.
|
// Skip invalid messages.
|
||||||
if b.skipMessage(v) {
|
if b.skipMessage(v) {
|
||||||
continue
|
continue
|
||||||
@ -343,12 +321,6 @@ func (b *Bxmpp) handleXMPP() error {
|
|||||||
if v.ReplaceID != "" {
|
if v.ReplaceID != "" {
|
||||||
msgID = v.ReplaceID
|
msgID = v.ReplaceID
|
||||||
}
|
}
|
||||||
|
|
||||||
var parentID string
|
|
||||||
if res, ok := b.OriginIDs.Get(v.ReplyID); ok {
|
|
||||||
parentID, _ = res.(string)
|
|
||||||
}
|
|
||||||
|
|
||||||
rmsg := config.Message{
|
rmsg := config.Message{
|
||||||
Username: b.parseNick(v.Remote),
|
Username: b.parseNick(v.Remote),
|
||||||
Text: v.Text,
|
Text: v.Text,
|
||||||
@ -356,7 +328,6 @@ func (b *Bxmpp) handleXMPP() error {
|
|||||||
Account: b.Account,
|
Account: b.Account,
|
||||||
Avatar: avatar,
|
Avatar: avatar,
|
||||||
UserID: v.Remote,
|
UserID: v.Remote,
|
||||||
ParentID: parentID,
|
|
||||||
ID: msgID,
|
ID: msgID,
|
||||||
Event: event,
|
Event: event,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user