diff --git a/config/upgrade.go b/config/upgrade.go index 00cd3da..8b0fb95 100644 --- a/config/upgrade.go +++ b/config/upgrade.go @@ -118,6 +118,7 @@ func DoUpgrade(helper *up.Helper) { helper.Copy(up.Bool, "bridge", "encryption", "default") helper.Copy(up.Bool, "bridge", "encryption", "require") helper.Copy(up.Bool, "bridge", "encryption", "appservice") + helper.Copy(up.Bool, "bridge", "encryption", "plaintext_mentions") helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "receive") helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "send") helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "share") diff --git a/example-config.yaml b/example-config.yaml index 632fab6..c38302b 100644 --- a/example-config.yaml +++ b/example-config.yaml @@ -354,6 +354,8 @@ bridge: # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. # You must use a client that supports requesting keys from other users to use this feature. allow_key_sharing: false + # Should users mentions be in the event wire content to enable the server to send push notifications? + plaintext_mentions: false # What level of device verification should be required from users? # # Valid levels: diff --git a/formatting.go b/formatting.go index 3adb86e..9bd4360 100644 --- a/formatting.go +++ b/formatting.go @@ -1,5 +1,5 @@ // mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge. -// Copyright (C) 2021 Tulir Asokan +// Copyright (C) 2023 Tulir Asokan // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by @@ -125,6 +125,8 @@ func (formatter *Formatter) ParseWhatsApp(roomID id.RoomID, content *event.Messa return fmt.Sprintf(`%s`, groups[2], groups[1]) }) } + alreadyMentioned := make(map[id.UserID]struct{}) + content.Mentions = &event.Mentions{} for _, rawJID := range mentionedJIDs { jid, err := types.ParseJID(rawJID) if err != nil { @@ -136,7 +138,12 @@ func (formatter *Formatter) ParseWhatsApp(roomID id.RoomID, content *event.Messa number := "@" + jid.User output = strings.ReplaceAll(output, number, fmt.Sprintf(`%s`, mxid, displayname)) content.Body = strings.ReplaceAll(content.Body, number, displayname) + if _, ok := alreadyMentioned[mxid]; !ok { + alreadyMentioned[mxid] = struct{}{} + content.Mentions.UserIDs = append(content.Mentions.UserIDs, mxid) + } } + content.UnstableMentions = content.Mentions if output != content.Body || forceHTML { output = strings.ReplaceAll(output, "\n", "
") content.FormattedBody = output diff --git a/go.mod b/go.mod index c32f005..8dbefd0 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( golang.org/x/net v0.6.0 google.golang.org/protobuf v1.28.1 maunium.net/go/maulogger/v2 v2.4.1 - maunium.net/go/mautrix v0.15.0-beta.1.0.20230226232632-00f40652f33d + maunium.net/go/mautrix v0.15.0-beta.2 ) require ( diff --git a/go.sum b/go.sum index 2aad86e..1f0e342 100644 --- a/go.sum +++ b/go.sum @@ -127,5 +127,5 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M= maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA= maunium.net/go/maulogger/v2 v2.4.1 h1:N7zSdd0mZkB2m2JtFUsiGTQQAdP0YeFWT7YMc80yAL8= maunium.net/go/maulogger/v2 v2.4.1/go.mod h1:omPuYwYBILeVQobz8uO3XC8DIRuEb5rXYlQSuqrbCho= -maunium.net/go/mautrix v0.15.0-beta.1.0.20230226232632-00f40652f33d h1:16Q4co5TusYEovGLiHSkT6FY6fFn5tNNLCR3FvGCLFk= -maunium.net/go/mautrix v0.15.0-beta.1.0.20230226232632-00f40652f33d/go.mod h1:AE3TCX9q4W7fYfrL/1RsuOell9rTUBO27XUULuwArH4= +maunium.net/go/mautrix v0.15.0-beta.2 h1:J7sEehF7taahVtoCsM6E41VauaBNQMPCCcxYCe/0Zbk= +maunium.net/go/mautrix v0.15.0-beta.2/go.mod h1:AE3TCX9q4W7fYfrL/1RsuOell9rTUBO27XUULuwArH4=