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

Code before:
    /**
     * Mutes this chat forever, unless a date is specified
     * @param {?Date} unmuteDate Date at which the Chat will be unmuted, leave as is to mute forever
     */
    async mute(unmuteDate) {
        return this.client.muteChat(this.id._serialized, unmuteDate);
    }

    /**
     * Unmutes this chat
     */
    async unmute() {
        return this.client.unmuteChat(this.id._serialized);
    }

    /**
     * Mark this chat as unread
     */
    async markUnread(){
        return this.client.markChatUnread(this.id._serialized);
    }

    /**
     * Loads chat messages, sorted from earliest to latest.
     * @param {Object} searchOptions Options for searching messages. Right now only limit is supported.
     * @param {Number} [searchOptions.limit] The amount of messages to return. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.
     * @returns {Promise<Array<Message>>}
     */
    async fetchMessages(searchOptions) {
        let messages = await this.client.pupPage.evaluate(async (chatId, searchOptions) => {
            const msgFilter = m => !m.isNotification; // dont include notification messages

            const chat = window.Store.Chat.get(chatId);
            let msgs = chat.msgs.models.filter(msgFilter);

            if (searchOptions && searchOptions.limit) {
                while (msgs.length < searchOptions.limit) {
                    const loadedMessages = await chat.loadEarlierMsgs();
                    if (!loadedMessages) break;
                    msgs = [...loadedMessages.filter(msgFilter), ...msgs];
                }
                if (msgs.length > searchOptions.limit)
                    msgs = msgs.splice(msgs.length - searchOptions.limit);
            }

            msgs.sort((a, b) => (a.t > b.t) ? 1 : -1);
            return msgs.map(m => window.WWebJS.getMessageModel(m));

        }, this.id._serialized, searchOptions);

        return messages.map(m => new Message(this.client, m));

Review comment (suggestion):
```suggestion
     * @param {Number} [searchOptions.limit] The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.
```

Code after:
    /**
     * Mutes this chat forever, unless a date is specified
     * @param {?Date} unmuteDate Date at which the Chat will be unmuted, leave as is to mute forever
     */
    async mute(unmuteDate) {
        return this.client.muteChat(this.id._serialized, unmuteDate);
    }

    /**
     * Unmutes this chat
     */
    async unmute() {
        return this.client.unmuteChat(this.id._serialized);
    }

    /**
     * Mark this chat as unread
     */
    async markUnread(){
        return this.client.markChatUnread(this.id._serialized);
    }

    /**
     * Loads chat messages, sorted from earliest to latest.
     * @param {Object} searchOptions Options for searching messages. Right now only limit is supported.
     * @param {Number} [searchOptions.limit] The amount of messages to return. If no limit is specified, the available messages will be returned. Note that the actual number of returned messages may be smaller if there aren't enough messages in the conversation. Set this to Infinity to load all messages.
     * @returns {Promise<Array<Message>>}
     */
    async fetchMessages(searchOptions) {
        let messages = await this.client.pupPage.evaluate(async (chatId, searchOptions) => {
            const msgFilter = m => !m.isNotification; // dont include notification messages

            const chat = window.Store.Chat.get(chatId);
            let msgs = chat.msgs.models.filter(msgFilter);

            if (searchOptions && searchOptions.limit) {
                while (msgs.length < searchOptions.limit) {
                    const loadedMessages = await chat.loadEarlierMsgs();
                    if (!loadedMessages) break;
                    msgs = [...loadedMessages.filter(msgFilter), ...msgs];
                }
                if (msgs.length > searchOptions.limit)
                    msgs = msgs.splice(msgs.length - searchOptions.limit);
            }

            msgs.sort((a, b) => (a.t > b.t) ? 1 : -1);
            return msgs.map(m => window.WWebJS.getMessageModel(m));

        }, this.id._serialized, searchOptions);

        return messages.map(m => new Message(this.client, m));