Skip to content

Commit

Permalink
fix: Fixed ephemeral setting for sending messages (fix #1014);
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed May 1, 2023
1 parent 68eeffe commit a7d840d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
15 changes: 14 additions & 1 deletion src/chat/functions/prepareRawMessage.ts
Expand Up @@ -19,7 +19,11 @@ import { getParticipants } from '../../group';
import { WPPError } from '../../util';
import { ChatModel, MsgKey, MsgModel, UserPrefs, Wid } from '../../whatsapp';
import { ACK } from '../../whatsapp/enums';
import { canReplyMsg, unixTime } from '../../whatsapp/functions';
import {
canReplyMsg,
getEphemeralFields,
unixTime,
} from '../../whatsapp/functions';
import { defaultSendMessageOptions, RawMessage, SendMessageOptions } from '..';
import { generateMessageID, getMessageById } from '.';

Expand Down Expand Up @@ -49,6 +53,15 @@ export async function prepareRawMessage<T extends RawMessage>(
...message,
};

if (message.type !== 'protocol') {
const ephemeral = getEphemeralFields(chat);

message = {
...ephemeral,
...message,
};
}

if (options.messageId) {
if (typeof options.messageId === 'string') {
options.messageId = MsgKey.fromString(options.messageId);
Expand Down
35 changes: 35 additions & 0 deletions src/whatsapp/functions/getEphemeralFields.ts
@@ -0,0 +1,35 @@
/*!
* 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 { exportModule } from '../exportModule';
import { ChatModel } from '../models';

/**
* @whatsapp 700154 >= 2.2318.11
*/
export declare function getEphemeralFields(chat: ChatModel): {
ephemeralDuration?: number;
ephemeralSettingTimestamp?: number;
disappearingModeInitiator?: number;
};

exportModule(
exports,
{
getEphemeralFields: 'getEphemeralFields',
},
(m) => m.getEphemeralFields
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -37,6 +37,7 @@ export * from './generateVideoThumbsAndDuration';
export * from './genMinimalLinkPreview';
export * from './getABPropConfigValue';
export * from './getCommunityParticipants';
export * from './getEphemeralFields';
export * from './getFanOutList';
export * from './getGroupSenderKeyList';
export * from './getGroupSizeLimit';
Expand Down
4 changes: 2 additions & 2 deletions src/whatsapp/models/MsgModel.ts
Expand Up @@ -176,8 +176,8 @@ interface Props {
paymentRequestMessageKey?: any;
paymentExpiryTimestamp?: any;
ephemeralStartTimestamp?: any;
ephemeralDuration?: any;
ephemeralSettingTimestamp?: any;
ephemeralDuration?: number;
ephemeralSettingTimestamp?: number;
ephemeralOutOfSync?: any;
ephemeralSharedSecret?: any;
disappearingModeInitiator?: any;
Expand Down

0 comments on commit a7d840d

Please sign in to comment.