Skip to content

Commit

Permalink
feat: Improovment on edit message captions (#1946)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelo386 authored May 22, 2024
1 parent f9e60e6 commit b609a9f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/chat/functions/editMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { WPPError } from '../../util';
import { MsgKey } from '../../whatsapp';
import { canEditMsg } from '../../whatsapp/functions';
import { canEditCaption, canEditMsg } from '../../whatsapp/functions';
import {
defaultSendMessageOptions,
LinkPreviewOptions,
Expand Down Expand Up @@ -52,7 +52,8 @@ export async function editMessage(
const msg = await getMessageById(msgId);

const canEdit = canEditMsg(msg);
if (!canEdit) {
const canEditCaptionMessage = canEditCaption(msg);
if (!canEdit && !canEditCaptionMessage) {
throw new WPPError(`edit_message_error`, `Cannot edit this message`);
}

Expand All @@ -61,6 +62,7 @@ export async function editMessage(
subtype: 'message_edit',
protocolMessageKey: msg.id,
body: newText.trim(),
caption: newText.trim(),
editMsgType: msg.type,
};

Expand Down
31 changes: 31 additions & 0 deletions src/whatsapp/functions/canEditCaption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*!
* Copyright 2024 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 { exportModule } from '../exportModule';
import { MsgModel } from '../models';

/**
* @whatsapp WAWebMsgActionCapability >= 2.3000.0
*/
export declare function canEditCaption(msg: MsgModel): boolean;

exportModule(
exports,
{
canEditCaption: 'canEditCaption',
},
(m) => m.canEditCaption
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export * from './addAndSendMsgToChat';
export * from './addToLabelCollection';
export * from './blockContact';
export * from './calculateFilehashFromBlob';
export * from './canEditCaption';
export * from './canEditMsg';
export * from './canReplyMsg';
export * from './changeOptInStatusForExternalWebBeta';
Expand Down

0 comments on commit b609a9f

Please sign in to comment.