From eb218da8fbedd689454294945a1acd26fb6bff27 Mon Sep 17 00:00:00 2001 From: devlikepro Date: Wed, 6 Nov 2024 14:49:46 +0700 Subject: [PATCH] [core] linkPreview: false|true fix #596 #598 --- src/core/engines/noweb/session.noweb.core.ts | 17 +++++++++++++++++ src/core/engines/webjs/session.webjs.core.ts | 1 + src/structures/chatting.dto.ts | 2 ++ 3 files changed, 20 insertions(+) diff --git a/src/core/engines/noweb/session.noweb.core.ts b/src/core/engines/noweb/session.noweb.core.ts index 30450ba7..b94c1410 100644 --- a/src/core/engines/noweb/session.noweb.core.ts +++ b/src/core/engines/noweb/session.noweb.core.ts @@ -621,6 +621,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { const message = { text: request.text, mentions: request.mentions?.map(toJID), + linkPreview: this.getLinkPreview(request), }; const options = await this.getMessageOptions(request); return this.sock.sendMessage(chatId, message, options); @@ -1686,6 +1687,22 @@ export class WhatsappSessionNoWebCore extends WhatsappSession { quoted: quoted, }; } + + protected getLinkPreview(request): any { + // NOWEB works this way + // If it's undefined - it'll generate it + // If it's false - it will not generate it + let linkPreview: boolean | undefined; + switch (request.linkPreview) { + case false: + linkPreview = false; + break; + case true: + default: + linkPreview = undefined; + } + return linkPreview; + } } function hasPath(url: string) { diff --git a/src/core/engines/webjs/session.webjs.core.ts b/src/core/engines/webjs/session.webjs.core.ts index 0cc28638..15bb472c 100644 --- a/src/core/engines/webjs/session.webjs.core.ts +++ b/src/core/engines/webjs/session.webjs.core.ts @@ -1169,6 +1169,7 @@ export class WhatsappSessionWebJSCore extends WhatsappSession { return { mentions: mentions, quotedMessageId: quotedMessageId, + linkPreview: request.linkPreview, }; } } diff --git a/src/structures/chatting.dto.ts b/src/structures/chatting.dto.ts index e689025b..5fbc3e12 100644 --- a/src/structures/chatting.dto.ts +++ b/src/structures/chatting.dto.ts @@ -156,6 +156,8 @@ export class MessageTextRequest extends ChatRequest { @ReplyToProperty() reply_to?: string; + + linkPreview?: boolean = true; } export class EditMessageRequest {