@@ -32,6 +32,8 @@ type PatchInfo struct {
32
32
Timestamp time.Time
33
33
// Type is the app state type being mutated.
34
34
Type WAPatchName
35
+ // Operation is SET / REMOVE
36
+ Operation waServerSync.SyncdMutation_SyncdOperation
35
37
// Mutations contains the individual mutations to apply to the app state in this patch.
36
38
Mutations []MutationInfo
37
39
}
@@ -46,7 +48,8 @@ func BuildMute(target types.JID, mute bool, muteDuration time.Duration) PatchInf
46
48
}
47
49
48
50
return PatchInfo {
49
- Type : WAPatchRegularHigh ,
51
+ Type : WAPatchRegularHigh ,
52
+ Operation : waServerSync .SyncdMutation_SET ,
50
53
Mutations : []MutationInfo {{
51
54
Index : []string {IndexMute , target .String ()},
52
55
Version : 2 ,
@@ -60,6 +63,27 @@ func BuildMute(target types.JID, mute bool, muteDuration time.Duration) PatchInf
60
63
}
61
64
}
62
65
66
+ func BuildContact (target types.JID , fullName string , add bool ) PatchInfo {
67
+ operation := waServerSync .SyncdMutation_SET
68
+ if ! add {
69
+ operation = waServerSync .SyncdMutation_REMOVE
70
+ }
71
+ return PatchInfo {
72
+ Type : WAPatchCriticalUnblockLow ,
73
+ Operation : operation ,
74
+ Mutations : []MutationInfo {{
75
+ Index : []string {IndexContact , target .String ()},
76
+ Version : 2 ,
77
+ Value : & waSyncAction.SyncActionValue {
78
+ ContactAction : & waSyncAction.ContactAction {
79
+ FullName : & fullName ,
80
+ SaveOnPrimaryAddressbook : proto .Bool (add ),
81
+ },
82
+ },
83
+ }},
84
+ }
85
+ }
86
+
63
87
func newPinMutationInfo (target types.JID , pin bool ) MutationInfo {
64
88
return MutationInfo {
65
89
Index : []string {IndexPin , target .String ()},
@@ -75,7 +99,8 @@ func newPinMutationInfo(target types.JID, pin bool) MutationInfo {
75
99
// BuildPin builds an app state patch for pinning or unpinning a chat.
76
100
func BuildPin (target types.JID , pin bool ) PatchInfo {
77
101
return PatchInfo {
78
- Type : WAPatchRegularLow ,
102
+ Type : WAPatchRegularLow ,
103
+ Operation : waServerSync .SyncdMutation_SET ,
79
104
Mutations : []MutationInfo {
80
105
newPinMutationInfo (target , pin ),
81
106
},
@@ -119,6 +144,7 @@ func BuildArchive(target types.JID, archive bool, lastMessageTimestamp time.Time
119
144
120
145
result := PatchInfo {
121
146
Type : WAPatchRegularLow ,
147
+ Operation : waServerSync .SyncdMutation_SET ,
122
148
Mutations : mutations ,
123
149
}
124
150
@@ -140,7 +166,8 @@ func newLabelChatMutation(target types.JID, labelID string, labeled bool) Mutati
140
166
// BuildLabelChat builds an app state patch for labeling or un(labeling) a chat.
141
167
func BuildLabelChat (target types.JID , labelID string , labeled bool ) PatchInfo {
142
168
return PatchInfo {
143
- Type : WAPatchRegular ,
169
+ Type : WAPatchRegular ,
170
+ Operation : waServerSync .SyncdMutation_SET ,
144
171
Mutations : []MutationInfo {
145
172
newLabelChatMutation (target , labelID , labeled ),
146
173
},
@@ -162,7 +189,8 @@ func newLabelMessageMutation(target types.JID, labelID, messageID string, labele
162
189
// BuildLabelMessage builds an app state patch for labeling or un(labeling) a message.
163
190
func BuildLabelMessage (target types.JID , labelID , messageID string , labeled bool ) PatchInfo {
164
191
return PatchInfo {
165
- Type : WAPatchRegular ,
192
+ Type : WAPatchRegular ,
193
+ Operation : waServerSync .SyncdMutation_SET ,
166
194
Mutations : []MutationInfo {
167
195
newLabelMessageMutation (target , labelID , messageID , labeled ),
168
196
},
@@ -186,7 +214,8 @@ func newLabelEditMutation(labelID string, labelName string, labelColor int32, de
186
214
// BuildLabelEdit builds an app state patch for editing a label.
187
215
func BuildLabelEdit (labelID string , labelName string , labelColor int32 , deleted bool ) PatchInfo {
188
216
return PatchInfo {
189
- Type : WAPatchRegular ,
217
+ Type : WAPatchRegular ,
218
+ Operation : waServerSync .SyncdMutation_SET ,
190
219
Mutations : []MutationInfo {
191
220
newLabelEditMutation (labelID , labelName , labelColor , deleted ),
192
221
},
@@ -208,7 +237,8 @@ func newSettingPushNameMutation(pushName string) MutationInfo {
208
237
// BuildSettingPushName builds an app state patch for setting the push name.
209
238
func BuildSettingPushName (pushName string ) PatchInfo {
210
239
return PatchInfo {
211
- Type : WAPatchCriticalBlock ,
240
+ Type : WAPatchCriticalBlock ,
241
+ Operation : waServerSync .SyncdMutation_SET ,
212
242
Mutations : []MutationInfo {
213
243
newSettingPushNameMutation (pushName ),
214
244
},
@@ -238,7 +268,8 @@ func BuildStar(target, sender types.JID, messageID types.MessageID, fromMe, star
238
268
senderJID = "0"
239
269
}
240
270
return PatchInfo {
241
- Type : WAPatchRegularHigh ,
271
+ Type : WAPatchRegularHigh ,
272
+ Operation : waServerSync .SyncdMutation_SET ,
242
273
Mutations : []MutationInfo {
243
274
newStarMutation (targetJID , senderJID , messageID , isFromMe , starred ),
244
275
},
@@ -281,11 +312,11 @@ func (proc *Processor) EncodePatch(keyID []byte, state HashState, patchInfo Patc
281
312
return nil , fmt .Errorf ("failed to encrypt mutation: %w" , err )
282
313
}
283
314
284
- valueMac := generateContentMAC (waServerSync . SyncdMutation_SET , encryptedContent , keyID , keys .ValueMAC )
315
+ valueMac := generateContentMAC (patchInfo . Operation , encryptedContent , keyID , keys .ValueMAC )
285
316
indexMac := concatAndHMAC (sha256 .New , keys .Index , indexBytes )
286
317
287
318
mutations = append (mutations , & waServerSync.SyncdMutation {
288
- Operation : waServerSync . SyncdMutation_SET .Enum (),
319
+ Operation : patchInfo . Operation .Enum (),
289
320
Record : & waServerSync.SyncdRecord {
290
321
Index : & waServerSync.SyncdIndex {Blob : indexMac },
291
322
Value : & waServerSync.SyncdValue {Blob : append (encryptedContent , valueMac ... )},
0 commit comments