Skip to content

Commit

Permalink
Fix Maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
DikaArdnt committed Jan 4, 2024
1 parent 6b766d9 commit 548c1f3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 39 deletions.
8 changes: 8 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ client.on('message_create', (msg) => {
}
});

client.on('message_ciphertext', (msg) => {
// Receiving new incoming messages that have been encrypted
// msg.type === 'ciphertext'
msg.body = 'Waiting for this message. Check your phone.';

// do stuff here
});

client.on('message_revoke_everyone', async (after, before) => {
// Fired whenever a message is deleted by anyone (including you)
console.log(after); // message after it was deleted.
Expand Down
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ declare namespace WAJS {
message: Message
) => void): this

/** Emitted when a new message ciphertext is received */
on(event: 'message_ciphertext', listener: (
/** The message that was ciphertext */
message: Message
) => void): this

/** Emitted when a message is deleted for everyone in the chat */
on(event: 'message_revoke_everyone', listener: (
/** The message that was revoked, in its current state. It will not contain the original message's data */
Expand Down
27 changes: 12 additions & 15 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const { GroupNotification, Message, ClientInfo, Call, MessageMedia, Location, Po
* @fires Client#message_create
* @fires Client#message_revoke_me
* @fires Client#message_revoke_everyone
* @fires Client#message_ciphertext
* @fires Client#media_uploaded
* @fires Client#group_join
* @fires Client#group_leave
Expand Down Expand Up @@ -408,6 +409,7 @@ class Client extends EventEmitter {
if (msg.type === 'ciphertext') {
// defer message event until ciphertext is resolved (type changed)
msg.once('change:type', (_msg) => window.onAddMessageEvent(window.WAJS.getMessageModel(_msg)));
window.EmitEvent(Events.MESSAGE_CIPHERTEXT, window.WWebJS.getMessageModel(msg));
} else {
window.onAddMessageEvent(window.WAJS.getMessageModel(msg));
}
Expand All @@ -430,8 +432,8 @@ class Client extends EventEmitter {
* @type {ClientInfo}
*/
this.info = new ClientInfo(this, await page.evaluate(() => {
const pushname = window.WPP.whatsapp.Conn.pushname
const platform = window.WPP.whatsapp.Conn.platform
const pushname = window.WPP.whatsapp.Conn.pushname;
const platform = window.WPP.whatsapp.Conn.platform;
return { pushname, platform, wid: window.WPP.whatsapp.UserPrefs.getMeUser() };
}));

Expand Down Expand Up @@ -1001,19 +1003,14 @@ class Client extends EventEmitter {
const statusCode = participant.error ?? 200;

if (autoSendInviteV4 && statusCode === 403) {
window.WPP.whatsapp.ContactStore.gadd(participant.wid, { silent: true });
const addParticipantResult = await window.Store.GroupInviteV4.sendGroupInviteMessage(
await window.WPP.whatsapp.ChatStore.find(participant.wid),
createGroupResult.wid._serialized,
createGroupResult.subject,
participant.invite_code,
participant.invite_code_exp,
comment,
await window.WAJS.getProfilePicThumbToBase64(createGroupResult.wid._serialized)
);
isInviteV4Sent = window.WAJS.compareWwebVersions(window.Debug.VERSION, '<', '2.2335.6')
? addParticipantResult === 'OK'
: addParticipantResult.messageSendResult === 'OK';
await Util.sleep(2500);
await window.WPP.chat.sendGroupInviteMessage(participantId, {
inviteCode: participant.invite_code,
inviteCodeExpiration: participant.invite_code_exp,
groupId: createGroupResult.wid._serialized,
caption: comment
});
isInviteV4Sent = true;
}

participantData[participantId] = {
Expand Down
28 changes: 10 additions & 18 deletions src/Structures/GroupChat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const Chat = require('./Chat');
const Util = require('../Util/Util');

/**
* Group participant information
Expand Down Expand Up @@ -79,28 +80,19 @@ class GroupChat extends Chat {
return await this.client.playPage.evaluate(async ({ groupId, participantIds, options }) => {
const { autoSendInviteV4 = true, comment = '' } = options;

const group = await window.WPP.chat.get(groupId);
const results = await window.WPP.group.addParticipants(groupId, participantIds);

for (let participant of participantIds) {
await Util.sleep(2500);
const results = await window.WPP.group.addParticipants(groupId, participant);
const result = results[participant];
const userChat = window.WPP.chat.get(participant);

if (autoSendInviteV4 && result.code === 403) {
const groupName = group.formattedTitle || group.name || group.subject;
await window.Store.GroupInviteV4.sendGroupInviteMessage(
userChat,
groupId,
groupName,
result.invite_code,
result.invite_code_exp,
comment,
await window.WAJS.getProfilePicThumbToBase64(groupId)
);
if (autoSendInviteV4 && result.invite_code) {
await window.WPP.chat.sendGroupInviteMessage(participant, {
inviteCode: result.invite_code,
inviteCodeExpiration: result.invite_code_exp,
groupId: groupId,
caption: comment
});
}
}

return results;
}, { groupId: this.id._serialized, participantIds, options });
}

Expand Down
1 change: 1 addition & 0 deletions src/Util/Constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports.Events = {
CHAT_REMOVED: 'chat_removed',
CHAT_ARCHIVED: 'chat_archived',
MESSAGE_RECEIVED: 'message',
MESSAGE_CIPHERTEXT: 'message_ciphertext',
MESSAGE_CREATE: 'message_create',
MESSAGE_REVOKED_EVERYONE: 'message_revoke_everyone',
MESSAGE_REVOKED_ME: 'message_revoke_me',
Expand Down
9 changes: 3 additions & 6 deletions src/Util/Injected.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exports.StoreObject = () => {
},
{
id: 'getMsgInfo',
conditions: (module) => module.queryMsgInfo && module
conditions: (module) => (module.sendQueryMsgInfo || module.queryMsgInfo) && module
},
{
id: 'QueryOrder',
Expand Down Expand Up @@ -122,10 +122,7 @@ exports.LoadUtils = () => {
forceGif: options.sendVideoAsGif
});

if (options.caption) {
attOptions.caption = options.caption;
delete options.caption;
}
attOptions.caption = options.caption;
content = options.sendMediaAsSticker ? undefined : attOptions.preview;
attOptions.isViewOnce = options.isViewOnce;

Expand All @@ -146,7 +143,7 @@ exports.LoadUtils = () => {
}

if (options.mentionedJidList) {
options.mentionedJidList = options.mentionedJidList.map(cId => window.WPP.whatsapp.ContactStore.get(cId).id);
options.mentionedJidList = options.mentionedJidList.map(cId => window.WPP.whatsapp.WidFactory.createWid(cId));
}

let locationOptions = {};
Expand Down

0 comments on commit 548c1f3

Please sign in to comment.