This commit is contained in:
tzagim 2024-05-21 20:20:55 +03:00 committed by GitHub
parent 0cf7c09ed5
commit af075e15fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 105 additions and 12 deletions

View File

@ -123,6 +123,96 @@ func BuildArchive(target types.JID, archive bool, lastMessageTimestamp time.Time
return result
}
func newLabelChatMutation(target types.JID, labelID string, labeled bool) MutationInfo {
return MutationInfo{
Index: []string{IndexLabelAssociationChat, labelID, target.String()},
Version: 3,
Value: &waProto.SyncActionValue{
LabelAssociationAction: &waProto.LabelAssociationAction{
Labeled: &labeled,
},
},
}
}
// BuildLabelChat builds an app state patch for labeling or un(labeling) a chat.
func BuildLabelChat(target types.JID, labelID string, labeled bool) PatchInfo {
return PatchInfo{
Type: WAPatchRegular,
Mutations: []MutationInfo{
newLabelChatMutation(target, labelID, labeled),
},
}
}
func newLabelMessageMutation(target types.JID, labelID, messageID string, labeled bool) MutationInfo {
return MutationInfo{
Index: []string{IndexLabelAssociationMessage, labelID, target.String(), messageID, "0", "0"},
Version: 3,
Value: &waProto.SyncActionValue{
LabelAssociationAction: &waProto.LabelAssociationAction{
Labeled: &labeled,
},
},
}
}
// BuildLabelMessage builds an app state patch for labeling or un(labeling) a message.
func BuildLabelMessage(target types.JID, labelID, messageID string, labeled bool) PatchInfo {
return PatchInfo{
Type: WAPatchRegular,
Mutations: []MutationInfo{
newLabelMessageMutation(target, labelID, messageID, labeled),
},
}
}
func newLabelEditMutation(labelID string, labelName string, labelColor int32, deleted bool) MutationInfo {
return MutationInfo{
Index: []string{IndexLabelEdit, labelID},
Version: 3,
Value: &waProto.SyncActionValue{
LabelEditAction: &waProto.LabelEditAction{
Name: &labelName,
Color: &labelColor,
Deleted: &deleted,
},
},
}
}
// BuildLabelEdit builds an app state patch for editing a label.
func BuildLabelEdit(labelID string, labelName string, labelColor int32, deleted bool) PatchInfo {
return PatchInfo{
Type: WAPatchRegular,
Mutations: []MutationInfo{
newLabelEditMutation(labelID, labelName, labelColor, deleted),
},
}
}
func newSettingPushNameMutation(pushName string) MutationInfo {
return MutationInfo{
Index: []string{IndexSettingPushName},
Version: 1,
Value: &waProto.SyncActionValue{
PushNameSetting: &waProto.PushNameSetting{
Name: &pushName,
},
},
}
}
// BuildSettingPushName builds an app state patch for setting the push name.
func BuildSettingPushName(pushName string) PatchInfo {
return PatchInfo{
Type: WAPatchCriticalBlock,
Mutations: []MutationInfo{
newSettingPushNameMutation(pushName),
},
}
}
func (proc *Processor) EncodePatch(keyID []byte, state HashState, patchInfo PatchInfo) ([]byte, error) {
keys, err := proc.getAppStateKey(keyID)
if err != nil {

View File

@ -37,18 +37,21 @@ var AllPatchNames = [...]WAPatchName{WAPatchCriticalBlock, WAPatchCriticalUnbloc
// Constants for the first part of app state indexes.
const (
IndexMute = "mute"
IndexPin = "pin_v1"
IndexArchive = "archive"
IndexContact = "contact"
IndexClearChat = "clearChat"
IndexDeleteChat = "deleteChat"
IndexStar = "star"
IndexDeleteMessageForMe = "deleteMessageForMe"
IndexMarkChatAsRead = "markChatAsRead"
IndexSettingPushName = "setting_pushName"
IndexSettingUnarchiveChats = "setting_unarchiveChats"
IndexUserStatusMute = "userStatusMute"
IndexMute = "mute"
IndexPin = "pin_v1"
IndexArchive = "archive"
IndexContact = "contact"
IndexClearChat = "clearChat"
IndexDeleteChat = "deleteChat"
IndexStar = "star"
IndexDeleteMessageForMe = "deleteMessageForMe"
IndexMarkChatAsRead = "markChatAsRead"
IndexSettingPushName = "setting_pushName"
IndexSettingUnarchiveChats = "setting_unarchiveChats"
IndexUserStatusMute = "userStatusMute"
IndexLabelEdit = "label_edit"
IndexLabelAssociationChat = "label_jid"
IndexLabelAssociationMessage = "label_message"
)
type Processor struct {