Skip to content

Commit

Permalink
fix: Fixed send status (text/image/video) (fix #1270,fix #1284, fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Oct 8, 2023
1 parent 54b7770 commit e7e028e
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 17 deletions.
32 changes: 16 additions & 16 deletions src/status/functions/sendRawStatus.ts
Expand Up @@ -21,8 +21,8 @@ import { functions, MsgKey, UserPrefs } from '../../whatsapp';
import { wrapModuleFunction } from '../../whatsapp/exportModule';
import {
createMsgProtobuf,
encryptAndSendGroupMsg,
encryptAndSendMsg,
encryptAndSendSenderKeyMsg,
randomHex,
} from '../../whatsapp/functions';
import { defaultSendStatusOptions, updateParticipants } from '..';
Expand Down Expand Up @@ -90,13 +90,15 @@ webpack.onInjected(() => {

// Force to send as group for broadcast list
wrapModuleFunction(encryptAndSendMsg, async (func, ...args) => {
const [msg] = args;
const [, data] = args;

try {
return await func(...args);
} catch (error: any) {
const to = data.to;

if (
!msg.to?.isStatusV3() ||
!to?.isStatusV3() ||
error.message !== '[messaging] unsupported remote jid type'
) {
throw error;
Expand All @@ -106,30 +108,28 @@ webpack.onInjected(() => {
await updateParticipants();
}

const participants = await functions.getParticipants(msg.to);
const participants = await functions.getParticipants(to);

if (!participants || participants.participants.length === 0) {
throw new Error('empty participants for status@broadcast');
}

await functions.markForgetSenderKey(
msg.to,
to,
participants.participants.map(assertWid)
);

let c;
if (functions.getAsMms(msg)) {
const t = msg.isUnsentPhoneMsg();
c = t ? { type: msg.type } : msg.avParams();
}

if (!msg.author) {
msg.author = UserPrefs.getMaybeMeUser();
}
args[1].to.server = 'g.us';

const proto = createMsgProtobuf(msg, c || {});
return await func(...args);
}
});

return await encryptAndSendGroupMsg(msg, proto);
wrapModuleFunction(encryptAndSendSenderKeyMsg, async (func, ...args) => {
if (args[1].to.user === 'status') {
args[1].to.server = 'broadcast';
}

return await func(...args);
});
});
18 changes: 17 additions & 1 deletion src/whatsapp/functions/encryptAndSendMsg.ts
Expand Up @@ -15,14 +15,30 @@
*/

import { exportModule } from '../exportModule';
import { MsgKey, Wid } from '../misc';
import { MsgModel } from '../models';

/**
* @whatsapp 95547
* @whatsapp 695547 >= 2.2222.8
* @whatsapp 925080 >= 2.2228.4
*/
export declare function encryptAndSendMsg(message: MsgModel): Promise<any>;
export declare function encryptAndSendMsg(
msg: {
type: string;
data: MsgModel;
},
data: {
ack: number;
author?: Wid;
from: Wid;
id: MsgKey;
subtype?: string;
to: Wid;
type: string;
},
report: any
): Promise<any>;

exportModule(
exports,
Expand Down
53 changes: 53 additions & 0 deletions src/whatsapp/functions/encryptAndSendSenderKeyMsg.ts
@@ -0,0 +1,53 @@
/*!
* 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 { MsgKey, Wid } from '../misc';
import { MsgModel } from '../models';

/**
* @whatsapp 95547
* @whatsapp 695547 >= 2.2222.8
* @whatsapp 925080 >= 2.2228.4
*/
export declare function encryptAndSendSenderKeyMsg(
msg: {
type: string;
data: MsgModel;
},
data: {
ack: number;
author?: Wid;
from: Wid;
id: MsgKey;
subtype?: string;
to: Wid;
type: string;
},
proto: any,
skGroup: any,
options: any,
report: any,
other: any
): Promise<any>;

exportModule(
exports,
{
encryptAndSendSenderKeyMsg: 'encryptAndSendSenderKeyMsg',
},
(m) => m.encryptAndSendSenderKeyMsg
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Expand Up @@ -33,6 +33,7 @@ export * from './editBusinessProfile';
export * from './encodeMaybeMediaType';
export * from './encryptAndSendGroupMsg';
export * from './encryptAndSendMsg';
export * from './encryptAndSendSenderKeyMsg';
export * from './encryptMsgProtobuf';
export * from './fetchLinkPreview';
export * from './findChat';
Expand Down

0 comments on commit e7e028e

Please sign in to comment.