Skip to content

Commit

Permalink
fix: Fixed compatibility with WhatsApp WEB >= 2.2220.8
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jun 8, 2022
1 parent d9fb419 commit 1a96ab1
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/lib/wapi/business/send-message-with-buttons.js
Expand Up @@ -18,7 +18,7 @@
window.WAPI.sendButtons = async function (chatId) {
var chat = WPP.whatsapp.ChatStore.get(chatId);
var tempMsg = Object.create(chat.msgs.filter((msg) => msg.__x_isSentByMe)[0]);
// var tempMsg = Object.create(WPP.whatsapp.MsgStore.models.filter(msg => msg.to._serialized===chatId&&msg.__x_isSentByMe&& msg.type=='chat' && !msg.quotedStanzaID)[0])
// var tempMsg = Object.create(WPP.whatsapp.MsgStore.getModelsArray().filter(msg => msg.to._serialized===chatId&&msg.__x_isSentByMe&& msg.type=='chat' && !msg.quotedStanzaID)[0])
var t2 = Object.create(
WPP.whatsapp.MsgStore.filter(
(x) => (x.type == 'template') & !x.id.fromMe
Expand Down Expand Up @@ -195,7 +195,7 @@ window.WAPI.sendButtons = async function (chatId) {
window.WAPI.sendButtons2 = async function (chatId) {
var chat = WPP.whatsapp.ChatStore.get(chatId);
var tempMsg = Object.create(
WPP.whatsapp.MsgStore.models.filter(
WPP.whatsapp.MsgStore.getModelsArray().filter(
(msg) =>
msg.to._serialized === chatId &&
msg.__x_isSentByMe &&
Expand All @@ -204,7 +204,7 @@ window.WAPI.sendButtons2 = async function (chatId) {
)[0]
);
var t2 = Object.create(
WPP.whatsapp.MsgStore.models.filter(
WPP.whatsapp.MsgStore.getModelsArray().filter(
(msg) =>
msg.to._serialized === chatId &&
msg.__x_isSentByMe &&
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/forward-messages.js
Expand Up @@ -58,7 +58,7 @@ export async function forwardMessages(chatId, messagesId, skipMyMessages) {
await chat.forwardMessages(toForward);
await new Promise((resolve) => setTimeout(resolve, 100)); // Wait collection update

const msgs = chat.msgs.models.slice(messagesId.length * -1);
const msgs = chat.msgs.getModelsArray().slice(messagesId.length * -1);

return msgs.map((m) => m.id._serialized);
}
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/get-all-messages-in-chat.js
Expand Up @@ -24,7 +24,7 @@ export async function getAllMessagesInChat(
var chat = await WAPI.sendExist(id);
let output = [];
if (!chat.erro) {
const messages = chat.msgs.models;
const messages = chat.msgs.getModelsArray();
for (const i in messages) {
if (i === 'remove') {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/get-unread-messages.js
Expand Up @@ -21,7 +21,7 @@ export function getUnreadMessages(
useUnreadCount,
done
) {
const chats = WPP.whatsapp.ChatStore.models;
const chats = WPP.whatsapp.ChatStore.getModelsArray();
const output = [];

for (const chat in chats) {
Expand Down
Expand Up @@ -33,7 +33,7 @@ export async function loadAndGetAllMessagesInChat(
}

let output = [];
const messages = chat.msgs.models;
const messages = chat.msgs.getModelsArray();

for (const i in messages) {
if (i === 'remove') {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/load-earlier-messages-til-date.js
Expand Up @@ -19,7 +19,7 @@ export function loadEarlierMessagesTillDate(id, lastMessage, done) {
const found = WAPI.getChat(id);
const x = function () {
if (
found.msgs.models[0].t > lastMessage &&
found.msgs.getModelsArray()[0].t > lastMessage &&
!found.msgs.msgLoadState.noEarlierMsgs
) {
found.loadEarlierMsgs().then(x);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/reject-call.js
Expand Up @@ -56,7 +56,7 @@ export async function rejectCall(callId) {
return 1;
}

const calls = WPP.whatsapp.CallStore.models.filter(
const calls = WPP.whatsapp.CallStore.getModelsArray().filter(
(c) => c.getState() === 'INCOMING_RING'
);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-file.js
Expand Up @@ -55,7 +55,7 @@ export async function sendFile(

var mediaBlob = base64ToFile(imgBase64, filename);
var mediaCollection = await processFiles(chat, mediaBlob);
var media = mediaCollection.models[0];
var media = mediaCollection.getModelsArray()[0];
var result =
(await media.sendToChat(chat, { caption, quotedMsg, isViewOnce })) || '';
var m = { type: type, filename: filename, text: caption, mimeType: mime };
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-image-with-product.js
Expand Up @@ -62,7 +62,7 @@ export function sendImageWithProduct(
// var mc = new Store.MediaCollection(chat);
// mc.processFiles([mediaBlob], chat, 1)
processFiles(chat, mediaBlob).then((mc) => {
var media = mc.models[0];
var media = mc.getModelsArray()[0];
Object.entries(temp.productMsgOptions).map(
([k, v]) => (media.mediaPrep._mediaData[k] = v)
);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-ptt.js
Expand Up @@ -51,7 +51,7 @@ export async function sendPtt(

var mediaBlob = base64ToFile(imgBase64, filename);
var mediaCollection = await processFiles(chat, mediaBlob);
var media = mediaCollection.models[0];
var media = mediaCollection.getModelsArray()[0];
media.mediaPrep._mediaData.type = 'ptt';

var result = (await media.sendToChat(chat, { caption, quotedMsg })) || '';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-video-as-gif.js
Expand Up @@ -37,7 +37,7 @@ export async function sendVideoAsGif(
if (!chat.erro) {
var mediaBlob = base64ToFile(dataBase64, filename);
var mediaCollection = await processFiles(chat, mediaBlob);
var media = mediaCollection.models[0];
var media = mediaCollection.getModelsArray()[0];
media.mediaPrep._mediaData.isGif = true;
media.mediaPrep._mediaData.gifAttribution = 1;

Expand Down
5 changes: 3 additions & 2 deletions src/lib/wapi/listeners/add-on-presence-changed.js
Expand Up @@ -24,7 +24,7 @@ export function addOnPresenceChanged() {
WPP.whatsapp.PresenceStore.on('change:chatstate.type', (chatstate) => {
try {
// Search precense model from chatstate
const presence = WPP.whatsapp.PresenceStore.models.find(
const presence = WPP.whatsapp.PresenceStore.getModelsArray().find(
(m) => m.chatstate === chatstate
);

Expand All @@ -50,7 +50,8 @@ export function addOnPresenceChanged() {
}

if (presence.isGroup) {
data.participants = presence.chatstates.models
data.participants = presence.chatstates
.getModelsArray()
.filter((c) => !!c.type)
.map((c) => {
const contact = WPP.whatsapp.ContactStore.get(c.id);
Expand Down

0 comments on commit 1a96ab1

Please sign in to comment.