Skip to content

Commit

Permalink
feat: Get Chat Module
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Jul 13, 2022
1 parent b384162 commit a1701a2
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/webpack/@types/API.d.ts
Expand Up @@ -4,6 +4,7 @@ interface API {
newMessage: (callback: Function) => void;
newOnAck: (callback: Function) => void;
getAllContacts: () => void;
addChatWapi: () => void;
}

declare global {
Expand Down
1 change: 1 addition & 0 deletions src/webpack/api/browser.ts
Expand Up @@ -14,6 +14,7 @@ export async function initBrowser(Browser: Browser): Promise<Page | boolean> {
if (wpage) {
try {
await wpage.setUserAgent(puppeteerConfig.useragentOverride);
await wpage.setCacheEnabled(true);
await wpage.goto(puppeteerConfig.whatsappUrl, {
waitUntil: 'domcontentloaded',
});
Expand Down
1 change: 1 addition & 0 deletions src/webpack/api/init.ts
Expand Up @@ -108,6 +108,7 @@ export async function initServer(
interFace.result.mode === 'MAIN' &&
interFace.result.info === 'NORMAL'
) {
client.addChatWapi();
ev.statusFind = {
erro: false,
connect: true,
Expand Down
4 changes: 3 additions & 1 deletion src/webpack/assets/api.js
Expand Up @@ -18,7 +18,8 @@ import {
sendExist,
checkNumberStatus,
isMD,
sendCheckType
sendCheckType,
addChatWapi
} from './functions/help';

import {
Expand Down Expand Up @@ -77,6 +78,7 @@ if (typeof window.API === 'undefined') {
window.API.encryptAndUploadFile = encryptAndUploadFile;
window.API.getFileHash = getFileHash;
window.API.sendCheckType = sendCheckType;
window.API.addChatWapi = addChatWapi;

// Functions
window.API.sendMessage = sendMessage;
Expand Down
34 changes: 34 additions & 0 deletions src/webpack/assets/functions/help/add-chat-wapi.js
@@ -0,0 +1,34 @@
function getChat(modules) {
for (let idx in modules) {
if (typeof modules[idx] === 'object' && modules[idx] !== null) {
const module = modules[idx];
const evet =
module.default && module.default.Chat && module.default.Msg
? module.default.Chat
: null;

if (evet) {
Store['Chat'] = evet;
if (Store && Store.BusinessProfile) {
Store.Chat._findAndParse = Store.BusinessProfile._findAndParse;
Store.Chat._find = Store.BusinessProfile._find;
}
}
}
}
}

export async function addChatWapi() {
const parasite = `chat${Date.now()}`;
window['webpackChunkwhatsapp_web_client'].push([
[parasite],
{},
function (o) {
let modules = [];
for (let idx in o.m) {
modules.push(o(idx));
}
getChat(modules);
},
]);
}
3 changes: 2 additions & 1 deletion src/webpack/assets/functions/help/index.js
Expand Up @@ -5,4 +5,5 @@ export { getNewMessageId } from './get-new-message';
export { sendExist } from './send-exist';
export { checkNumberStatus } from './check-number-status';
export { sendCheckType } from './send-check-type';
export { isMD } from './is-md';
export { isMD } from './is-md';
export { addChatWapi } from './add-chat-wapi';
34 changes: 15 additions & 19 deletions src/webpack/assets/help/inject-paresite.js
Expand Up @@ -29,30 +29,26 @@ export const injectParasiteSnake = async () => {
}
}

let neededStore = filterObjects.find((e) => e.type === 'Module');

if (neededStore) {
window.Store = filterObjects.yesModule ? filterObjects.yesModule : {};
}

filterObjects.splice(filterObjects.indexOf(neededStore), 1);

filterObjects.forEach((needObj) => {
if (needObj.yesModule) {
window.Store[needObj.type] = needObj.yesModule;
if (needObj.type !== "Module") {
window.Store[needObj.type] = needObj.yesModule;
}
}
});

if (typeof neededStore?.yesModule === 'object') {
Object.keys(neededStore.yesModule).forEach((e) => {
window.Store[e] = neededStore.yesModule[e];
})
}

if (Store && Store.BusinessProfile) {
Store.Chat._findAndParse = Store.BusinessProfile._findAndParse;
Store.Chat._find = Store.BusinessProfile._find;
}
},
const module = (filterObjects.filter((e) => e.type === "Module"))[0].yesModule;
Object.keys(module).forEach((key) => {
if (!['Chat'].includes(key)) {
if (window.Store[key]) {
window.Store[key + '_'] = module[key];
} else {
window.Store[key] = module[key];
}
}
});

}
]);
}

0 comments on commit a1701a2

Please sign in to comment.