original_string: 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;
      }
code: 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;
      }
code_tokens: 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 ; }
docstring: Gets the default subscription value for the logged in user.
  
  @param \stdClass $forum The forum record
  @param \context $context The course context
  @param \cm_info $cm cm_info
  @param int|null $discussionid The discussion we are checking against
  @return bool Default subscription
  @throws coding_exception
docstring_tokens: Gets the default subscription value for the logged in user .