diff --git a/index.d.ts b/index.d.ts index 1cd43a5..a06a66d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -981,7 +981,7 @@ declare namespace WAWebJS { * The custom message secret, can be used as a poll ID * @note It has to be a unique vector with a length of 32 */ - messageSecret: ?Array + messageSecret: Array|undefined } /** Represents a Poll on WhatsApp */ @@ -1341,7 +1341,7 @@ declare namespace WAWebJS { code: number; message: string; isInviteV4Sent: boolean, - }; + } }; /** An object that handles options for adding participants */ @@ -1410,7 +1410,7 @@ declare namespace WAWebJS { /** Group participants */ participants: Array; /** Adds a list of participants by ID to the group */ - addParticipants: (participantIds: string|string[], options?: AddParticipantsOptions) => Promise|string>; + addParticipants: (participantIds: string | string[], options?: AddParticipantsOptions) => Promise<{ [key: string]: AddParticipantsResult } | string>; /** Removes a list of participants by ID to the group */ removeParticipants: (participantIds: string[]) => Promise<{ status: number }>; /** Promotes participants by IDs to admins */ diff --git a/src/structures/Message.js b/src/structures/Message.js index 5886b82..d21be77 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -534,15 +534,20 @@ class Message extends Base { */ /** - * Get information about message delivery status. May return null if the message does not exist or is not sent by you. + * Get information about message delivery status. + * May return null if the message does not exist or is not sent by you. * @returns {Promise} */ async getInfo() { const info = await this.client.pupPage.evaluate(async (msgId) => { const msg = window.Store.Msg.get(msgId); - if (!msg) return null; + if (!msg || !msg.id.fromMe) return null; - return await window.Store.MessageInfo.sendQueryMsgInfo(msg.id); + return new Promise((resolve) => { + setTimeout(async () => { + resolve(await window.Store.getMsgInfo(msg.id)); + }, (Date.now() - msg.t * 1000 < 1250) && Math.floor(Math.random() * (1200 - 1100 + 1)) + 1100 || 0); + }); }, this.id._serialized); return info; diff --git a/src/util/Injected.js b/src/util/Injected.js index 641a0e7..7109f7d 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -23,7 +23,6 @@ exports.ExposeStore = (moduleRaidStr) => { window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0]; window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0]; window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default; - window.Store.MessageInfo = window.mR.findModule('sendQueryMsgInfo')[0]; window.Store.OpaqueData = window.mR.findModule(module => module.default && module.default.createFromData)[0].default; window.Store.QueryProduct = window.mR.findModule('queryProduct')[0]; window.Store.QueryOrder = window.mR.findModule('queryOrder')[0]; @@ -58,16 +57,17 @@ 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); window.Store.ReplyUtils = (m = window.mR.findModule('canReplyMsg')).length > 0 && m[0]; + window.Store.getMsgInfo = m = window.mR.findModule('sendQueryMsgInfo')[0] ? m.sendQueryMsgInfo : window.mR.findModule('queryMsgInfo')[0].queryMsgInfo; /* eslint-enable no-undef, no-cond-assign */ + window.Store.Settings = { + ...window.mR.findModule('ChatlistPanelState')[0], + setPushname: window.mR.findModule((m) => m.setPushname && !m.ChatlistPanelState)[0].setPushname + }; window.Store.StickerTools = { ...window.mR.findModule('toWebpSticker')[0], ...window.mR.findModule('addWebpMetadata')[0] @@ -128,9 +128,9 @@ exports.ExposeStore = (moduleRaidStr) => { /** * Target options object description * @typedef {Object} TargetOptions - * @property {string|number} moduleId The name or a key of the target module to search + * @property {string|number} module The name or a key of the target module to search * @property {number} index The index value of the target module - * @property {string} property The function name to get from a module + * @property {string} function The function name to get from a module */ /** @@ -139,17 +139,17 @@ exports.ExposeStore = (moduleRaidStr) => { * @param {Function} callback Modified function */ window.injectToFunction = (target, callback) => { - const module = typeof target.moduleId === 'string' - ? window.mR.findModule(target.moduleId) - : window.mR.modules[target.moduleId]; - const originalFunction = module[target.index][target.property]; + const module = typeof target.module === 'string' + ? window.mR.findModule(target.module) + : window.mR.modules[target.module]; + const originalFunction = module[target.index][target.function]; const modifiedFunction = (...args) => callback(originalFunction, ...args); - module[target.index][target.property] = modifiedFunction; + module[target.index][target.function] = modifiedFunction; }; - window.injectToFunction({ moduleId: 'mediaTypeFromProtobuf', index: 0, property: 'mediaTypeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage ? null : func(...args); }); + window.injectToFunction({ module: 'mediaTypeFromProtobuf', index: 0, function: 'mediaTypeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage ? null : func(...args); }); - window.injectToFunction({ moduleId: 'typeAttributeFromProtobuf', index: 0, property: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); }); + window.injectToFunction({ module: 'typeAttributeFromProtobuf', index: 0, function: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); }); }; exports.LoadUtils = () => {