diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 81b572b5e88..e6f3b151b3b 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -2,7 +2,7 @@ import { Boom } from '@hapi/boom' import NodeCache from 'node-cache' import { proto } from '../../WAProto' import { DEFAULT_CACHE_TTLS, PROCESSABLE_HISTORY_TYPES } from '../Defaults' -import { ALL_WA_PATCH_NAMES, ChatModification, ChatMutation, LTHashState, MessageUpsertType, PresenceData, SocketConfig, WABusinessHoursConfig, WABusinessProfile, WAMediaUpload, WAMessage, WAPatchCreate, WAPatchName, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types' +import { ALL_WA_PATCH_NAMES, ChatModification, ChatMutation, ContactAction, LTHashState, MessageUpsertType, PresenceData, SocketConfig, WABusinessHoursConfig, WABusinessProfile, WAMediaUpload, WAMessage, WAPatchCreate, WAPatchName, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types' import { LabelActionBody } from '../Types/Label' import { chatModificationToAppPatch, ChatMutationMap, decodePatches, decodeSyncdSnapshot, encodeSyncdPatch, extractSyncdPatches, generateProfilePicture, getHistoryMsg, newLTHashState, processSyncAction } from '../Utils' import { makeMutex } from '../Utils/make-mutex' @@ -773,6 +773,24 @@ export const makeChatsSocket = (config: SocketConfig) => { }, jid) } + /** + * Add or Edit Contact + */ + const addOrEditContact = (jid: string, contact: ContactAction) => { + return chatModify({ + contact + }, jid) + } + + /** + * Remove Contact + */ + const removeContact = (jid: string) => { + return chatModify({ + contact: null + }, jid) + } + /** * Adds label */ @@ -1004,6 +1022,8 @@ export const makeChatsSocket = (config: SocketConfig) => { resyncAppState, chatModify, cleanDirtyBits, + addOrEditContact, + removeContact, addLabel, addChatLabel, removeChatLabel, diff --git a/src/Types/Chat.ts b/src/Types/Chat.ts index 58018891e34..38d51bd0577 100644 --- a/src/Types/Chat.ts +++ b/src/Types/Chat.ts @@ -1,5 +1,6 @@ import type { proto } from '../../WAProto' import type { AccountSettings } from './Auth' +import type { ContactAction } from './Contact' import type { BufferedEventData } from './Events' import type { LabelActionBody } from './Label' import type { ChatLabelAssociationActionBody } from './LabelAssociation' @@ -93,6 +94,7 @@ export type ChatModification = lastMessages: LastMessageList } | { delete: true, lastMessages: LastMessageList } + | { contact: ContactAction | null } // Label | { addLabel: LabelActionBody } // Label assosiation diff --git a/src/Types/Contact.ts b/src/Types/Contact.ts index 5c88587e508..5aa22599a40 100644 --- a/src/Types/Contact.ts +++ b/src/Types/Contact.ts @@ -17,4 +17,10 @@ export interface Contact { */ imgUrl?: string | null status?: string +} + +export type ContactAction = { + fistName: string + fullName: string + saveOnPrimaryAddressbook: boolean } \ No newline at end of file diff --git a/src/Utils/chat-utils.ts b/src/Utils/chat-utils.ts index 9b56f868568..f0c58e02d32 100644 --- a/src/Utils/chat-utils.ts +++ b/src/Utils/chat-utils.ts @@ -588,6 +588,16 @@ export const chatModificationToAppPatch = ( apiVersion: 5, operation: OP.SET } + } else if('contact' in mod) { + patch = { + syncAction: { + contactAction: mod.contact || {} + }, + index: ['contact', jid], + type: 'critical_unblock_low', + apiVersion: 2, + operation: mod.contact ? OP.SET : OP.REMOVE + } } else if('star' in mod) { const key = mod.star.messages[0] patch = {