From 24d172fd559cd26ca202960f99627b8fd4f5466d Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 19 Mar 2021 21:14:01 +0200 Subject: [PATCH] Don't create portals for stub messages --- portal.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/portal.go b/portal.go index 1e98bfb..f9be041 100644 --- a/portal.go +++ b/portal.go @@ -196,7 +196,10 @@ func (portal *Portal) handleMessageLoop() { for msg := range portal.messages { if len(portal.MXID) == 0 { if msg.timestamp+MaxMessageAgeToCreatePortal < uint64(time.Now().Unix()) { - portal.log.Debugln("Not creating portal room for incoming message as the message is too old.") + portal.log.Debugln("Not creating portal room for incoming message: message is too old") + continue + } else if !portal.shouldCreateRoom(msg) { + portal.log.Debugln("Not creating portal room for incoming message: message is not a chat message") continue } portal.log.Debugln("Creating Matrix room from incoming message") @@ -212,6 +215,16 @@ func (portal *Portal) handleMessageLoop() { } } +func (portal *Portal) shouldCreateRoom(msg PortalMessage) bool { + stubMsg, ok := msg.data.(whatsapp.StubMessage) + if ok { + // This could be more specific: if someone else was added, we might not care, + // but if the local user was added, we definitely care. + return stubMsg.Type == waProto.WebMessageInfo_GROUP_PARTICIPANT_ADD || stubMsg.Type == waProto.WebMessageInfo_GROUP_PARTICIPANT_INVITE + } + return true +} + func (portal *Portal) handleMessage(msg PortalMessage, isBackfill bool) { if len(portal.MXID) == 0 { portal.log.Warnln("handleMessage called even though portal.MXID is empty")