Add eslint config and fix linting issues

This commit is contained in:
Pedro Lopez
2020-02-02 14:50:04 -04:00
parent 8eb461ed32
commit cc477f9545
11 changed files with 1047 additions and 124 deletions

View File

@@ -1,6 +1,6 @@
'use strict';
exports.WhatsWebURL = 'https://web.whatsapp.com/'
exports.WhatsWebURL = 'https://web.whatsapp.com/';
exports.UserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36';
@@ -9,13 +9,13 @@ exports.DefaultOptions = {
headless: true
},
session: false
}
};
exports.Status = {
INITIALIZING: 0,
AUTHENTICATING: 1,
READY: 3
}
};
exports.Events = {
AUTHENTICATED: 'authenticated',
@@ -25,7 +25,7 @@ exports.Events = {
MESSAGE_CREATE: 'message_create',
QR_RECEIVED: 'qr',
DISCONNECTED: 'disconnected'
}
};
exports.MessageTypes = {
TEXT: 'chat',
@@ -35,25 +35,25 @@ exports.MessageTypes = {
VIDEO: 'video',
DOCUMENT: 'document',
STICKER: 'sticker'
}
};
exports.ChatTypes = {
SOLO: 'solo',
GROUP: 'group',
UNKNOWN: 'unknown'
}
};
exports.WAState = {
CONFLICT: "CONFLICT",
CONNECTED: "CONNECTED",
DEPRECATED_VERSION: "DEPRECATED_VERSION",
OPENING: "OPENING",
PAIRING: "PAIRING",
PROXYBLOCK: "PROXYBLOCK",
SMB_TOS_BLOCK: "SMB_TOS_BLOCK",
TIMEOUT: "TIMEOUT",
TOS_BLOCK: "TOS_BLOCK",
UNLAUNCHED: "UNLAUNCHED",
UNPAIRED: "UNPAIRED",
UNPAIRED_IDLE: "UNPAIRED_IDLE"
}
CONFLICT: 'CONFLICT',
CONNECTED: 'CONNECTED',
DEPRECATED_VERSION: 'DEPRECATED_VERSION',
OPENING: 'OPENING',
PAIRING: 'PAIRING',
PROXYBLOCK: 'PROXYBLOCK',
SMB_TOS_BLOCK: 'SMB_TOS_BLOCK',
TIMEOUT: 'TIMEOUT',
TOS_BLOCK: 'TOS_BLOCK',
UNLAUNCHED: 'UNLAUNCHED',
UNPAIRED: 'UNPAIRED',
UNPAIRED_IDLE: 'UNPAIRED_IDLE'
};

View File

