Skip to content

Commit

Permalink
Make reactions/redactions work for old unencrypted messages
Browse files Browse the repository at this point in the history
Also disable read receipts completely for those
  • Loading branch information
tulir committed Feb 9, 2024
1 parent fe742c7 commit ecf0960
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions database/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,7 @@ func (msg *Message) EditTimestamp() int64 {
func (msg *Message) UpdateEditTimestamp(ctx context.Context, ts int64) error {
return msg.UpdateEditCount(ctx, ts)
}

func (msg *Message) IsUnencrypted() bool {
return strings.HasPrefix(msg.ID, "mid.$")
}
8 changes: 4 additions & 4 deletions portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ func (portal *Portal) handleMatrixReadReceiptForWhatsApp(ctx context.Context, se
groupedMessages := make(map[types.JID][]types.MessageID)
for _, msg := range messages {
var key types.JID
if msg.Sender == sender.MetaID {
// Don't send read receipts for own messages or fake messages
if msg.Sender == sender.MetaID || msg.IsUnencrypted() {
// Don't send read receipts for own messages or unencrypted messages
continue
} else if !portal.IsPrivateChat() {
// TODO: this is hacky since it hardcodes the server
Expand Down Expand Up @@ -743,7 +743,7 @@ func (portal *Portal) handleMatrixRedaction(ctx context.Context, sender *User, e
portal.sendMessageStatusCheckpointFailed(ctx, evt, errRedactionTargetSentBySomeoneElse)
return
}
if portal.ThreadType.IsWhatsApp() {
if !dbMessage.IsUnencrypted() {
consumerMsg := wrapRevoke(&waConsumerApplication.ConsumerApplication_RevokeMessage{
Key: portal.buildMessageKey(sender, dbMessage),
})
Expand Down Expand Up @@ -877,7 +877,7 @@ func (portal *Portal) buildMessageKey(user *User, targetMsg *database.Message) *
}

func (portal *Portal) sendReaction(ctx context.Context, sender *User, targetMsg *database.Message, metaEmoji string, timestamp int64) error {
if portal.ThreadType.IsWhatsApp() {
if !targetMsg.IsUnencrypted() {
consumerMsg := wrapReaction(&waConsumerApplication.ConsumerApplication_ReactionMessage{
Key: portal.buildMessageKey(sender, targetMsg),
Text: metaEmoji,
Expand Down

0 comments on commit ecf0960

Please sign in to comment.