Sync history conversation of the Chat (#3281)
* Sync historical message * Add documentation * Code simplify * feat: add syncHistory method in Chat class * docs: update docs * chore: update examples * fix: handle asynchronous function properly * refactor: include await --------- Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
This commit is contained in:
parent
e7265a34b9
commit
0fa6ebb66d
5 changed files with 42 additions and 3 deletions
|
|
@ -1739,6 +1739,24 @@ class Client extends EventEmitter {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync chat history conversation
|
||||
* @param {string} chatId
|
||||
* @return {Promise<boolean>} True if operation completed successfully, false otherwise.
|
||||
*/
|
||||
async syncHistory(chatId) {
|
||||
return await this.pupPage.evaluate(async (chatId) => {
|
||||
const chat = await window.WWebJS.getChat(chatId);
|
||||
if (chat.endOfHistoryTransferType === 0) {
|
||||
await window.Store.HistorySync.sendPeerDataOperationRequest(3, {
|
||||
chatId: chat.id
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, chatId);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Client;
|
||||
module.exports = Client;
|
||||
|
|
|
|||
|
|
@ -270,6 +270,14 @@ class Chat extends Base {
|
|||
async changeLabels(labelIds) {
|
||||
return this.client.addOrRemoveLabels(labelIds, [this.id._serialized]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync chat history conversation
|
||||
* @return {Promise<boolean>} True if operation completed successfully, false otherwise.
|
||||
*/
|
||||
async syncHistory() {
|
||||
return this.client.syncHistory(this.id._serialized);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Chat;
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ exports.ExposeStore = () => {
|
|||
window.Store.BotSecret = window.require('WAWebBotMessageSecret');
|
||||
window.Store.BotProfiles = window.require('WAWebBotProfileCollection');
|
||||
window.Store.DeviceList = window.require('WAWebApiDeviceList');
|
||||
window.Store.HistorySync = window.require('WAWebSendNonMessageDataRequest');
|
||||
if (window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.1014111620'))
|
||||
window.Store.AddonReactionTable = window.require('WAWebAddonReactionTableMode').reactionTableMode;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue