Browse Source

Add a setting to disable collapsing old comments

merge-requests/34/head
Chad Birch 6 years ago
parent
commit
14149aaf2c
  1. 29
      tildes/alembic/versions/04fd898de0db_add_collapse_old_comments_setting.py
  2. 1
      tildes/tildes/models/user/user.py
  3. 2
      tildes/tildes/templates/settings.jinja2
  4. 21
      tildes/tildes/templates/settings_comment_visits.jinja2
  5. 19
      tildes/tildes/views/api/web/user.py
  6. 3
      tildes/tildes/views/topic.py

29
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")

1
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"
)

2
tildes/tildes/templates/settings.jinja2

@ -121,7 +121,7 @@
{% endif %}
</li>
<li>
<a href="/settings/comment_visits">Toggle marking new comments (currently {{ 'enabled' if request.user.track_comment_visits else 'disabled' }})</a>
<a href="/settings/comment_visits">Configure marking new comments (currently {{ 'enabled' if request.user.track_comment_visits else 'disabled' }})</a>
<div class="text-small text-secondary">Marks new comments in topics since your last visit, and which topics have any</div>
</li>
<li>

21
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
>
<div class="form-group">
<label class="form-checkbox">
@ -37,7 +37,24 @@
<i class="form-icon"></i> Track my last visit to each topic's comments and mark new comments
</label>
</div>
</form>
<button class="btn btn-primary" type="submit">Save setting</button>
<form
name="collapse-old-comments"
autocomplete="off"
data-ic-patch-to="{{ request.route_url('ic_user', username=request.user.username) }}"
>
<div class="form-group">
<label class="form-checkbox">
<input
type="checkbox"
id="collapse_old_comments"
name="collapse_old_comments"
data-js-autosubmit-on-change
{% if request.user.collapse_old_comments %}checked{% endif %}
>
<i class="form-icon"></i> Collapse old comments when I return to a topic (no effect unless the overall setting is enabled)
</label>
</div>
</form>
{% endblock %}

19
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(

3
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 {

Loading…
Cancel
Save