mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-24 11:42:03 -08:00
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.
This commit is contained in:
parent
bf21604d42
commit
a775b57134
@ -17,6 +17,7 @@ type Bxmpp struct {
|
|||||||
xc *xmpp.Client
|
xc *xmpp.Client
|
||||||
xmppMap map[string]string
|
xmppMap map[string]string
|
||||||
*bridge.Config
|
*bridge.Config
|
||||||
|
startTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg *bridge.Config) bridge.Bridger {
|
func New(cfg *bridge.Config) bridge.Bridger {
|
||||||
@ -153,6 +154,7 @@ func (b *Bxmpp) xmppKeepAlive() chan bool {
|
|||||||
func (b *Bxmpp) handleXMPP() error {
|
func (b *Bxmpp) handleXMPP() error {
|
||||||
var ok bool
|
var ok bool
|
||||||
var msgid string
|
var msgid string
|
||||||
|
b.startTime = time.Now()
|
||||||
done := b.xmppKeepAlive()
|
done := b.xmppKeepAlive()
|
||||||
defer close(done)
|
defer close(done)
|
||||||
for {
|
for {
|
||||||
@ -164,15 +166,27 @@ func (b *Bxmpp) handleXMPP() error {
|
|||||||
case xmpp.Chat:
|
case xmpp.Chat:
|
||||||
if v.Type == "groupchat" {
|
if v.Type == "groupchat" {
|
||||||
b.Log.Debugf("== Receiving %#v", v)
|
b.Log.Debugf("== Receiving %#v", v)
|
||||||
|
event := ""
|
||||||
// skip invalid messages
|
// skip invalid messages
|
||||||
if b.skipMessage(v) {
|
if b.skipMessage(v) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if strings.Contains(v.Text, "has set the subject to:") {
|
||||||
|
event = config.EventTopicChange
|
||||||
|
}
|
||||||
msgid = v.ID
|
msgid = v.ID
|
||||||
if v.ReplaceID != "" {
|
if v.ReplaceID != "" {
|
||||||
msgid = 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
|
// check if we have an action event
|
||||||
rmsg.Text, ok = b.replaceAction(rmsg.Text)
|
rmsg.Text, ok = b.replaceAction(rmsg.Text)
|
||||||
@ -259,6 +273,11 @@ func (b *Bxmpp) skipMessage(message xmpp.Chat) bool {
|
|||||||
return true
|
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
|
// skip delayed messages
|
||||||
t := time.Time{}
|
t := time.Time{}
|
||||||
return message.Stamp != t
|
return message.Stamp != t
|
||||||
|
Loading…
Reference in New Issue
Block a user