Browse Source

Fix unread forum

sh4nks 8 years ago
parent
commit
8439db1380
2 changed files with 12 additions and 1 deletions
  1. 5 1
      flaskbb/utils/helpers.py
  2. 7 0
      tests/unit/utils/test_helpers.py

+ 5 - 1
flaskbb/utils/helpers.py

@@ -215,6 +215,10 @@ def forum_is_unread(forum, forumsread, user):
     if forum and forum.topic_count == 0:
     if forum and forum.topic_count == 0:
         return False
         return False
 
 
+    # check if the last post is newer than the tracker length
+    if forum.last_post_created < read_cutoff:
+        return False
+
     # If the user hasn't visited a topic in the forum - therefore,
     # If the user hasn't visited a topic in the forum - therefore,
     # forumsread is None and we need to check if it is still unread
     # forumsread is None and we need to check if it is still unread
     if forum and not forumsread:
     if forum and not forumsread:
@@ -263,7 +267,7 @@ def topic_is_unread(topic, topicsread, user, forumsread=None):
         return False
         return False
 
 
     # topicsread is none if the user has marked the forum as read
     # topicsread is none if the user has marked the forum as read
-    # or if he hasn't visited yet
+    # or if he hasn't visited the topic yet
     if topicsread is None:
     if topicsread is None:
         # user has cleared the forum - check if there is a new post
         # user has cleared the forum - check if there is a new post
         if forumsread and forumsread.cleared is not None:
         if forumsread and forumsread.cleared is not None:

+ 7 - 0
tests/unit/utils/test_helpers.py

@@ -40,6 +40,13 @@ def test_forum_is_unread(guest, user, forum, topic, forumsread):
     flaskbb_config["TRACKER_LENGTH"] = 0
     flaskbb_config["TRACKER_LENGTH"] = 0
     assert not forum_is_unread(forum, forumsread, user)
     assert not forum_is_unread(forum, forumsread, user)
 
 
+    # there haven't been a post since TRACKER_LENGTH and thus the forum is read
+    flaskbb_config["TRACKER_LENGTH"] = 1
+    # this is cheating; don't do this.
+    forum.last_post_created = forum.last_post_created - datetime.timedelta(hours=48)
+    forum.save()
+    assert not forum_is_unread(forum, forumsread, user)
+
     # no topics in this forum
     # no topics in this forum
     topic.delete()
     topic.delete()
     forum = Forum.query.filter_by(id=forum.id).first()
     forum = Forum.query.filter_by(id=forum.id).first()