From eb8f8e0d7204e757ad7c4e7a457de59bfc9851bd Mon Sep 17 00:00:00 2001 From: Alon Schwartzblat <63599777+Schwartzblat@users.noreply.github.com> Date: Fri, 25 Mar 2022 13:48:00 +0300 Subject: [PATCH 1/4] Add join group by groupInviteMessage (#1355) * Add join group by groupInviteMessage * Add join group by groupInviteMessage * Fix typo --- README.md | 7 +++++++ src/Socket/groups.ts | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index d241d44..83f3560 100644 --- a/README.md +++ b/README.md @@ -749,6 +749,13 @@ Of course, replace ``` xyz ``` with an actual ID. ``` Of course, replace ``` xxx ``` with invitation code. + +- To join the group using groupInviteMessage + ``` ts + const response = await sock.groupAcceptInviteV4(groupInviteMessage) + console.log("joined to: " + response) + ``` + Of course, replace ``` xxx ``` with invitation code. ## Broadcast Lists & Stories **Note:** messages cannot be sent to broadcast lists from the MD version right now diff --git a/src/Socket/groups.ts b/src/Socket/groups.ts index 7421a20..237a994 100644 --- a/src/Socket/groups.ts +++ b/src/Socket/groups.ts @@ -2,6 +2,7 @@ import { GroupMetadata, ParticipantAction, SocketConfig } from '../Types' import { generateMessageID } from '../Utils' import { BinaryNode, getBinaryNodeChild, getBinaryNodeChildren, jidEncode, jidNormalizedUser } from '../WABinary' import { makeSocket } from './socket' +import { proto } from '../../WAProto' export const makeGroupsSocket = (config: SocketConfig) => { const sock = makeSocket(config) @@ -134,6 +135,13 @@ export const makeGroupsSocket = (config: SocketConfig) => { const result = getBinaryNodeChild(results, 'group') return result.attrs.jid }, + groupAcceptInviteV4: async(jid: string, inviteMessage: proto.IGroupInviteMessage) => { + const results = await groupQuery(inviteMessage.groupJid, 'set', [{ tag: 'accept', attrs: { + code: inviteMessage.inviteCode, + expiration: inviteMessage.inviteExpiration.toString(), + admin: jid} }]) + return results.attrs.from; + }, groupToggleEphemeral: async(jid: string, ephemeralExpiration: number) => { const content: BinaryNode = ephemeralExpiration ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } : From 6275b85eaebb0d1ff6c4054bc5dd90774fac9d38 Mon Sep 17 00:00:00 2001 From: Catalin Bozan <43291246+catabozan@users.noreply.github.com> Date: Fri, 25 Mar 2022 12:53:38 +0200 Subject: [PATCH 2/4] Keep aspect ratio when generating thumbnails (#1409) * fix: generated thumbnail ratio * Delete myvid.mp4 * Delete thumb.jpeg --- src/Utils/messages-media.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Utils/messages-media.ts b/src/Utils/messages-media.ts index d9c8e27..e8599bc 100644 --- a/src/Utils/messages-media.ts +++ b/src/Utils/messages-media.ts @@ -81,7 +81,7 @@ const extractVideoThumb = async( time: string, size: { width: number; height: number }, ) => new Promise((resolve, reject) => { - const cmd = `ffmpeg -ss ${time} -i ${path} -y -s ${size.width}x${size.height} -vframes 1 -f image2 ${destPath}` + const cmd = `ffmpeg -ss ${time} -i ${path} -y -vf scale=${size.width}:-1 -vframes 1 -f image2 ${destPath}` exec(cmd, (err) => { if(err) { reject(err) @@ -99,17 +99,17 @@ export const extractImageThumb = async(bufferOrFilePath: Readable | Buffer | str const lib = await getImageProcessingLibrary() if('sharp' in lib) { const result = await lib.sharp!.default(bufferOrFilePath) - .resize(32, 32) + .resize(32) .jpeg({ quality: 50 }) .toBuffer() return result } else { - const { read, MIME_JPEG, RESIZE_BILINEAR } = lib.jimp + const { read, MIME_JPEG, RESIZE_BILINEAR, AUTO } = lib.jimp const jimp = await read(bufferOrFilePath as any) const result = await jimp .quality(50) - .resize(32, 32, RESIZE_BILINEAR) + .resize(32, AUTO, RESIZE_BILINEAR) .getBufferAsync(MIME_JPEG) return result } From 54a448b2a8377a18b4f68f51bf0131d767869a7b Mon Sep 17 00:00:00 2001 From: Cesar Cejudo Date: Sun, 27 Mar 2022 09:06:28 -0600 Subject: [PATCH 3/4] Fix in-memory-store contacts (#1420) fix issue where fromJSON loads contacts from the wrong variable --- src/Store/make-in-memory-store.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Store/make-in-memory-store.ts b/src/Store/make-in-memory-store.ts index 45c17a1..362a153 100644 --- a/src/Store/make-in-memory-store.ts +++ b/src/Store/make-in-memory-store.ts @@ -239,7 +239,7 @@ export default ( const fromJSON = (json: { chats: Chat[], contacts: { [id: string]: Contact }, messages: { [id: string]: WAMessage[] } }) => { chats.upsert(...json.chats) - contactsUpsert(Object.values(contacts)) + contactsUpsert(Object.values(json.contacts)) for(const jid in json.messages) { const list = assertMessageList(jid) for(const msg of json.messages[jid]) { From 3953e6df1f0f5846f6e49ccd0dd4234859dafe47 Mon Sep 17 00:00:00 2001 From: Jefersson Lemes Date: Sun, 27 Mar 2022 12:06:57 -0300 Subject: [PATCH 4/4] fix recording audio showing how typing (#1416) --- src/Socket/chats.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Socket/chats.ts b/src/Socket/chats.ts index 1b127f9..54a25a9 100644 --- a/src/Socket/chats.ts +++ b/src/Socket/chats.ts @@ -421,6 +421,10 @@ export const makeChatsSocket = (config: SocketConfig) => { type = 'available' } + if (firstChild.attrs?.media === 'audio'){ + type = 'recording'; + } + presence = { lastKnownPresence: type } } else { logger.error({ tag, attrs, content }, 'recv invalid presence node')