Skip to content

Commit a775b57

Browse files
authored
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.
1 parent bf21604 commit a775b57

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

bridge/xmpp/xmpp.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Bxmpp struct {
1717
xc *xmpp.Client
1818
xmppMap map[string]string
1919
*bridge.Config
20+
startTime time.Time
2021
}
2122

2223
func New(cfg *bridge.Config) bridge.Bridger {
@@ -153,6 +154,7 @@ func (b *Bxmpp) xmppKeepAlive() chan bool {
153154
func (b *Bxmpp) handleXMPP() error {
154155
var ok bool
155156
var msgid string
157+
b.startTime = time.Now()
156158
done := b.xmppKeepAlive()
157159
defer close(done)
158160
for {
@@ -164,15 +166,27 @@ func (b *Bxmpp) handleXMPP() error {
164166
case xmpp.Chat:
165167
if v.Type == "groupchat" {
166168
b.Log.Debugf("== Receiving %#v", v)
169+
event := ""
167170
// skip invalid messages
168171
if b.skipMessage(v) {
169172
continue
170173
}
174+
if strings.Contains(v.Text, "has set the subject to:") {
175+
event = config.EventTopicChange
176+
}
171177
msgid = v.ID
172178
if v.ReplaceID != "" {
173179
msgid = v.ReplaceID
174180
}
175-
rmsg := config.Message{Username: b.parseNick(v.Remote), Text: v.Text, Channel: b.parseChannel(v.Remote), Account: b.Account, UserID: v.Remote, ID: msgid}
181+
rmsg := config.Message{
182+
Username: b.parseNick(v.Remote),
183+
Text: v.Text,
184+
Channel: b.parseChannel(v.Remote),
185+
Account: b.Account,
186+
UserID: v.Remote,
187+
ID: msgid,
188+
Event: event,
189+
}
176190

177191
// check if we have an action event
178192
rmsg.Text, ok = b.replaceAction(rmsg.Text)
@@ -259,6 +273,11 @@ func (b *Bxmpp) skipMessage(message xmpp.Chat) bool {
259273
return true
260274
}
261275

276+
// do not show subjects on connect #732
277+
if strings.Contains(message.Text, "has set the subject to:") && time.Since(b.startTime) < time.Second*5 {
278+
return true
279+
}
280+
262281
// skip delayed messages
263282
t := time.Time{}
264283
return message.Stamp != t

0 commit comments

Comments
 (0)