From 9f4eeef3bfd8fffe61897d0c9051e1aa4bbe8241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Souza?= Date: Fri, 6 Nov 2020 15:04:11 -0300 Subject: [PATCH] feat: new function to change group permission --- src/api/layers/controls.layer.ts | 14 ++++++++++++++ src/lib/wapi/functions/send-sticker.js | 5 +++-- src/lib/wapi/wapi.js | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/api/layers/controls.layer.ts b/src/api/layers/controls.layer.ts index 4559686f3..56b6acc2a 100644 --- a/src/api/layers/controls.layer.ts +++ b/src/api/layers/controls.layer.ts @@ -72,6 +72,7 @@ declare module WAPI { const markUnseenMessage: (messageId: string) => boolean; const blockContact: (messageId: string) => boolean; const unblockContact: (messageId: string) => boolean; + const setMessagesAdminsOnly: (chatId: string, option: boolean) => boolean; } export class ControlsLayer extends UILayer { @@ -189,4 +190,17 @@ export class ControlsLayer extends UILayer { { contactId: chatId, messageId, onlyLocal } ); } + + /** + * Archive and unarchive chat messages with true or false + * @param chatId {string} id '000000000000@c.us' + * @param option {boolean} true or false + * @returns boolean + */ + public async setMessagesAdminsOnly(chatId: string, option: boolean) { + return this.page.evaluate( + ({ chatId, option }) => WAPI.setMessagesAdminsOnly(chatId, option), + { chatId, option } + ); + } } diff --git a/src/lib/wapi/functions/send-sticker.js b/src/lib/wapi/functions/send-sticker.js index bd8e52be1..c908380f9 100644 --- a/src/lib/wapi/functions/send-sticker.js +++ b/src/lib/wapi/functions/send-sticker.js @@ -82,13 +82,14 @@ export async function sendSticker(sticker, chatId, metadata, type) { ); result = result.join(''); var m = { type: type }, + obj, To = await WAPI.getchatId(chatId); if (result === 'OK') { - var obj = WAPI.scope(To, false, result, null); + obj = WAPI.scope(To, false, result, null); Object.assign(obj, m); return obj; } else { - var obj = WAPI.scope(To, true, result, null); + obj = WAPI.scope(To, true, result, null); Object.assign(obj, m); return obj; } diff --git a/src/lib/wapi/wapi.js b/src/lib/wapi/wapi.js index d0b8884d2..ad1a159bb 100644 --- a/src/lib/wapi/wapi.js +++ b/src/lib/wapi/wapi.js @@ -497,3 +497,8 @@ window.WAPI.onIncomingCall = function (callback) { window.Store.Call.on('add', callback); return true; }; + +window.WAPI.setMessagesAdminsOnly = async function (chatId, option) { + await Store.WapQuery.setGroupProperty(chatId, 'announcement', option); + return true; +};