private function get_read_receipts_from_posts(stdClass $user, array $groupedposts) {
        $forumdatamapper = $this->legacydatamapperfactory->get_forum_data_mapper();
        $trackedforums = [];
        $trackedpostids = [];

        foreach ($groupedposts as $group) {
            ['forum' => $forum, 'posts' => $posts] = $group;
            $forumid = $forum->get_id();

            if (!isset($trackedforums[$forumid])) {
                $forumrecord = $forumdatamapper->to_legacy_object($forum);
                $trackedforums[$forumid] = forum_tp_is_tracked($forumrecord, $user);
            }

            if ($trackedforums[$forumid]) {
                foreach ($posts as $post) {
                    $trackedpostids[] = $post->get_id();
                }
            }
        }

        if (empty($trackedpostids)) {
            return [];
        }

        // We can just load a single receipt collection for all tracked posts.
        $receiptvault = $this->vaultfactory->get_post_read_receipt_collection_vault();
        $readreceiptcollection = $receiptvault->get_from_user_id_and_post_ids($user->id, $trackedpostids);
        $receiptsbyforumid = [];

        // Assign the collection to all forums that are tracked.
        foreach ($trackedforums as $forumid => $tracked) {
            if ($tracked) {
                $receiptsbyforumid[$forumid] = $readreceiptcollection;
            }
        }

        return $receiptsbyforumid;
    }