Repository: pedroslopez/whatsapp-web.js
File: src/Client.js (JavaScript)

Code before:

    /**
     * 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;
    }

    /**
     * Sync history conversation
     * @param {string} chatId
     * @return {boolean} true/false
     */
    async syncHistory(chatId) {
        return await this.pupPage.evaluate(async (chatId) => {
            const chat = await window.WWebJS.getChat(chatId);
            if (chat.endOfHistoryTransferType == window.Store.HistoryStates.COMPLETE_BUT_MORE_MESSAGES_REMAIN_ON_PRIMARY) {
                window.Store.HistorySync.sendPeerDataOperationRequest(window.require("WAWebProtobufsE2E.pb").Message$PeerDataOperationRequestType.HISTORY_SYNC_ON_DEMAND, {
                    chatId: chat.id
                });
                return true;
            }
            return false;
        }, chatId);
    }
}

module.exports = Client;

Review comment (refactor):
Also we can simplify here, since properties of the object `window.require("WAWebProtobufsE2E.pb").Message$PeerDataOperationRequestType` are:
```js
{
  UPLOAD_STICKER: 0,
  SEND_RECENT_STICKER_BOOTSTRAP: 1,
  GENERATE_LINK_PREVIEW: 2,
  HISTORY_SYNC_ON_DEMAND: 3,
  PLACEHOLDER_MESSAGE_RESEND: 4,
  WAFFLE_LINKING_NONCE_FETCH: 5,
  FULL_HISTORY_SYNC_ON_DEMAND: 6
}
```

```suggestion
                window.Store.HistorySync.sendPeerDataOperationRequest(3, {
```

Code after:

    /**
     * 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;
    }

    /**
     * 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;