From e8353799787c2d7472c4593ecf2f34e07d4771b1 Mon Sep 17 00:00:00 2001 From: Marcos Travasso Date: Wed, 20 Nov 2024 13:29:04 -0300 Subject: [PATCH] appstate: add delete for me --- appstate/encode.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/appstate/encode.go b/appstate/encode.go index 20d91f3d..2bedb8ab 100644 --- a/appstate/encode.go +++ b/appstate/encode.go @@ -243,6 +243,37 @@ func BuildStar(target, sender types.JID, messageID types.MessageID, fromMe, star } } +func newDeleteForMeMutation(targetJID, senderJID string, messageInfo types.MessageInfo, fromMe string, deleteMedia bool) MutationInfo { + return MutationInfo{ + Index: []string{IndexDeleteMessageForMe, targetJID, messageInfo.ID, fromMe, senderJID}, + Version: 2, + Value: &waProto.SyncActionValue{ + DeleteMessageForMeAction: &waProto.DeleteMessageForMeAction{ + DeleteMedia: proto.Bool(deleteMedia), + MessageTimestamp: proto.Int64(messageInfo.Timestamp.UnixMilli()), + }, + }, + } +} + +// BuildDeleteForMe builds an app state patch for deleting a message for me. +func BuildDeleteForMe(messageInfo types.MessageInfo, deleteMedia bool) PatchInfo { + isFromMe := "0" + if messageInfo.IsFromMe { + isFromMe = "1" + } + targetJID, senderJID := messageInfo.Chat.String(), messageInfo.Sender.String() + if messageInfo.Chat.User == messageInfo.Sender.User { + senderJID = "0" + } + return PatchInfo{ + Type: WAPatchRegularHigh, + Mutations: []MutationInfo{ + newDeleteForMeMutation(targetJID, senderJID, messageInfo, isFromMe, deleteMedia), + }, + } +} + func (proc *Processor) EncodePatch(keyID []byte, state HashState, patchInfo PatchInfo) ([]byte, error) { keys, err := proc.getAppStateKey(keyID) if err != nil {