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:
Kang 2024-09-20 16:29:08 +08:00 • committed by GitHub
commit 0fa6ebb66d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;