diff --git a/index.d.ts b/index.d.ts index 38014be..1cd43a5 100644 --- a/index.d.ts +++ b/index.d.ts @@ -143,6 +143,27 @@ declare namespace WAWebJS { * @param displayName New display name */ setDisplayName(displayName: string): Promise + + /** + * Changes the autoload Audio + * @param flag true/false on or off + */ + setAutoDownloadAudio(flag: boolean): Promise + /** + * Changes the autoload Documents + * @param flag true/false on or off + */ + setAutoDownloadDocuments(flag: boolean): Promise + /** + * Changes the autoload Photos + * @param flag true/false on or off + */ + setAutoDownloadPhotos(flag: boolean): Promise + /** + * Changes the autoload Videos + * @param flag true/false on or off + */ + setAutoDownloadVideos(flag: boolean): Promise /** Changes and returns the archive state of the Chat */ unarchiveChat(chatId: string): Promise diff --git a/src/Client.js b/src/Client.js index d4f5ffd..475067d 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1047,8 +1047,8 @@ class Client extends EventEmitter { if(!window.Store.Conn.canSetMyPushname()) return false; if(window.Store.MDBackend) { - // TODO - return false; + await window.Store.Settings.setPushname(displayName); + return true; } else { const res = await window.Store.Wap.setPushname(displayName); return !res.status || res.status === 200; @@ -1597,6 +1597,67 @@ class Client extends EventEmitter { return await window.WWebJS.membershipRequestAction(groupId, 'Reject', requesterIds, sleep); }, groupId, options); } + + + /** + * Setting autoload download audio + * @param {boolean} flag true/false + */ + async setAutoDownloadAudio(flag) { + await this.pupPage.evaluate(async flag => { + const autoDownload = window.Store.Settings.getAutoDownloadAudio(); + if (autoDownload === flag) { + return flag; + } + await window.Store.Settings.setAutoDownloadAudio(flag); + return flag; + }, flag); + } + + /** + * Setting autoload download documents + * @param {boolean} flag true/false + */ + async setAutoDownloadDocuments(flag) { + await this.pupPage.evaluate(async flag => { + const autoDownload = window.Store.Settings.getAutoDownloadDocuments(); + if (autoDownload === flag) { + return flag; + } + await window.Store.Settings.setAutoDownloadDocuments(flag); + return flag; + }, flag); + } + + /** + * Setting autoload download photos + * @param {boolean} flag true/false + */ + async setAutoDownloadPhotos(flag) { + await this.pupPage.evaluate(async flag => { + const autoDownload = window.Store.Settings.getAutoDownloadPhotos(); + if (autoDownload === flag) { + return flag; + } + await window.Store.Settings.setAutoDownloadPhotos(flag); + return flag; + }, flag); + } + + /** + * Setting autoload download videos + * @param {boolean} flag true/false + */ + async setAutoDownloadVideos(flag) { + await this.pupPage.evaluate(async flag => { + const autoDownload = window.Store.Settings.getAutoDownloadVideos(); + if (autoDownload === flag) { + return flag; + } + await window.Store.Settings.setAutoDownloadVideos(flag); + return flag; + }, flag); + } } module.exports = Client; diff --git a/src/util/Injected.js b/src/util/Injected.js index b71f0b7..641a0e7 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -58,6 +58,10 @@ exports.ExposeStore = (moduleRaidStr) => { window.Store.LidUtils = window.mR.findModule('getCurrentLid')[0]; window.Store.WidToJid = window.mR.findModule('widToUserJid')[0]; window.Store.JidToWid = window.mR.findModule('userJidToUserWid')[0]; + window.Store.Settings = { + ...window.mR.findModule('ChatlistPanelState')[0], + setPushname: window.mR.findModule((m) => m.setPushname && !m.ChatlistPanelState)[0].setPushname + }; /* eslint-disable no-undef, no-cond-assign */ window.Store.QueryExist = ((m = window.mR.findModule('queryExists')[0]) ? m.queryExists : window.mR.findModule('queryExist')[0].queryWidExists);