From 70f03213810fb821c05ea5f024f6f270babe4df5 Mon Sep 17 00:00:00 2001 From: Rajeh Taher Date: Sun, 22 Sep 2024 14:32:05 +0300 Subject: [PATCH] fix(master): New profile update/removal endpoint (inspired by #1048) --- src/Socket/chats.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 7385d09..495b86f 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -220,11 +220,21 @@ export const makeChatsSocket = (config: SocketConfig) => { /** update the profile picture for yourself or a group */ const updateProfilePicture = async(jid: string, content: WAMediaUpload) => { + let targetJid = '' + if(!jid) { + throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update') + } + + if(jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me!.id)) { + targetJid = jid // in case it is someone other than us + } + const { img } = await generateProfilePicture(content) await query({ tag: 'iq', attrs: { - to: jidNormalizedUser(jid), + target: targetJid, + to: S_WHATSAPP_NET, type: 'set', xmlns: 'w:profile:picture' }, @@ -240,10 +250,20 @@ export const makeChatsSocket = (config: SocketConfig) => { /** remove the profile picture for yourself or a group */ const removeProfilePicture = async(jid: string) => { + let targetJid = '' + if(!jid) { + throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update') + } + + if(jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me!.id)) { + targetJid = jid // in case it is someone other than us + } + await query({ tag: 'iq', attrs: { - to: jidNormalizedUser(jid), + target: targetJid, + to: S_WHATSAPP_NET, type: 'set', xmlns: 'w:profile:picture' }