MDL-65786 mod_forum: mark posts as read when they are read
authorShamim Rezaie <shamim@moodle.com>
Thu, 13 Jun 2019 09:48:43 +0000 (19:48 +1000)
committerShamim Rezaie <shamim@moodle.com>
Thu, 13 Jun 2019 13:33:35 +0000 (23:33 +1000)
mod/forum/view.php

index 5e489df..aee7394 100644 (file)
@@ -160,12 +160,27 @@ switch ($forum->get_type()) {
                 $orderpostsby
             );
         echo $discussionsrenderer->render($USER, $post, $replies);
+
+        if (!$CFG->forum_usermarksread && forum_tp_is_tracked($forumrecord, $USER)) {
+            $postids = array_map(function($post) {
+                return $post->get_id();
+            }, array_merge([$post], array_values($replies)));
+            forum_tp_mark_posts_read($USER, $postids);
+        }
         break;
     case 'blog':
         $discussionsrenderer = $rendererfactory->get_blog_discussion_list_renderer($forum);
         // Blog forums always show discussions newest first.
         echo $discussionsrenderer->render($USER, $cm, $groupid, $discussionlistvault::SORTORDER_CREATED_DESC,
             $pageno, $pagesize);
+
+        if (!$CFG->forum_usermarksread && forum_tp_is_tracked($forumrecord, $USER)) {
+            $discussions = mod_forum_get_discussion_summaries($forum, $USER, $groupid, null, $pageno, $pagesize);
+            $firstpostids = array_map(function($discussion) {
+                return $discussion->get_first_post()->get_id();
+            }, array_values($discussions));
+            forum_tp_mark_posts_read($USER, $firstpostids);
+        }
         break;
     default:
         $discussionsrenderer = $rendererfactory->get_discussion_list_renderer($forum);