Don't create portals for stub messages

This commit is contained in:
Tulir Asokan 2021-03-19 21:14:01 +02:00
parent 93953ec48f
commit 24d172fd55

View file

@ -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")