Skip to content

Commit

Permalink
feat: mew
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Jul 9, 2021
1 parent 4aeef14 commit 06915eb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 18 deletions.
32 changes: 28 additions & 4 deletions src/api/layers/controls.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,34 @@ export class ControlsLayer extends UILayer {
* @returns boolean
*/
public async markUnseenMessage(contactId: string) {
return this.page.evaluate(
(contactId: string) => WAPI.markUnseenMessage(contactId),
contactId
);
return new Promise(async (resolve, reject) => {
const typeFunction = 'markUnseenMessage';
const type = 'string';
const check = [
{
param: 'contactId',
type: type,
value: contactId,
function: typeFunction,
isUser: true,
},
];

const validating = checkValuesSender(check);
if (typeof validating === 'object') {
return reject(validating);
}
const result = await this.page.evaluate(
(contactId: string) => WAPI.markUnseenMessage(contactId),
contactId
);

if (result['erro'] == true) {
return reject(result);
} else {
return resolve(result);
}
});
}

/**
Expand Down
28 changes: 27 additions & 1 deletion src/api/layers/sender.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,33 @@ export class SenderLayer extends ListenerLayer {
* @param chatId chat id: [email protected]
*/
public async sendSeen(chatId: string) {
return this.page.evaluate((chatId) => WAPI.sendSeen(chatId), chatId);
return new Promise(async (resolve, reject) => {
const typeFunction = 'markUnseenMessage';
const type = 'string';
const check = [
{
param: 'chatId',
type: type,
value: chatId,
function: typeFunction,
isUser: true,
},
];
const validating = checkValuesSender(check);
if (typeof validating === 'object') {
return reject(validating);
}
const result = await this.page.evaluate(
(chatId) => WAPI.sendSeen(chatId),
chatId
);

if (result['erro'] == true) {
return reject(result);
} else {
return resolve(result);
}
});
}

/**
Expand Down
15 changes: 9 additions & 6 deletions src/lib/wapi/functions/mark-unseen-message.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
export async function markUnseenMessage(id) {
if (!id) {
return false;
}
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
await Store.ReadSeen.markUnread(chat, true);
const chat = await WAPI.sendExist(id);
if (!chat.erro) {
await Store.ReadSeen.markUnread(chat, true)
.then(() => {
return WAPI.scope(undefined, false, 'OK', null);
})
.catch(() => {
return WAPI.scope(undefined, true, 'Error', null);
});
return true;
} else {
return false;
Expand Down
18 changes: 11 additions & 7 deletions src/lib/wapi/functions/send-seen.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
export async function sendSeen(id, done) {
if (!id) return false;
var chat = window.WAPI.getChat(id);
if (chat !== undefined) {
await Store.ReadSeen.sendSeen(chat, false);
done && done(true);
const chat = await WAPI.sendExist(id);
if (!chat.erro) {
await Store.ReadSeen.markUnread(chat, false)
.then(() => {
return WAPI.scope(undefined, false, 'OK', null);
})
.catch(() => {
return WAPI.scope(undefined, true, 'Error', null);
});
return true;
} else {
return false;
}
done && done(false);
return false;
}

0 comments on commit 06915eb

Please sign in to comment.