Count user connected devices (#3223)
* Update Store.js * All * Make Eslist god happy --------- Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com> Co-authored-by: Shir Serlui <70711723+shirser121@users.noreply.github.com>
This commit is contained in:
parent
8fdf2b840e
commit
d2597bba72
4 changed files with 35 additions and 3 deletions
|
|
@ -450,6 +450,14 @@ client.on('message', async msg => {
|
||||||
*/
|
*/
|
||||||
const result = await msg.pin(60); // Will pin a message for 1 minute
|
const result = await msg.pin(60); // Will pin a message for 1 minute
|
||||||
console.log(result); // True if the operation completed successfully, false otherwise
|
console.log(result); // True if the operation completed successfully, false otherwise
|
||||||
|
}else if (msg.body === '!howManyConnections'){
|
||||||
|
/**
|
||||||
|
* Get user device count by ID
|
||||||
|
* Each WaWeb Connection counts as one device, and the phone (if exists) counts as one
|
||||||
|
* So for a non-enterprise user with one WaWeb connection it should return "2"
|
||||||
|
*/
|
||||||
|
let deviceCount = await client.getContactDeviceCount(msg.from);
|
||||||
|
await msg.reply(`You have *${deviceCount}* devices connected`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
8
index.d.ts
vendored
8
index.d.ts
vendored
|
|
@ -177,6 +177,14 @@ declare namespace WAWebJS {
|
||||||
*/
|
*/
|
||||||
setAutoDownloadVideos(flag: boolean): Promise<void>
|
setAutoDownloadVideos(flag: boolean): Promise<void>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user device count by ID
|
||||||
|
* Each WaWeb Connection counts as one device, and the phone (if exists) counts as one
|
||||||
|
* So for a non-enterprise user with one WaWeb connection it should return "2"
|
||||||
|
* @param {string} contactId
|
||||||
|
*/
|
||||||
|
getContactDeviceCount(contactId: string): Promise<Number>
|
||||||
|
|
||||||
/** Changes and returns the archive state of the Chat */
|
/** Changes and returns the archive state of the Chat */
|
||||||
unarchiveChat(chatId: string): Promise<boolean>
|
unarchiveChat(chatId: string): Promise<boolean>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1617,8 +1617,8 @@ class Client extends EventEmitter {
|
||||||
* @returns {Promise<Array<GroupMembershipRequest>>} An array of membership requests
|
* @returns {Promise<Array<GroupMembershipRequest>>} An array of membership requests
|
||||||
*/
|
*/
|
||||||
async getGroupMembershipRequests(groupId) {
|
async getGroupMembershipRequests(groupId) {
|
||||||
return await this.pupPage.evaluate(async (gropId) => {
|
return await this.pupPage.evaluate(async (groupId) => {
|
||||||
const groupWid = window.Store.WidFactory.createWid(gropId);
|
const groupWid = window.Store.WidFactory.createWid(groupId);
|
||||||
return await window.Store.MembershipRequestUtils.getMembershipApprovalRequests(groupWid);
|
return await window.Store.MembershipRequestUtils.getMembershipApprovalRequests(groupWid);
|
||||||
}, groupId);
|
}, groupId);
|
||||||
}
|
}
|
||||||
|
|
@ -1724,6 +1724,21 @@ class Client extends EventEmitter {
|
||||||
return flag;
|
return flag;
|
||||||
}, flag);
|
}, flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get user device count by ID
|
||||||
|
* Each WaWeb Connection counts as one device, and the phone (if exists) counts as one
|
||||||
|
* So for a non-enterprise user with one WaWeb connection it should return "2"
|
||||||
|
* @param {string} contactId
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
async getContactDeviceCount(contactId) {
|
||||||
|
let devices = await window.Store.DeviceList.getDeviceIds([window.Store.WidFactory.createWid(contactId)]);
|
||||||
|
if(devices && devices.length && devices[0] != null && typeof devices[0].devices == 'object'){
|
||||||
|
return devices[0].devices.length;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Client;
|
module.exports = Client;
|
||||||
|
|
@ -97,6 +97,7 @@ exports.ExposeStore = () => {
|
||||||
window.Store.Settings = window.require('WAWebUserPrefsGeneral');
|
window.Store.Settings = window.require('WAWebUserPrefsGeneral');
|
||||||
window.Store.BotSecret = window.require('WAWebBotMessageSecret');
|
window.Store.BotSecret = window.require('WAWebBotMessageSecret');
|
||||||
window.Store.BotProfiles = window.require('WAWebBotProfileCollection');
|
window.Store.BotProfiles = window.require('WAWebBotProfileCollection');
|
||||||
|
window.Store.DeviceList = window.require('WAWebApiDeviceList');
|
||||||
if (window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.1014111620'))
|
if (window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.1014111620'))
|
||||||
window.Store.AddonReactionTable = window.require('WAWebAddonReactionTableMode').reactionTableMode;
|
window.Store.AddonReactionTable = window.require('WAWebAddonReactionTableMode').reactionTableMode;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue