public static function get_group_members_in_context(userlist $userlist, string $component, int $itemid = 0) {
        $context = $userlist->get_context();

        if (!$context instanceof \context_course) {
            return;
        }

        // Group members in the given context.
        $sql = "SELECT gm.userid
                  FROM {groups_members} gm
                  JOIN {groups} g ON gm.groupid = g.id
                 WHERE g.courseid = :courseid AND gm.component = :component";
        $params = [
            'courseid'      => $context->instanceid,
            'component'     => $component
        ];

        if ($itemid) {
            $sql .= ' AND gm.itemid = :itemid';
            $params['itemid'] = $itemid;
        }

        $userlist->add_from_sql('userid', $sql, $params);

        // Get the users with some group conversation in this context.
        \core_message\privacy\provider::add_conversations_in_context($userlist, 'core_group', 'groups', $itemid);
    }