From a9e3db383922c910e147a1d86f3b5a7fe80a6e3c Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Thu, 28 Apr 2022 08:36:42 +0000
Subject: [PATCH] store visit if user opened comments, fixes #903

Closes #903
---
 app/controllers/news.php    | 5 +++++
 app/views/news/_actions.php | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/app/controllers/news.php b/app/controllers/news.php
index 81e832edb24..6ce922e2e4c 100644
--- a/app/controllers/news.php
+++ b/app/controllers/news.php
@@ -90,6 +90,11 @@ class NewsController extends StudipController
             return $this->render_nothing();
         }
 
+        // Store visit if user opened comments
+        if (Request::bool('comments') && Request::submitted('contentbox_open')) {
+            object_set_visit(Request::option('contentbox_open'), 'news');
+        }
+
         // Check if user wrote a comment
         if (Request::submitted('accept') && trim(Request::get('comment_content')) && Request::isPost()) {
             CSRFProtection::verifySecurityToken();
diff --git a/app/views/news/_actions.php b/app/views/news/_actions.php
index b3df43c14c9..15daf3c15fd 100644
--- a/app/views/news/_actions.php
+++ b/app/views/news/_actions.php
@@ -18,7 +18,7 @@
 <?
 if ($new['allow_comments']) :
     $num = StudipComment::NumCommentsForObject($new['news_id']);
-    $visited = object_get_visit($new['news_id'], 'news', false, false);
+    $visited = object_get_visit($new['news_id'], 'news');
     $isnew = StudipComment::NumCommentsForObjectSinceLastVisit($new['news_id'], $visited, $GLOBALS['user']->id);
     ?>
     <? if ($num): ?>
-- 
GitLab