MDL-65665 forum: WS does not respect subscribe on reply user preference
authorMihail Geshoski <mihail@moodle.com>
Mon, 10 Jun 2019 09:14:45 +0000 (17:14 +0800)
committerMihail Geshoski <mihail@moodle.com>
Fri, 14 Jun 2019 00:44:28 +0000 (08:44 +0800)
mod/forum/externallib.php

index 37f09d7..5a6fb60 100644 (file)
@@ -1257,9 +1257,13 @@ class mod_forum_external extends external_api {
         $context = context_module::instance($cm->id);
         self::validate_context($context);
 
+        $coursecontext = \context_course::instance($forum->get_course_id());
+        $discussionsubscribe = \mod_forum\subscriptions::get_user_default_subscription($forumrecord, $coursecontext,
+            $cm, null);
+
         // Validate options.
         $options = array(
-            'discussionsubscribe' => true,
+            'discussionsubscribe' => $discussionsubscribe,
             'private'             => false,
             'inlineattachmentsid' => 0,
             'attachmentsid' => null,
@@ -1350,9 +1354,11 @@ class mod_forum_external extends external_api {
                 $completion->update_state($cm, COMPLETION_COMPLETE);
             }
 
-            $settings = new stdClass();
-            $settings->discussionsubscribe = $options['discussionsubscribe'];
-            forum_post_subscription($settings, $forumrecord, $discussionrecord);
+            if ($options['discussionsubscribe']) {
+                $settings = new stdClass();
+                $settings->discussionsubscribe = $options['discussionsubscribe'];
+                forum_post_subscription($settings, $forumrecord, $discussionrecord);
+            }
         } else {
             throw new moodle_exception('couldnotadd', 'forum');
         }