...
 
Commits (2)
......@@ -26,17 +26,20 @@ from tildes.views.decorators import ic_view_config
def _increment_topic_comments_seen(
request: Request,
comment: Comment,
request: Request,
comment: Comment,
) -> None:
"""If the user has the "track comment visits" feature enabled, we want to
"""Increment the number of comments in a topic the user has viewed.
If the user has the "track comment visits" feature enabled, we want to
increment the number of comments they've seen in the thread that the
comment came from, so that they don't *both* get a notification as well as
have the thread highlight with "(1 new)". This should only happen if their
last visit was before the comment was posted, however. Below, this is
implemented as a INSERT ... ON CONFLICT DO UPDATE so that it will insert
a new topic visit with 1 comment if they didn't previously have one at
all. """
all.
"""
if request.user.track_comment_visits:
statement = (
insert(TopicVisit.__table__)
......@@ -334,13 +337,17 @@ def put_mark_comments_read(
request: Request,
clear_all_previous: str = 'false'
) -> Response:
"""Mark a comment read (clear all notifications)."""
"""Mark comment(s) read clearing notifications.
comment(s) are removed from unread_notifications and the from topics
'new' count. If the query param clear_all_previous is 'true' all
notifications prior to the target will be cleared.
"""
comment = request.context
response = IC_NOOP
if clear_all_previous == 'true':
prev_notifications = (
request.query(CommentNotification).filter(
CommentNotification.is_unread == True, #noqa
CommentNotification.created_time <=
......@@ -356,14 +363,12 @@ def put_mark_comments_read(
)
for notification in prev_notifications:
notification.is_unread = False
_increment_topic_comments_seen(request, notification.comment)
notification.is_unread = False
_increment_topic_comments_seen(request, notification.comment)
return Response('Your comment notifications have been cleared.')
response = Response('Your comment notifications have been cleared.')
else:
request.query(CommentNotification).filter(
CommentNotification.user == request.user,
CommentNotification.comment == comment,
......@@ -372,4 +377,4 @@ def put_mark_comments_read(
_increment_topic_comments_seen(request, comment)
return IC_NOOP
return response