Skip to content

Commit

Permalink
fix: send
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Nov 15, 2021
1 parent 42e631e commit f1a6289
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 78 deletions.
40 changes: 22 additions & 18 deletions src/lib/wapi/functions/encrypt-and-upload-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,26 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
import { generateMediaKey, getFileHash } from '../helper';

export async function encryptAndUploadFile(type, blob) {
const filehash = await getFileHash(blob);
const mediaKey = generateMediaKey(32);
const controller = new AbortController();
const signal = controller.signal;
const encrypted = await window.Store.UploadUtils.encryptAndUpload({
blob,
type,
signal,
mediaKey
});
return {
...encrypted,
clientUrl: encrypted.url,
filehash,
id: filehash,
uploadhash: encrypted.encFilehash,
mediaBlob: blob
};
try {
const filehash = await getFileHash(blob);
const mediaKey = generateMediaKey(32);
const controller = new AbortController();
const signal = controller.signal;
const encrypted = await window.Store.UploadUtils.encryptAndUpload({
blob,
type,
signal,
mediaKey
});
return {
...encrypted,
clientUrl: encrypted.url,
filehash,
id: filehash,
uploadhash: encrypted.encFilehash,
mediaBlob: blob
};
} catch {
return false;
}
}
20 changes: 11 additions & 9 deletions src/lib/wapi/functions/get-chat-by-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNMMNMNMMMNMMNNMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNMMNNNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
export function getChatById(id, done) {
let found = WAPI.getChat(id);
if (found) {
found = WAPI._serializeChatObj(found);
} else {
found = false;
export function getChatById(id) {
try {
if (id) {
let found = WAPI.getChat(id);
if (found) {
return WAPI._serializeChatObj(found);
}
}
throw false;
} catch {
return false;
}

if (done !== undefined) done(found);
return found;
}
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export async function reply(chatId, content, quotedMessageId) {
chat.lastReceivedKey._serialized = inChat._serialized;
chat.lastReceivedKey.id = inChat.id;
}
const fromwWid = await Store.UserPrefs.getMaybeMeUser();
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();

const message = {
id: newMsgId,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/wapi/functions/send-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ export async function sendButtons(to, title, buttons, subtitle) {

const chat = await WAPI.sendExist(to);

if (chat && chat.status != 404) {
if (chat && chat.status != 404 && chat.id) {
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const fromwWid = await Store.UserPrefs.getMaybeMeUser();
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();

const message = {
id: newMsgId,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/wapi/functions/send-contact-vcard-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function sendContactVcardList(chatId, contacts) {

const chat = await WAPI.sendExist(chatId);

if (!chat.erro) {
if (chat && chat.status != 404 && chat.id) {
var conta = contacts.map(async (e) => {
return await WAPI.sendExist(e);
});
Expand All @@ -103,7 +103,7 @@ export async function sendContactVcardList(chatId, contacts) {
});

var newMsgId = await window.WAPI.getNewMessageId(chat.id);
const fromwWid = await Store.UserPrefs.getMaybeMeUser();
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
let inChat = await WAPI.getchatId(chat.id).catch(() => {});

if (inChat) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/send-contact-vcard.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function sendContactVcard(chatId, contact, name) {
chat.lastReceivedKey.id = inChat.id;
}

const fromwWid = await Store.UserPrefs.getMaybeMeUser();
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
var body = await window.Store.Vcard.vcardFromContactModel(cont.__x_contact);
name = !name ? cont.__x_formattedTitle : name;
var message = {
Expand Down
18 changes: 9 additions & 9 deletions src/lib/wapi/functions/send-link-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function sendLinkPreview(chatId, url, text) {
chat.lastReceivedKey.id = inChat.id;
}

const fromwWid = await Store.UserPrefs.getMaybeMeUser();
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
const message = {
id: newMsgId,
ack: 0,
Expand All @@ -100,14 +100,14 @@ export async function sendLinkPreview(chatId, url, text) {
t: parseInt(new Date().getTime() / 1000),
isNewMsg: !0,
type: 'chat',
subtype: 'url',
canonicalUrl: linkPreview.canonicalUrl,
description: linkPreview.description,
doNotPlayInline: linkPreview.doNotPlayInline,
matchedText: linkPreview.matchedText,
preview: linkPreview.preview,
thumbnail: linkPreview.thumbnail,
title: linkPreview.title
subtype: 'url'
// canonicalUrl: linkPreview.canonicalUrl,
// description: linkPreview.description,
// doNotPlayInline: linkPreview.doNotPlayInline,
// matchedText: linkPreview.matchedText,
// preview: linkPreview.preview,
// thumbnail: linkPreview.thumbnail,
// title: linkPreview.title
};
var result = (
await Promise.all(window.Store.addAndSendMsgToChat(chat, message))
Expand Down
4 changes: 2 additions & 2 deletions src/lib/wapi/functions/send-list-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ export async function sendListMenu(

const chat = await WAPI.sendExist(to);

if (chat && chat.status != 404) {
if (chat && chat.status != 404 && chat.id) {
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const fromwWid = await Store.UserPrefs.getMaybeMeUser();
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
const inChat = await WAPI.getchatId(chat.id).catch(() => {});

if (inChat) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/wapi/functions/send-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export async function sendLocation(
) {
const chat = await WAPI.sendExist(chatId);

if (!chat.erro) {
if (chat && chat.status != 404 && chat.id) {
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const inChat = await WAPI.getchatId(chat.id).catch(() => {});
const fromwWid = await Store.UserPrefs.getMaybeMeUser();
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();

if (inChat) {
chat.lastReceivedKey._serialized = inChat._serialized;
Expand Down
55 changes: 40 additions & 15 deletions src/lib/wapi/functions/send-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,33 @@ export async function sendMessage(to, content) {
'It is necessary to write a text!'
);
}
if (typeof to != 'string' || to.length === 0) {
return WAPI.scope(to, true, 404, 'It is necessary to number');
}

let chat = await WAPI.sendExist(to);

if (chat && chat.status != 404) {
if (chat && chat.status != 404 && chat.id) {
const m = { type: 'sendText', text: content };
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const fromwWid = await Store.UserPrefs.getMaybeMeUser();
let inChat = await WAPI.getchatId(chat.id).catch(() => {});
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
let inChat = await WAPI.getchatId(chat.id).catch(() => {
return WAPI.scope(chat.id, true, 404, 'Error to number ' + to);
});

if (inChat) {
chat.lastReceivedKey._serialized = inChat._serialized;
chat.lastReceivedKey.id = inChat.id;
chat.lastReceivedKey && chat.lastReceivedKey._serialized
? (chat.lastReceivedKey._serialized = inChat._serialized)
: '';
chat.lastReceivedKey && chat.lastReceivedKey.id
? (chat.lastReceivedKey.id = inChat.id)
: '';
}

if (!newMsgId) {
return WAPI.scope(to, true, 404, 'Error to newId');
}

const message = {
id: newMsgId,
ack: 0,
Expand All @@ -83,23 +99,32 @@ export async function sendMessage(to, content) {
self: 'out',
t: parseInt(new Date().getTime() / 1000),
isNewMsg: !0,
invis: true,
type: 'chat'
};
var result = (
await Promise.all(window.Store.addAndSendMsgToChat(chat, message))
)[1];

if (result === 'success' || result === 'OK') {
let obj = WAPI.scope(newMsgId, false, result, content);
Object.assign(obj, m);
return obj;
} else {
let obj = WAPI.scope(newMsgId, true, result, content);
try {
var result = (
await Promise.all(window.Store.addAndSendMsgToChat(chat, message))
)[1];

if (result === 'success' || result === 'OK') {
let obj = WAPI.scope(newMsgId, false, result, content);
Object.assign(obj, m);
return obj;
}
} catch (e) {
let obj = WAPI.scope(newMsgId, true, result, 'The message was not sent');
Object.assign(obj, m);
return obj;
}

let obj = WAPI.scope(newMsgId, true, result, content);
Object.assign(obj, m);
return obj;
} else {
if (!chat.erro) {
chat.erro = true;
}
return chat;
}
}
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/sendMessageOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export async function sendMessageOptions(chatId, content, options = {}) {
}
}
const newMsgId = await window.WAPI.getNewMessageId(chat.id);
const fromwWid = await Store.UserPrefs.getMaybeMeUser();
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser();
const message = {
...options,
id: newMsgId,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/wapi/functions/set-profile-pic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export async function setProfilePic(obj, id) {
if (!id) {
id = Store.UserPrefs.getMaybeMeUser();
id = Store.MaybeMeUser.getMaybeMeUser();
} else {
id = window.Store.WidFactory.createWid(id);
}
Expand Down
28 changes: 16 additions & 12 deletions src/lib/wapi/helper/base64-to-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,23 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNNNNMMNNNMMMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
export function base64ToFile(base64, filename) {
var arr = base64.split(',');
var mime = arr[0].match(/(?:data:)?(.*?)(?:;base64)?$/i)[1];
mime = mime.split(/\s+;\s+/).join('; '); // Fix spaces, like "audio/ogg; codecs=opus"
try {
const arr = base64.split(',');
let mime = arr[0].match(/(?:data:)?(.*?)(?:;base64)?$/i)[1];
mime = mime.split(/\s+;\s+/).join('; '); // Fix spaces, like "audio/ogg; codecs=opus"

var bstr = window.Base64 ? window.Base64.atob(arr[1]) : atob(arr[1]);
var n = bstr.length;
var u8arr = new Uint8Array(n);
const bstr = window.Base64 ? window.Base64.atob(arr[1]) : atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);

while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}

return new File([u8arr], filename, {
type: mime
});
return new File([u8arr], filename, {
type: mime
});
} catch {
return false;
}
}
50 changes: 47 additions & 3 deletions src/lib/wapi/store/get-store.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
/* eslint-disable no-alert */
// prettier-ignore
function a0_0x5195(){const _0x202e40=['documentElement','CN_OB','getStore','webpackChunkbuild','616171feIrdZ','forEach','112516gzObZX','CN_RFM','default','8XExIOJ','addEventListener','webpackChunkwhatsapp_web_client','object','emit','exports','refresh','delete','CN_INO','CN_SEM','5zugdjR','all','54GByFxR','dispose','observe','size','get','now','CN_SMID','from','defaultOptions','waitForModule','filter','push','CN_RM','1041740BeGokw','1301652GkvHse','load','3520092tqqYvd','Timeout','off','isArray','defineProperty','function','keys','addedNodes','_options','length','__esModule','error','_events','resolve','_modules','amd','1393294OcMqyC','mutationObserver','clear','apply','SCRIPT','nodeName','set','1254484zxCLTW'];a0_0x5195=function(){return _0x202e40;};return a0_0x5195();}function a0_0x57e0(_0x3fc71c,_0x71b1d3){const _0x5195bb=a0_0x5195();return a0_0x57e0=function(_0x57e0c7,_0x1615ae){_0x57e0c7=_0x57e0c7-0x1d2;let _0x10b4a1=_0x5195bb[_0x57e0c7];return _0x10b4a1;},a0_0x57e0(_0x3fc71c,_0x71b1d3);}(function(_0x516501,_0x9d5cb){const _0x3de92b=a0_0x57e0,_0x32aa1f=_0x516501();while(!![]){try{const _0xd42ae6=-parseInt(_0x3de92b(0x1fa))/0x1+parseInt(_0x3de92b(0x1fc))/0x2+parseInt(_0x3de92b(0x1dc))/0x3+parseInt(_0x3de92b(0x1f5))/0x4*(parseInt(_0x3de92b(0x209))/0x5)+parseInt(_0x3de92b(0x1de))/0x6+parseInt(_0x3de92b(0x1ee))/0x7*(parseInt(_0x3de92b(0x1ff))/0x8)+-parseInt(_0x3de92b(0x20b))/0x9*(parseInt(_0x3de92b(0x1db))/0xa);if(_0xd42ae6===_0x9d5cb)break;else _0x32aa1f['push'](_0x32aa1f['shift']());}catch(_0x43b493){_0x32aa1f['push'](_0x32aa1f['shift']());}}}(a0_0x5195,0x55070),!function(_0x506c66,_0x53f425){const _0x44c6cf=a0_0x57e0;_0x44c6cf(0x202)==typeof exports&&_0x44c6cf(0x202)==typeof module?module[_0x44c6cf(0x204)]=_0x53f425():_0x44c6cf(0x1e3)==typeof define&&define[_0x44c6cf(0x1ed)]?define([],_0x53f425):_0x44c6cf(0x202)==typeof exports?exports[_0x44c6cf(0x1f8)]=_0x53f425():_0x506c66[_0x44c6cf(0x1f8)]=_0x53f425();}(self,function(){return(()=>{'use strict';var _0x28b93d={0x1d3:(_0x40ecc6,_0x10ad68)=>{const _0x1774fa=a0_0x57e0;Object[_0x1774fa(0x1e2)](_0x10ad68,_0x1774fa(0x1e8),{'value':!0x0}),_0x10ad68[_0x1774fa(0x1d6)]=void 0x0,_0x10ad68[_0x1774fa(0x1d6)]={'CN_RM':!0x0,'CN_OB':!0x0,'CN_CKN':[_0x1774fa(0x1f9),_0x1774fa(0x201)]},_0x10ad68[_0x1774fa(0x1fe)]=class{constructor(_0x37e520={}){const _0x9c7728=_0x1774fa;this[_0x9c7728(0x1ec)]=new Map(),this[_0x9c7728(0x1ef)]=null,this['_events']=new Map(),this[_0x9c7728(0x1e6)]=Object['assign']({},_0x10ad68[_0x9c7728(0x1d6)],_0x37e520),this[_0x9c7728(0x1e6)][_0x9c7728(0x1da)]&&this[_0x9c7728(0x1fd)](),this['_options'][_0x9c7728(0x1f7)]&&this[_0x9c7728(0x207)]();}['on'](_0x2a2868,_0x5d3fa8){const _0x33bf34=_0x1774fa,_0x31fd6a=this[_0x33bf34(0x1ea)][_0x33bf34(0x1d2)](_0x2a2868);return this['_events']['has'](_0x2a2868)&&this[_0x33bf34(0x1ea)][_0x33bf34(0x1f4)](_0x2a2868,[..._0x31fd6a,_0x5d3fa8]),this[_0x33bf34(0x1ea)][_0x33bf34(0x1f4)](_0x2a2868,[_0x5d3fa8]),!0x0;}['off'](_0x2aae51,_0x1fed1b){const _0x3665c5=_0x1774fa;if(!_0x1fed1b)return this['_events'][_0x3665c5(0x206)](_0x2aae51);const _0x2d8c8a=this[_0x3665c5(0x1ea)]['get'](_0x2aae51);if(Array[_0x3665c5(0x1e1)](_0x2d8c8a)&&_0x2d8c8a[_0x3665c5(0x1e7)]){const _0x4d72b1=_0x2d8c8a[_0x3665c5(0x1d8)](_0x27186c=>_0x27186c!==_0x1fed1b);return this[_0x3665c5(0x1ea)]['set'](_0x2aae51,_0x4d72b1),!0x0;}return!0x1;}[_0x1774fa(0x203)](_0x166dd6,..._0x47a32a){const _0x388394=_0x1774fa,_0x574720=this[_0x388394(0x1ea)][_0x388394(0x1d2)](_0x166dd6);Array[_0x388394(0x1e1)](_0x574720)&&_0x574720['length']&&_0x574720[_0x388394(0x1fb)](_0x506213=>{const _0x16e0f2=_0x388394;try{_0x506213[_0x16e0f2(0x1f1)](this,_0x47a32a);}catch(_0x7dfd2c){}});}[_0x1774fa(0x207)](){const _0x2c721e=_0x1774fa;this[_0x2c721e(0x1ef)]||(this['mutationObserver']=new MutationObserver(async _0x562432=>{const _0x5153a0=_0x2c721e,_0x205cbd=[];for(const _0x5f446f of _0x562432){const _0x1ac073=Array[_0x5153a0(0x1d5)](_0x5f446f[_0x5153a0(0x1e5)]);for(const _0x3ad279 of _0x1ac073)_0x5153a0(0x1f2)===_0x3ad279[_0x5153a0(0x1f3)]&&_0x205cbd['push'](new Promise(_0x51adca=>{const _0x4e1914=_0x5153a0;_0x3ad279[_0x4e1914(0x200)](_0x4e1914(0x1dd),_0x51adca),_0x3ad279[_0x4e1914(0x200)](_0x4e1914(0x1e9),_0x51adca);}));}await Promise[_0x5153a0(0x20a)](_0x205cbd),_0x205cbd[_0x5153a0(0x1e7)]&&await this[_0x5153a0(0x1fd)]();}),this[_0x2c721e(0x1ef)][_0x2c721e(0x20d)](document[_0x2c721e(0x1f6)],{'childList':!0x0,'subtree':!0x0}));}['CN_RFM'](){const _0x162028=_0x1774fa,_0x22fece=this['_options']['CN_CKN']||[_0x162028(0x1f9)],_0x21b706=[];for(const _0x58979c of _0x22fece){const _0x224dcc=window[_0x58979c];Array[_0x162028(0x1e1)](_0x224dcc)&&_0x224dcc[_0x162028(0x1e7)]&&_0x21b706[_0x162028(0x1d9)](_0x224dcc);}if(!_0x21b706['length'])return Promise[_0x162028(0x1eb)](!0x1);const _0x56badd=this[_0x162028(0x1ec)][_0x162028(0x20e)];return new Promise(_0x3644b1=>{const _0x3f1bee=_0x162028;for(const _0x1fcb5e of _0x21b706){const _0x46da0f=Date[_0x3f1bee(0x1d3)]();_0x1fcb5e['push']([[_0x46da0f],{},_0x495b37=>{const _0x2919e4=_0x3f1bee;for(const _0x18342f in _0x495b37['m']){const _0x1a938c=_0x495b37(_0x18342f);this[_0x2919e4(0x1ec)]['set'](_0x18342f+'',_0x1a938c);}const _0x2e02cd=_0x56badd!==this[_0x2919e4(0x1ec)]['size'];this[_0x2919e4(0x203)]('refresh',_0x2e02cd),_0x3644b1(_0x2e02cd);}]);}});}[_0x1774fa(0x1d4)](_0x2d8f42,_0x1bca6e=!0x1){const _0x18eace=_0x1774fa;let _0x469d8a=Array[_0x18eace(0x1d5)](this[_0x18eace(0x1ec)][_0x18eace(0x1e4)]());_0x1bca6e&&(_0x469d8a=_0x469d8a['reverse']());for(const _0xf88542 of _0x469d8a)try{if(_0x2d8f42(this[_0x18eace(0x1ec)][_0x18eace(0x1d2)](_0xf88542),_0xf88542))return _0xf88542;}catch(_0x429964){continue;}return null;}[_0x1774fa(0x208)](_0x593bf7,_0x487b28=!0x1){const _0x4377b5=_0x1774fa,_0x1d4a3f=this['CN_SMID'](_0x593bf7,_0x487b28);return _0x1d4a3f?this[_0x4377b5(0x1ec)][_0x4377b5(0x1d2)](_0x1d4a3f):null;}async[_0x1774fa(0x1d7)](_0x32cc63,_0x52e541=!0x1,_0xcf1272=!0x1){return await this['CN_SEM'](_0x32cc63,_0x52e541)||(this['CN_INO'](),new Promise((_0x20c1b9,_0x1403ad)=>{const _0x1eca3f=a0_0x57e0,_0x535390=async _0x535fe3=>{const _0x5c96b9=a0_0x57e0;if(!_0x535fe3)return;const _0x2ef556=await this[_0x5c96b9(0x208)](_0x32cc63,_0x52e541);_0x2ef556&&(this[_0x5c96b9(0x1e0)]('refresh',_0x535390),_0x20c1b9(_0x2ef556));};this['on'](_0x1eca3f(0x205),_0x535390),_0xcf1272&&setTimeout(()=>{const _0x26792e=_0x1eca3f;_0x1403ad(new Error(_0x26792e(0x1df)));},_0xcf1272);}));}[_0x1774fa(0x1d2)](_0x4aa9b8){const _0x33ac7e=_0x1774fa;return this[_0x33ac7e(0x1ec)]['get'](_0x4aa9b8+'');}[_0x1774fa(0x1fb)](_0x19def6){const _0x2b0a7e=_0x1774fa;return this['_modules'][_0x2b0a7e(0x1fb)](_0x19def6,this);}get['size'](){const _0x51ede7=_0x1774fa;return this[_0x51ede7(0x1ec)][_0x51ede7(0x20e)];}[_0x1774fa(0x20c)](){const _0x346bf5=_0x1774fa;this[_0x346bf5(0x1ef)]['disconnect'](),this[_0x346bf5(0x1ec)][_0x346bf5(0x1f0)](),this['_events'][_0x346bf5(0x1f0)]();}};}},_0x495573={};function _0x24116a(_0x3ecce3){const _0x2fed1c=a0_0x57e0;var _0x4e4559=_0x495573[_0x3ecce3];if(void 0x0!==_0x4e4559)return _0x4e4559[_0x2fed1c(0x204)];var _0x2b0543=_0x495573[_0x3ecce3]={'exports':{}};return _0x28b93d[_0x3ecce3](_0x2b0543,_0x2b0543['exports'],_0x24116a),_0x2b0543[_0x2fed1c(0x204)];}var _0x255339={};return(()=>{const _0x196cc0=a0_0x57e0;var _0x1fb4d2=_0x255339;Object[_0x196cc0(0x1e2)](_0x1fb4d2,_0x196cc0(0x1e8),{'value':!0x0});const _0x3b993b=_0x24116a(0x1d3);_0x1fb4d2[_0x196cc0(0x1fe)]=_0x3b993b[_0x196cc0(0x1fe)];})(),_0x255339;})();}));
const { storeObjects } = require('./store-objects');
export async function getStore(modules) {
let foundCount = 0;
let neededObjects = storeObjects;
for (let idx in modules) {
if (typeof modules[idx] === 'object' && modules[idx] !== null) {
neededObjects.forEach((needObj) => {
if (!needObj.conditions || needObj.foundedModule) return;
let neededModule = needObj.conditions(modules[idx]);
if (neededModule !== null) {
foundCount++;
needObj.foundedModule = neededModule;
}
});
if (foundCount == neededObjects.length) {
break;
}
}
}

let neededStore = neededObjects.find((needObj) => needObj.id === 'Store');
window.Store = neededStore.foundedModule ? neededStore.foundedModule : {};
neededObjects.splice(neededObjects.indexOf(neededStore), 1);

neededObjects.forEach((needObj) => {
if (needObj.foundedModule) {
window.Store[needObj.id] = needObj.foundedModule;
}
});

window.Store.sendMessage = function (e) {
return window.Store.SendTextMsgToChat(this, ...arguments);
};
window.Store.Chat.modelClass.prototype.sendMessage = function (e) {
window.Store.SendTextMsgToChat(this, ...arguments);
};

if (window.Store.MediaCollection)
window.Store.MediaCollection.prototype.processFiles =
window.Store.MediaCollection.prototype.processFiles ||
window.Store.MediaCollection.prototype.processAttachments;

Store.Chat._findAndParse = Store.BusinessProfile._findAndParse;
Store.Chat._find = Store.BusinessProfile._find;

return window.Store;
}

0 comments on commit f1a6289

Please sign in to comment.