summaryrefslogtreecommitdiffstats
path: root/bridge/xmpp/xmpp.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-02-23 23:03:21 +0100
committerGitHub <noreply@github.com>2019-02-23 23:03:21 +0100
commita775b5713471fe92e107498d3f79314ffa4d5eb9 (patch)
tree1d1bfea2f11d8298cbd3aa743cebb2393fe362c4 /bridge/xmpp/xmpp.go
parentbf21604d425b4feb1b95e4e94643e7a658eeea90 (diff)
downloadmatterbridge-msglm-a775b5713471fe92e107498d3f79314ffa4d5eb9.tar.gz
matterbridge-msglm-a775b5713471fe92e107498d3f79314ffa4d5eb9.tar.bz2
matterbridge-msglm-a775b5713471fe92e107498d3f79314ffa4d5eb9.zip
Do not send topic changes on connect (xmpp). Fixes #732 (#733)
This checks if we get a topic change < 5 seconds after connection. If that's the case, ignore it. Also this PR makes the topic change an actual EventTopicChange.
Diffstat (limited to 'bridge/xmpp/xmpp.go')
-rw-r--r--bridge/xmpp/xmpp.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go
index 75fc83a4..6fc573bf 100644
--- a/bridge/xmpp/xmpp.go
+++ b/bridge/xmpp/xmpp.go
@@ -17,6 +17,7 @@ type Bxmpp struct {
xc *xmpp.Client
xmppMap map[string]string
*bridge.Config
+ startTime time.Time
}
func New(cfg *bridge.Config) bridge.Bridger {
@@ -153,6 +154,7 @@ func (b *Bxmpp) xmppKeepAlive() chan bool {
func (b *Bxmpp) handleXMPP() error {
var ok bool
var msgid string
+ b.startTime = time.Now()
done := b.xmppKeepAlive()
defer close(done)
for {
@@ -164,15 +166,27 @@ func (b *Bxmpp) handleXMPP() error {
case xmpp.Chat:
if v.Type == "groupchat" {
b.Log.Debugf("== Receiving %#v", v)
+ event := ""
// skip invalid messages
if b.skipMessage(v) {
continue
}
+ if strings.Contains(v.Text, "has set the subject to:") {
+ event = config.EventTopicChange
+ }
msgid = v.ID
if v.ReplaceID != "" {
msgid = v.ReplaceID
}
- rmsg := config.Message{Username: b.parseNick(v.Remote), Text: v.Text, Channel: b.parseChannel(v.Remote), Account: b.Account, UserID: v.Remote, ID: msgid}
+ rmsg := config.Message{
+ Username: b.parseNick(v.Remote),
+ Text: v.Text,
+ Channel: b.parseChannel(v.Remote),
+ Account: b.Account,
+ UserID: v.Remote,
+ ID: msgid,
+ Event: event,
+ }
// check if we have an action event
rmsg.Text, ok = b.replaceAction(rmsg.Text)
@@ -259,6 +273,11 @@ func (b *Bxmpp) skipMessage(message xmpp.Chat) bool {
return true
}
+ // do not show subjects on connect #732
+ if strings.Contains(message.Text, "has set the subject to:") && time.Since(b.startTime) < time.Second*5 {
+ return true
+ }
+
// skip delayed messages
t := time.Time{}
return message.Stamp != t