public static function get_user_default_subscription($forum, $context, $cm, ?int $discussionid) {
        global $USER;
        $manageactivities = has_capability('moodle/course:manageactivities', $context);
        if (\mod_forum\subscriptions::subscription_disabled($forum) && !$manageactivities) {
            // User does not have permission to subscribe to this discussion at all.
            $discussionsubscribe = false;
        } else if (\mod_forum\subscriptions::is_forcesubscribed($forum)) {
            // User does not have permission to unsubscribe from this discussion at all.
            $discussionsubscribe = true;
        } else {
            if (isset($discussion) && \mod_forum\subscriptions::is_subscribed($USER->id, $forum, $discussionid, $cm)) {
                // User is subscribed to the discussion - continue the subscription.
                $discussionsubscribe = true;
            } else if (!isset($discussionid) && \mod_forum\subscriptions::is_subscribed($USER->id, $forum, null, $cm)) {
                // Starting a new discussion, and the user is subscribed to the forum - subscribe to the discussion.
                $discussionsubscribe = true;
            } else {
                // User is not subscribed to either forum or discussion. Follow user preference.
                $discussionsubscribe = $USER->autosubscribe ?? false;
            }
        }

        return $discussionsubscribe;
    }