From 14149aaf2c40ee8596786292de8268f0521d3ea8 Mon Sep 17 00:00:00 2001 From: Chad Birch Date: Tue, 28 Aug 2018 21:17:03 -0600 Subject: [PATCH] Add a setting to disable collapsing old comments --- ...de0db_add_collapse_old_comments_setting.py | 29 +++++++++++++++++++ tildes/tildes/models/user/user.py | 1 + tildes/tildes/templates/settings.jinja2 | 2 +- .../templates/settings_comment_visits.jinja2 | 21 ++++++++++++-- tildes/tildes/views/api/web/user.py | 19 ++++++++++-- tildes/tildes/views/topic.py | 3 +- 6 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 tildes/alembic/versions/04fd898de0db_add_collapse_old_comments_setting.py diff --git a/tildes/alembic/versions/04fd898de0db_add_collapse_old_comments_setting.py b/tildes/alembic/versions/04fd898de0db_add_collapse_old_comments_setting.py new file mode 100644 index 0000000..1a1ae00 --- /dev/null +++ b/tildes/alembic/versions/04fd898de0db_add_collapse_old_comments_setting.py @@ -0,0 +1,29 @@ +"""Add collapse_old_comments setting + +Revision ID: 04fd898de0db +Revises: b9d9ae4c2286 +Create Date: 2018-08-29 03:07:10.278549 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "04fd898de0db" +down_revision = "b9d9ae4c2286" +branch_labels = None +depends_on = None + + +def upgrade(): + op.add_column( + "users", + sa.Column( + "collapse_old_comments", sa.Boolean(), server_default="true", nullable=False + ), + ) + + +def downgrade(): + op.drop_column("users", "collapse_old_comments") diff --git a/tildes/tildes/models/user/user.py b/tildes/tildes/models/user/user.py index 683a245..a0cf1f1 100644 --- a/tildes/tildes/models/user/user.py +++ b/tildes/tildes/models/user/user.py @@ -77,6 +77,7 @@ class User(DatabaseModel): inviter_id: int = Column(Integer, ForeignKey("users.user_id")) invite_codes_remaining: int = Column(Integer, nullable=False, server_default="0") track_comment_visits: bool = Column(Boolean, nullable=False, server_default="false") + collapse_old_comments: bool = Column(Boolean, nullable=False, server_default="true") auto_mark_notifications_read: bool = Column( Boolean, nullable=False, server_default="false" ) diff --git a/tildes/tildes/templates/settings.jinja2 b/tildes/tildes/templates/settings.jinja2 index 1a30236..34004bb 100644 --- a/tildes/tildes/templates/settings.jinja2 +++ b/tildes/tildes/templates/settings.jinja2 @@ -121,7 +121,7 @@ {% endif %}
  • - Toggle marking new comments (currently {{ 'enabled' if request.user.track_comment_visits else 'disabled' }}) + Configure marking new comments (currently {{ 'enabled' if request.user.track_comment_visits else 'disabled' }})
    Marks new comments in topics since your last visit, and which topics have any
  • diff --git a/tildes/tildes/templates/settings_comment_visits.jinja2 b/tildes/tildes/templates/settings_comment_visits.jinja2 index e1ae187..82ed77c 100644 --- a/tildes/tildes/templates/settings_comment_visits.jinja2 +++ b/tildes/tildes/templates/settings_comment_visits.jinja2 @@ -24,7 +24,7 @@ name="comment-visits" autocomplete="off" data-ic-patch-to="{{ request.route_url('ic_user', username=request.user.username) }}" - data-ic-target="closest main" + data-js-autosubmit-on-change >
    + - +
    +
    + +
    {% endblock %} diff --git a/tildes/tildes/views/api/web/user.py b/tildes/tildes/views/api/web/user.py index 67bcca3..b884e20 100644 --- a/tildes/tildes/views/api/web/user.py +++ b/tildes/tildes/views/api/web/user.py @@ -190,10 +190,23 @@ def patch_change_track_comment_visits(request: Request) -> Response: track_comment_visits = bool(request.params.get("track_comment_visits")) user.track_comment_visits = track_comment_visits - if track_comment_visits: - return Response("Enabled tracking of last comment visit.") + return IC_NOOP + + +@ic_view_config( + route_name="user", + request_method="PATCH", + request_param="ic-trigger-name=collapse-old-comments", + permission="change_collapse_old_comments_setting", +) +def patch_change_collapse_old_comments(request: Request) -> Response: + """Change the user's "collapse old comments" setting.""" + user = request.context - return Response("Disabled tracking of last comment visit.") + collapse_old_comments = bool(request.params.get("collapse_old_comments")) + user.collapse_old_comments = collapse_old_comments + + return IC_NOOP @ic_view_config( diff --git a/tildes/tildes/views/topic.py b/tildes/tildes/views/topic.py index 8cf9d4d..b59b180 100644 --- a/tildes/tildes/views/topic.py +++ b/tildes/tildes/views/topic.py @@ -280,7 +280,8 @@ def get_topic(request: Request, comment_order: CommentSortOption) -> dict: mark_changed(request.db_session) # collapse old comments if the user has a previous visit to the topic - if topic.last_visit_time: + # (and doesn't have that behavior disabled) + if topic.last_visit_time and request.user.collapse_old_comments: tree.collapse_old_comments(topic.last_visit_time) return {