diff --git a/src/api/layers/controls.layer.ts b/src/api/layers/controls.layer.ts index 4a87e65a2..2755985f5 100644 --- a/src/api/layers/controls.layer.ts +++ b/src/api/layers/controls.layer.ts @@ -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); + } + }); } /** diff --git a/src/api/layers/sender.layer.ts b/src/api/layers/sender.layer.ts index a6d35af89..9a1d77cc6 100644 --- a/src/api/layers/sender.layer.ts +++ b/src/api/layers/sender.layer.ts @@ -1031,7 +1031,33 @@ export class SenderLayer extends ListenerLayer { * @param chatId chat id: xxxxx@us.c */ 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); + } + }); } /** diff --git a/src/lib/wapi/functions/mark-unseen-message.js b/src/lib/wapi/functions/mark-unseen-message.js index 9e7a4b157..348f67e07 100644 --- a/src/lib/wapi/functions/mark-unseen-message.js +++ b/src/lib/wapi/functions/mark-unseen-message.js @@ -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; diff --git a/src/lib/wapi/functions/send-seen.js b/src/lib/wapi/functions/send-seen.js index 09d98f76e..7d9c94c34 100644 --- a/src/lib/wapi/functions/send-seen.js +++ b/src/lib/wapi/functions/send-seen.js @@ -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; }