@@ -4,34 +4,35 @@
* Exposes the internal Store to the WhatsApp Web client
*/
exports.ExposeStore = (moduleRaidStr) => {
eval("var moduleRaid = " + moduleRaidStr);
eval('var moduleRaid = ' + moduleRaidStr);
// eslint-disable-next-line no-undef
window.mR = moduleRaid();
window.Store = window.mR.findModule("Chat")[1].default;
window.Store.AppState = window.mR.findModule("STREAM")[0].default;
window.Store.Conn = window.mR.findModule("Conn")[0].default;
window.Store.CryptoLib = window.mR.findModule("decryptE2EMedia")[0];
window.Store.Wap = window.mR.findModule("Wap")[0].default;
window.Store = window.mR.findModule('Chat')[1].default;
window.Store.AppState = window.mR.findModule('STREAM')[0].default;
window.Store.Conn = window.mR.findModule('Conn')[0].default;
window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0];
window.Store.Wap = window.mR.findModule('Wap')[0].default;
window.Store.genId = window.mR.findModule((module) => module.default && typeof module.default === 'function' && module.default.toString().match(/crypto/))[0].default;
window.Store.SendMessage = window.mR.findModule("addAndSendMsgToChat")[0];
window.Store.SendMessage = window.mR.findModule('addAndSendMsgToChat')[0];
window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default;
window.Store.Invite = window.mR.findModule("sendJoinGroupViaInvite")[0];
}
window.Store.Invite = window.mR.findModule('sendJoinGroupViaInvite')[0];
};
exports.LoadUtils = () => {
window.WWebJS = {};
window.WWebJS.sendMessage = async (chat, content, options) => {
const newMsgId = new Store.MsgKey({
from: Store.Conn.me,
const newMsgId = new window.Store.MsgKey({
from: window.Store.Conn.me,
to: chat.id,
id: Store.genId(),
id: window.Store.genId(),
});
const message = {
id: newMsgId,
ack: 0,
body: content,
from: Store.Conn.me,
from: window.Store.Conn.me,
to: chat.id,
local: true,
self: 'out',
@@ -39,11 +40,11 @@ exports.LoadUtils = () => {
isNewMsg: true,
type: 'chat',
...options
}
};
await Store.SendMessage.addAndSendMsgToChat(chat, message);
return Store.Msg.get(newMsgId._serialized);
}
await window.Store.SendMessage.addAndSendMsgToChat(chat, message);
return window.Store.Msg.get(newMsgId._serialized);
};
window.WWebJS.getChatModel = chat => {
let res = chat.serialize();
@@ -55,22 +56,22 @@ exports.LoadUtils = () => {
}
return res;
}
};
window.WWebJS.getChat = chatId => {
const chat = Store.Chat.get(chatId);
return WWebJS.getChatModel(chat);
}
const chat = window.Store.Chat.get(chatId);
return window.WWebJS.getChatModel(chat);
};
window.WWebJS.getChats = () => {
const chats = Store.Chat.models;
return chats.map(chat => WWebJS.getChatModel(chat));
}
const chats = window.Store.Chat.models;
return chats.map(chat => window.WWebJS.getChatModel(chat));
};
window.WWebJS.downloadBuffer = (url) => {
return new Promise(function(resolve, reject) {
let xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.open('GET', url);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
if (xhr.status == 200) {
@@ -90,27 +91,27 @@ exports.LoadUtils = () => {
};
xhr.send(null);
});
}
};
window.WWebJS.readBlobAsync = (blob) => {
return new Promise((resolve, reject) => {
let reader = new FileReader();
let reader = new FileReader();
reader.onload = () => {
resolve(reader.result);
};
reader.onload = () => {
resolve(reader.result);
};
reader.onerror = reject;
reader.onerror = reject;
reader.readAsDataURL(blob);
})
}
}
reader.readAsDataURL(blob);
});
};
};
exports.MarkAllRead = () => {
let Chats = Store.Chat.models;
let Chats = window.Store.Chat.models;
for (chatIndex in Chats) {
for (let chatIndex in Chats) {
if (isNaN(chatIndex)) {
continue;
}
@@ -119,7 +120,7 @@ exports.MarkAllRead = () => {
if (chat.unreadCount > 0) {
chat.markSeen();
Store.Wap.sendConversationSeen(chat.id, chat.getLastMsgKeyForAction(), chat.unreadCount - chat.pendingSeenCount);
window.Store.Wap.sendConversationSeen(chat.id, chat.getLastMsgKeyForAction(), chat.unreadCount - chat.pendingSeenCount);
}
}
}
};

View File

@@ -7,29 +7,29 @@ const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
*/
class Util {
constructor() {
throw new Error(`The ${this.constructor.name} class may not be instantiated.`);
}
/**
* Sets default properties on an object that aren't already specified.
* @param {Object} def Default properties
* @param {Object} given Object to assign defaults to
* @returns {Object}
* @private
*/
static mergeDefault(def, given) {
if (!given) return def;
for (const key in def) {
if (!has(given, key) || given[key] === undefined) {
given[key] = def[key];
} else if (given[key] === Object(given[key])) {
given[key] = Util.mergeDefault(def[key], given[key]);
}
constructor() {
throw new Error(`The ${this.constructor.name} class may not be instantiated.`);
}
return given;
}
/**
* Sets default properties on an object that aren't already specified.
* @param {Object} def Default properties
* @param {Object} given Object to assign defaults to
* @returns {Object}
* @private
*/
static mergeDefault(def, given) {
if (!given) return def;
for (const key in def) {
if (!has(given, key) || given[key] === undefined) {
given[key] = def[key];
} else if (given[key] === Object(given[key])) {
given[key] = Util.mergeDefault(def[key], given[key]);
}
}
return given;
}
}
module.exports = Util;