-
Notifications
You must be signed in to change notification settings - Fork 18
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
Showing
12 changed files
with
280 additions
and
95 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
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,16 @@ | ||
/** | ||
* Function to get all chats | ||
* @returns - Array of chats | ||
*/ | ||
export const getAllChats = async () => { | ||
const fromwWid = await Store.MaybeMeUser.getMaybeMeUser(); | ||
if (fromwWid) { | ||
const idUser = await API.returnChat(fromwWid._serialized); | ||
if (idUser && idUser.status !== 404) { | ||
const chats = Store.Chat.map((chat) => | ||
API.serializeChatObj(chat) | ||
); | ||
return chats; | ||
} | ||
} | ||
}; |
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,12 @@ | ||
/** | ||
* Function to get contact by id | ||
* @param {*} id | ||
* @returns | ||
*/ | ||
export const getContact = (id) => { | ||
const found = window.Store.Contact.get(id); | ||
if (found) { | ||
return window.API.serializeContactObj(found); | ||
} | ||
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,15 @@ | ||
/** | ||
* Function to check if a number is registered on WhatsApp chat | ||
* @param {*} id - The phone number | ||
* @returns - Return the status of the number | ||
*/ | ||
export const checkChatExist = async (id) => { | ||
try { | ||
const chat = await Store.Chat.find(id); | ||
if (chat?.chatEntryPoint === 'Chatlist') { | ||
return chat.id; | ||
} | ||
} catch (error) { | ||
return false; | ||
} | ||
}; |
149 changes: 92 additions & 57 deletions
149
src/webpack/assets/functions/help/check-number-status.js
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 |
---|---|---|
@@ -1,71 +1,106 @@ | ||
export async function checkNumberStatus(id, conn = false) { | ||
try { | ||
/** | ||
* Function to check if a number is registered on WhatsApp | ||
* @param {*} id - The phone number | ||
* @param {*} conn - Check if the connection is connected | ||
* @returns {Promise<Object>} - Return the status of the number | ||
*/ | ||
export const checkNumberStatus = async (id, conn = false) => { | ||
return new Promise(async (resolve, reject) => { | ||
try { | ||
const err = { | ||
error: 404 | ||
}; | ||
const connection = | ||
Store && | ||
Store.State && | ||
Store.State.Socket && | ||
Store.State.Socket.state | ||
? Store.State.Socket.state | ||
: ''; | ||
|
||
const err = { | ||
error: 404 | ||
}; | ||
|
||
const connection = | ||
window.Store && | ||
window.Store.State && | ||
window.Store.State.Socket && | ||
window.Store.State.Socket.state ? | ||
window.Store.State.Socket.state : | ||
''; | ||
|
||
if (conn === true) { | ||
if (connection !== 'CONNECTED') { | ||
const checkType = API.sendCheckType(id); | ||
if (!!checkType && checkType.status === 404) { | ||
Object.assign(err, { | ||
text: 'No connection with WhatsApp', | ||
connection: connection, | ||
text: checkType.text, | ||
numberExists: null, | ||
}); | ||
throw err; | ||
} | ||
} | ||
|
||
const lid = await API.getChat(id); | ||
if (lid) { | ||
return await Store.checkNumberMD | ||
.queryExists(lid.id) | ||
.then((result) => { | ||
if (!!result && typeof result === 'object') { | ||
const data = { | ||
status: 200, | ||
numberExists: true, | ||
id: result.wid, | ||
}; | ||
return data; | ||
} | ||
throw Object.assign(err, { | ||
|
||
if (conn === true) { | ||
if (connection !== 'CONNECTED') { | ||
Object.assign(err, { | ||
text: 'No connection with WhatsApp', | ||
connection: connection, | ||
numberExists: false, | ||
text: `The number does not exist`, | ||
numberExists: null, | ||
}); | ||
}) | ||
.catch((err) => { | ||
if (err.text) { | ||
throw err; | ||
} | ||
} | ||
|
||
const chat = await API.checkChatExist(id); | ||
if (chat) { | ||
const data = { | ||
status: 200, | ||
numberExists: true, | ||
id: chat, | ||
erro: false, | ||
checkNumberStatus: false, | ||
}; | ||
return resolve(data); | ||
} | ||
|
||
const lid = await API.getChat(id); | ||
if (lid) { | ||
return await Store.checkNumber | ||
.queryWidExists(lid.id) | ||
.then((result) => { | ||
if (!!result && typeof result === 'object') { | ||
const data = { | ||
status: 200, | ||
numberExists: true, | ||
id: result.wid, | ||
erro: false, | ||
checkNumberStatus: true, | ||
}; | ||
return resolve(data); | ||
} | ||
Object.assign(err, { | ||
connection: connection, | ||
numberExists: false, | ||
text: `The number does not exist`, | ||
}); | ||
throw err; | ||
}) | ||
.catch((err) => { | ||
if (err.text) { | ||
throw err; | ||
} | ||
Object.assign(err, { | ||
connection: connection, | ||
numberExists: false, | ||
text: err, | ||
checkNumberStatus: true, | ||
}); | ||
throw err; | ||
} | ||
throw Object.assign(err, { | ||
connection: connection, | ||
numberExists: false, | ||
text: err, | ||
}); | ||
} else { | ||
Object.assign(err, { | ||
connection: connection, | ||
numberExists: false, | ||
}); | ||
} else { | ||
throw Object.assign(err, { | ||
connection: connection, | ||
numberExists: false, | ||
}); | ||
throw err; | ||
} | ||
} catch (e) { | ||
const scope = { | ||
status: e.error, | ||
text: e.text, | ||
numberExists: e.numberExists, | ||
connection: e.connection, | ||
erro: true, | ||
}; | ||
reject(scope); | ||
} | ||
|
||
} catch (e) { | ||
return { | ||
status: e.error, | ||
text: e.text, | ||
numberExists: e.numberExists, | ||
connection: e.connection, | ||
}; | ||
} | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
|
||
export { getChat } from './get-chat'; | ||
export { scope } from './scope'; | ||
export { getNewId } from './get-mew-id'; | ||
export { getNewMessageId } from './get-new-message'; | ||
export { checkChatExist } from './check-chat-exist'; | ||
|
||
export { sendExist } from './send-exist'; | ||
export { checkNumberStatus } from './check-number-status'; | ||
export { sendCheckType } from './send-check-type'; | ||
|
||
export { checkNumberStatus } from './check-number-status'; | ||
export { isMD } from './is-md'; | ||
export { returnChat } from './return-to-chat'; | ||
export { scope } from './scope'; |
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,70 @@ | ||
|
||
/** | ||
* Function to return to chat or create a new chat | ||
* @param {*} chatId - Chat ID | ||
* @param {*} returnChat - Return Chat | ||
* @param {*} Send - Seen to message | ||
* @returns | ||
*/ | ||
export const returnChat = async (chatId, returnChat = true, Send = true) => { | ||
const checkType = API.sendCheckType(chatId); | ||
if (!!checkType && checkType.status === 404) { | ||
return checkType; | ||
} | ||
|
||
let chat = await window.API.getChat(chatId); | ||
if (!chat) { | ||
var idUser = new Store.UserConstructor(chatId, { | ||
intentionallyUsePrivateConstructor: true, | ||
}); | ||
const chatWid = new Store.WidFactory.createWid(chatId); | ||
await Store.Chat.add( | ||
{ | ||
createdLocally: true, | ||
id: chatWid | ||
}, | ||
{ | ||
merge: true | ||
} | ||
); | ||
chat = await Store.Chat.find(idUser); | ||
} | ||
|
||
if (chat === undefined) { | ||
const chatWid = new Store.WidFactory.createWid(chatId); | ||
await Store.Chat.add( | ||
{ | ||
createdLocally: true, | ||
id: chatWid | ||
}, | ||
{ | ||
merge: true | ||
} | ||
); | ||
const storeChat = await Store.Chat.find(chatId); | ||
if (storeChat) { | ||
chat = | ||
storeChat && storeChat.id && storeChat.id._serialized | ||
? await window.API.getChat(storeChat.id._serialized) | ||
: undefined; | ||
} | ||
} | ||
|
||
if (!chat) { | ||
return API.scope(chatId, true, 404); | ||
} | ||
|
||
if (Send) { | ||
await window.Store.ReadSeen.sendSeen(chat, false); | ||
} | ||
|
||
if (returnChat) { | ||
return chat; | ||
} | ||
|
||
return API.scope( | ||
chatId, | ||
false, | ||
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
Oops, something went wrong.