-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2ee4bd
commit 54ae3dd
Showing
13 changed files
with
1,844 additions
and
1,810 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { sendMessage } from './send-message'; | ||
export { sendMessage2 } from './send-message2'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export function sendMessage(id, message, done) { | ||
var chat = WAPI.getChat(id); | ||
if (chat) { | ||
if (done !== undefined) { | ||
chat.sendMessage(message).then(function() { | ||
function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
var trials = 0; | ||
|
||
function check() { | ||
for (let i = chat.msgs.models.length - 1; i >= 0; i--) { | ||
let msg = chat.msgs.models[i]; | ||
|
||
if (!msg.senderObj.isMe || msg.body != message) { | ||
continue; | ||
} | ||
done(WAPI._serializeMessageObj(msg)); | ||
return True; | ||
} | ||
trials += 1; | ||
// console.log(trials); | ||
|
||
if (trials > 30) { | ||
done(true); | ||
return; | ||
} | ||
sleep(500).then(check); | ||
} | ||
check(); | ||
}); | ||
return true; | ||
} else { | ||
chat.sendMessage(message); | ||
return true; | ||
} | ||
} else { | ||
if (done !== undefined) done(false); | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export function sendMessage2(id, message, done) { | ||
var chat = WAPI.getChat(id); | ||
if (chat !== undefined) { | ||
try { | ||
if (done !== undefined) { | ||
chat.sendMessage(message).then(function() { | ||
done(true); | ||
}); | ||
} else { | ||
chat.sendMessage(message); | ||
} | ||
return true; | ||
} catch (error) { | ||
if (done !== undefined) done(false); | ||
return false; | ||
} | ||
} | ||
if (done !== undefined) done(false); | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,4 @@ | |
"module": "commonjs", | ||
"target": "es6" | ||
}, | ||
"exclude": ["node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { _serializeChatObj } from './serialize-chat'; | ||
export { _serializeRawObj } from './serialize-raw'; | ||
export { _serializeMessageObj } from './serialize-message'; | ||
export { _serializeContactObj } from './serialize-contact'; | ||
export { _serializeNumberStatusObj } from './serialize-number-status'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { _serializeRawObj } from './serialize-raw'; | ||
|
||
/** | ||
* Serializes a chat object | ||
* | ||
* @param rawChat Chat object | ||
* @returns {Chat} | ||
*/ | ||
export const _serializeChatObj = obj => { | ||
if (obj == undefined) { | ||
return null; | ||
} | ||
|
||
return Object.assign(_serializeRawObj(obj), { | ||
kind: obj.kind, | ||
isGroup: obj.isGroup, | ||
contact: obj["contact"] | ||
? window.WAPI._serializeContactObj(obj["contact"]) | ||
: null, | ||
groupMetadata: obj["groupMetadata"] | ||
? _serializeRawObj(obj["groupMetadata"]) | ||
: null, | ||
presence: obj["presence"] | ||
? _serializeRawObj(obj["presence"]) | ||
: null, | ||
msgs: null, | ||
isOnline: obj.__x_presence.attributes.isOnline || null, | ||
lastSeen: | ||
obj && | ||
obj.previewMessage && | ||
obj.previewMessage.__x_ephemeralStartTimestamp | ||
? obj.previewMessage.__x_ephemeralStartTimestamp * 1000 | ||
: null | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Serializes contact object | ||
* @param {Contact} obj | ||
*/ | ||
export const _serializeContactObj = obj => { | ||
if (obj == undefined) { | ||
return null; | ||
} | ||
|
||
return Object.assign(window.WAPI._serializeRawObj(obj), { | ||
formattedName: obj.formattedName, | ||
isHighLevelVerified: obj.isHighLevelVerified, | ||
isMe: obj.isMe, | ||
isMyContact: obj.isMyContact, | ||
isPSA: obj.isPSA, | ||
isUser: obj.isUser, | ||
isVerified: obj.isVerified, | ||
isWAContact: obj.isWAContact, | ||
profilePicThumbObj: obj.profilePicThumb | ||
? WAPI._serializeProfilePicThumb(obj.profilePicThumb) | ||
: {}, | ||
statusMute: obj.statusMute, | ||
msgs: null | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Serializes chat object | ||
* @param {Chat} obj | ||
*/ | ||
export const _serializeMessageObj = obj => { | ||
if (obj == undefined) { | ||
return null; | ||
} | ||
const _chat = WAPI._serializeChatObj(obj["chat"]); | ||
return Object.assign(window.WAPI._serializeRawObj(obj), { | ||
id: obj.id._serialized, | ||
sender: obj["senderObj"] | ||
? WAPI._serializeContactObj(obj["senderObj"]) | ||
: null, | ||
timestamp: obj["t"], | ||
content: obj["body"], | ||
isGroupMsg: obj.isGroupMsg, | ||
isLink: obj.isLink, | ||
isMMS: obj.isMMS, | ||
isMedia: obj.isMedia, | ||
isNotification: obj.isNotification, | ||
isPSA: obj.isPSA, | ||
type: obj.type, | ||
chat: _chat, | ||
chatId: obj.id.remote, | ||
quotedMsgObj: WAPI._serializeMessageObj(obj["_quotedMsgObj"]), | ||
mediaData: window.WAPI._serializeRawObj(obj["mediaData"]), | ||
isOnline: _chat.isOnline, | ||
lastSeen: _chat.lastSeen | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Serializes number status object | ||
* @param {*} obj | ||
*/ | ||
export const _serializeNumberStatusObj = obj => { | ||
if (obj == undefined) { | ||
return null; | ||
} | ||
|
||
return Object.assign( | ||
{}, | ||
{ | ||
id: obj.jid, | ||
status: obj.status, | ||
isBusiness: obj.biz === true, | ||
canReceiveMessage: obj.status === 200 | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Serializes profile pic (thumbnail) object | ||
* @param {*} obj | ||
*/ | ||
export const _serializeProfilePicThumb = obj => { | ||
if (obj == undefined) { | ||
return null; | ||
} | ||
|
||
return Object.assign( | ||
{}, | ||
{ | ||
eurl: obj.eurl, | ||
id: obj.id, | ||
img: obj.img, | ||
imgFull: obj.imgFull, | ||
raw: obj.raw, | ||
tag: obj.tag | ||
} | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Serializes object into JSON format safely | ||
* @param {*} obj | ||
*/ | ||
export const _serializeRawObj = obj => { | ||
if (obj) { | ||
return obj.toJSON(); | ||
} | ||
return {}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { storeObjects } from "./store-objects"; | ||
|
||
export function getStore(modules) { | ||
let foundCount = 0; | ||
for (let idx in modules) { | ||
if (typeof modules[idx] === "object" && modules[idx] !== null) { | ||
let first = Object.values(modules[idx])[0]; | ||
if (typeof first === "object" && first.exports) { | ||
for (let idx2 in modules[idx]) { | ||
let module = modules(idx2); | ||
if (!module) { | ||
continue; | ||
} | ||
storeObjects.forEach(needObj => { | ||
if (!needObj.conditions || needObj.foundedModule) return; | ||
let neededModule = needObj.conditions(module); | ||
if (neededModule !== null) { | ||
foundCount++; | ||
needObj.foundedModule = neededModule; | ||
} | ||
}); | ||
if (foundCount == storeObjects.length) { | ||
break; | ||
} | ||
} | ||
|
||
let neededStore = storeObjects.find(needObj => needObj.id === "Store"); | ||
window.Store = neededStore.foundedModule | ||
? neededStore.foundedModule | ||
: {}; | ||
storeObjects.splice(storeObjects.indexOf(neededStore), 1); | ||
storeObjects.forEach(needObj => { | ||
if (needObj.foundedModule) { | ||
window.Store[needObj.id] = needObj.foundedModule; | ||
} | ||
}); | ||
window.Store.sendMessage = function(e) { | ||
return window.Store.SendTextMsgToChat(this, ...arguments); | ||
}; | ||
return window.Store; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.