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

Code before:
            const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
            const participants = participantIds.map(p => {
                const wid = window.Store.WidFactory.createWid(p);
                const lid = wid.server!=='lid' ? window.Store.LidUtils.getCurrentLid(wid) : wid;
                const phone = wid.server=='lid' ? window.Store.LidUtils.getPhoneNumber(wid) : wid;
                return (chat.groupMetadata.participants.get(lid._serialized) || chat.groupMetadata.participants.get(phone._serialized));
            });
            await window.Store.GroupParticipants.promoteParticipants(chat, participants);
            return { status: 200 };
        }, this.id._serialized, participantIds);
    }

    /**
     * Demotes participants by IDs to regular users
     * @param {Array<string>} participantIds 
     * @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
     */
    async demoteParticipants(participantIds) {
        return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
            const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
            const participants = participantIds.map(p => {
                const wid = window.Store.WidFactory.createWid(p);
                const lid = wid.server!=='lid' ? window.Store.LidUtils.getCurrentLid(wid) : wid;
                const phone = wid.server=='lid' ? window.Store.LidUtils.getPhoneNumber(wid) : wid;
                return (chat.groupMetadata.participants.get(lid._serialized) || chat.groupMetadata.participants.get(phone._serialized));
            });
            await window.Store.GroupParticipants.demoteParticipants(chat, participants);
            return { status: 200 };
        }, this.id._serialized, participantIds);
    }

    /**
     * Updates the group subject
     * @param {string} subject 
     * @returns {Promise<boolean>} Returns true if the subject was properly updated. This can return false if the user does not have the necessary permissions.
     */
    async setSubject(subject) {
        const success = await this.client.pupPage.evaluate(async (chatId, subject) => {
            const chatWid = window.Store.WidFactory.createWid(chatId);
            try {
                await window.Store.GroupUtils.setGroupSubject(chatWid, subject);
                return true;
            } catch (err) {
                if(err.name === 'ServerStatusCodeError') return false;
                throw err;
            }
        }, this.id._serialized, subject);

        if(!success) return false;
        this.name = subject;
        return true;

Review comment (suggestion):
```suggestion
                return chat.groupMetadata.participants.get(lid?._serialized) || chat.groupMetadata.participants.get(phone?._serialized);
            }).filter(p => Boolean(p));
```

Code after:
            const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
            const participants = participantIds.map(p => {
                const wid = window.Store.WidFactory.createWid(p);
                const lid = wid.server!=='lid' ? window.Store.LidUtils.getCurrentLid(wid) : wid;
                const phone = wid.server=='lid' ? window.Store.LidUtils.getPhoneNumber(wid) : wid;
                return chat.groupMetadata.participants.get(lid?._serialized) || chat.groupMetadata.participants.get(phone?._serialized);
            }).filter(p => Boolean(p));
            await window.Store.GroupParticipants.promoteParticipants(chat, participants);
            return { status: 200 };
        }, this.id._serialized, participantIds);
    }

    /**
     * Demotes participants by IDs to regular users
     * @param {Array<string>} participantIds 
     * @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
     */
    async demoteParticipants(participantIds) {
        return await this.client.pupPage.evaluate(async (chatId, participantIds) => {
            const chat = await window.WWebJS.getChat(chatId, { getAsModel: false });
            const participants = participantIds.map(p => {
                const wid = window.Store.WidFactory.createWid(p);
                const lid = wid.server!=='lid' ? window.Store.LidUtils.getCurrentLid(wid) : wid;
                const phone = wid.server=='lid' ? window.Store.LidUtils.getPhoneNumber(wid) : wid;
                return chat.groupMetadata.participants.get(lid?._serialized) || chat.groupMetadata.participants.get(phone?._serialized);
            }).filter(p => Boolean(p));
            await window.Store.GroupParticipants.demoteParticipants(chat, participants);
            return { status: 200 };
        }, this.id._serialized, participantIds);
    }

    /**
     * Updates the group subject
     * @param {string} subject 
     * @returns {Promise<boolean>} Returns true if the subject was properly updated. This can return false if the user does not have the necessary permissions.
     */
    async setSubject(subject) {
        const success = await this.client.pupPage.evaluate(async (chatId, subject) => {
            const chatWid = window.Store.WidFactory.createWid(chatId);
            try {
                await window.Store.GroupUtils.setGroupSubject(chatWid, subject);
                return true;
            } catch (err) {
                if(err.name === 'ServerStatusCodeError') return false;
                throw err;
            }
        }, this.id._serialized, subject);

        if(!success) return false;
        this.name = subject;
        return true;