From 0931800cdad655c5248369185a91586e721ee0ed Mon Sep 17 00:00:00 2001 From: Edgard Date: Sun, 30 Oct 2022 14:10:07 -0300 Subject: [PATCH] fix: Fixed send message with quotedMsg (fix #721) --- src/chat/functions/prepareRawMessage.ts | 4 +-- src/whatsapp/functions/canReplyMsg.ts | 38 +++++++++++++++++++++++++ src/whatsapp/functions/index.ts | 1 + src/whatsapp/models/MsgModel.ts | 2 +- 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/whatsapp/functions/canReplyMsg.ts diff --git a/src/chat/functions/prepareRawMessage.ts b/src/chat/functions/prepareRawMessage.ts index e2455318e0..7b98574e04 100644 --- a/src/chat/functions/prepareRawMessage.ts +++ b/src/chat/functions/prepareRawMessage.ts @@ -19,7 +19,7 @@ import { getParticipants } from '../../group'; import { WPPError } from '../../util'; import { ChatModel, MsgKey, MsgModel, UserPrefs, Wid } from '../../whatsapp'; import { ACK } from '../../whatsapp/enums'; -import { unixTime } from '../../whatsapp/functions'; +import { canReplyMsg, unixTime } from '../../whatsapp/functions'; import { defaultSendMessageOptions, RawMessage, SendMessageOptions } from '..'; import { generateMessageID, getMessageById } from '.'; @@ -160,7 +160,7 @@ export async function prepareRawMessage( }); } - if (!options.quotedMsg?.isStatusV3 && !options.quotedMsg.canReply()) { + if (!options.quotedMsg?.isStatusV3 && !canReplyMsg(options.quotedMsg)) { throw new WPPError( 'quoted_msg_can_not_reply', 'QuotedMsg can not reply', diff --git a/src/whatsapp/functions/canReplyMsg.ts b/src/whatsapp/functions/canReplyMsg.ts new file mode 100644 index 0000000000..98d4f4276a --- /dev/null +++ b/src/whatsapp/functions/canReplyMsg.ts @@ -0,0 +1,38 @@ +/*! + * Copyright 2021 WPPConnect Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as webpack from '../../webpack'; +import { exportModule } from '../exportModule'; +import { MsgModel } from '../models'; + +/** + * @whatsapp 973480 >= 2.2241.6 + */ +export declare function canReplyMsg(msg: MsgModel): boolean; + +exportModule( + exports, + { + canReplyMsg: 'canReplyMsg', + }, + (m) => m.canReplyMsg +); + +webpack.injectFallbackModule('canReplyMsg', { + canReplyMsg: (msg: MsgModel) => { + return msg.canReply?.() || false; + }, +}); diff --git a/src/whatsapp/functions/index.ts b/src/whatsapp/functions/index.ts index 00ebc7f500..debed3f89e 100644 --- a/src/whatsapp/functions/index.ts +++ b/src/whatsapp/functions/index.ts @@ -17,6 +17,7 @@ export * from './addAndSendMsgToChat'; export * from './blockContact'; export * from './calculateFilehashFromBlob'; +export * from './canReplyMsg'; export * from './collections'; export * from './createMsgProtobuf'; export * from './createOrUpdateReactions'; diff --git a/src/whatsapp/models/MsgModel.ts b/src/whatsapp/models/MsgModel.ts index ee7609e4d0..45d6f6a944 100644 --- a/src/whatsapp/models/MsgModel.ts +++ b/src/whatsapp/models/MsgModel.ts @@ -335,7 +335,7 @@ export declare class MsgModel extends Model { hasSymbol(): boolean; mayFail(): any; isUnsentPhoneMsg(): boolean; - canReply(): boolean; + canReply?(): boolean; canPrivateReply(): boolean; canPrivateReplyInRestrictedGrp(): boolean; canForward(): boolean;