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.removeParticipants(chat, participants);
            return { status: 200 };
        }, this.id._serialized, participantIds);
    }

    /**
     * Promotes participants by IDs to admins
     * @param {Array<string>} participantIds 
     * @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
     */
    async promoteParticipants(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.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);
    }

    /**

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.removeParticipants(chat, participants);
            return { status: 200 };
        }, this.id._serialized, participantIds);
    }

    /**
     * Promotes participants by IDs to admins
     * @param {Array<string>} participantIds 
     * @returns {Promise<{ status: number }>} Object with status code indicating if the operation was successful
     */
    async promoteParticipants(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.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);
    }

    /**