Skip to content

Commit

Permalink
fix: Fixed edit message function (close #1321) (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Sep 1, 2023
1 parent 8165a2a commit 209c994
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/chat/functions/editMessage.ts
Expand Up @@ -61,6 +61,7 @@ export async function editMessage(
subtype: 'message_edit',
protocolMessageKey: msg.id,
body: newText.trim(),
editMsgType: msg.type,
};

rawMessage = await prepareRawMessage(msg.chat!, rawMessage, options);
Expand Down
16 changes: 13 additions & 3 deletions src/chat/functions/sendRawMessage.ts
Expand Up @@ -17,14 +17,17 @@
import Debug from 'debug';

import { assertFindChat, assertGetChat } from '../../assert';
import { addAndSendMsgToChat } from '../../whatsapp/functions';
import {
addAndSendMessageEdit,
addAndSendMsgToChat,
} from '../../whatsapp/functions';
import {
defaultSendMessageOptions,
RawMessage,
SendMessageOptions,
SendMessageReturn,
} from '..';
import { markIsRead, prepareRawMessage } from '.';
import { getMessageById, markIsRead, prepareRawMessage } from '.';

const debug = Debug('WA-JS:message');

Expand Down Expand Up @@ -56,7 +59,14 @@ export async function sendRawMessage(
}

debug(`sending message (${rawMessage.type}) with id ${rawMessage.id}`);
const result = await addAndSendMsgToChat(chat, rawMessage);
let result = null as any;
if (rawMessage.type === 'protocol' && rawMessage.subtype === 'message_edit') {
const msg = await getMessageById(rawMessage.protocolMessageKey);
await addAndSendMessageEdit(msg, rawMessage);
result = [await getMessageById(rawMessage.protocolMessageKey), null];
} else {
result = await addAndSendMsgToChat(chat, rawMessage);
}
debug(`message ${rawMessage.id} queued`);

const message = await result[0];
Expand Down
34 changes: 34 additions & 0 deletions src/whatsapp/functions/addAndSendMessageEdit.ts
@@ -0,0 +1,34 @@
/*!
* Copyright 2023 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 { SendMsgResult } from '../enums';
import { exportModule } from '../exportModule';
import { ModelPropertiesContructor, MsgModel } from '../models';

/** @whatsapp 375399
*/
export declare function addAndSendMessageEdit(
editMsg: MsgModel,
message: ModelPropertiesContructor<MsgModel>
): Promise<[Promise<MsgModel>, Promise<SendMsgResult>]>;

exportModule(
exports,
{
addAndSendMessageEdit: 'addAndSendMessageEdit',
},
(m) => m.addAndSendMessageEdit
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

export * from './addAndSendMessageEdit';
export * from './addAndSendMsgToChat';
export * from './addToLabelCollection';
export * from './blockContact';
Expand Down

0 comments on commit 209c994

Please sign in to comment.