From 30a8d92ead78f68c67b3b73f97ef855931b21288 Mon Sep 17 00:00:00 2001 From: deing Date: Tue, 6 Aug 2019 18:12:22 +0200 Subject: [PATCH 1/2] Add warning when replying to old topics/comments --- tildes/static/js/behaviors/comment-reply-button.js | 14 ++++++++++++++ tildes/tildes/templates/topic.jinja2 | 3 +++ tildes/tildes/views/topic.py | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/tildes/static/js/behaviors/comment-reply-button.js b/tildes/static/js/behaviors/comment-reply-button.js index 0f94ad4..72f59a6 100644 --- a/tildes/static/js/behaviors/comment-reply-button.js +++ b/tildes/static/js/behaviors/comment-reply-button.js @@ -79,6 +79,20 @@ $.onmount("[data-js-comment-reply-button]", function() { } } + var originalCommentTimestamp = new Date( + $parentComment + .find(".comment-header time") + .first() + .attr("datetime") + ); + if (Date.now() - originalCommentTimestamp > 1000 * 3600 * 24 * 62) { + var warningDiv = document.createElement("div"); + warningDiv.classList.add("toast"); + warningDiv.innerHTML = + "The comment you're replying to is over two months old. Are you sure you want to continue?"; + clone.querySelector("form").prepend(warningDiv); + } + // update Intercooler so it knows about this new form Intercooler.processNodes(clone); diff --git a/tildes/tildes/templates/topic.jinja2 b/tildes/tildes/templates/topic.jinja2 index 73c4697..4816c31 100644 --- a/tildes/tildes/templates/topic.jinja2 +++ b/tildes/tildes/templates/topic.jinja2 @@ -213,6 +213,9 @@ data-js-prevent-double-submit data-js-confirm-leave-page-unsaved > + {% if old_topic_warning %} +
The topic you're replying to is over two months old. Are you sure you want to continue?
+ {% endif %} {{ markdown_textarea() }} diff --git a/tildes/tildes/views/topic.py b/tildes/tildes/views/topic.py index 6a33071..3b859b0 100644 --- a/tildes/tildes/views/topic.py +++ b/tildes/tildes/views/topic.py @@ -6,6 +6,7 @@ from collections import namedtuple from typing import Any, Optional, Union +from datetime import datetime, timedelta, timezone from marshmallow import missing, ValidationError from marshmallow.fields import Boolean, String from pyramid.httpexceptions import HTTPFound @@ -374,6 +375,11 @@ def get_topic(request: Request, comment_order: CommentTreeSortOption) -> dict: tree.uncollapse_new_comments(topic.last_visit_time) tree.finalize_collapsing_maximized() + old_topic_warning = False + + if datetime.now(timezone.utc) - topic.created_time > timedelta(days=62): + old_topic_warning = True + return { "topic": topic, "log": log, @@ -381,6 +387,7 @@ def get_topic(request: Request, comment_order: CommentTreeSortOption) -> dict: "comment_order": comment_order, "comment_order_options": CommentTreeSortOption, "comment_label_options": CommentLabelOption, + "old_topic_warning": old_topic_warning, } From b757a10a7fb86f12d6584ef3fe1d78d693e81f35 Mon Sep 17 00:00:00 2001 From: deing Date: Mon, 12 Aug 2019 14:47:36 +0200 Subject: [PATCH 2/2] Some fixes --- tildes/static/js/behaviors/comment-reply-button.js | 4 ++-- tildes/tildes/templates/topic.jinja2 | 2 +- tildes/tildes/views/topic.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tildes/static/js/behaviors/comment-reply-button.js b/tildes/static/js/behaviors/comment-reply-button.js index 72f59a6..f2f9e3f 100644 --- a/tildes/static/js/behaviors/comment-reply-button.js +++ b/tildes/static/js/behaviors/comment-reply-button.js @@ -81,13 +81,13 @@ $.onmount("[data-js-comment-reply-button]", function() { var originalCommentTimestamp = new Date( $parentComment - .find(".comment-header time") + .find(".comment-posted-time") .first() .attr("datetime") ); if (Date.now() - originalCommentTimestamp > 1000 * 3600 * 24 * 62) { var warningDiv = document.createElement("div"); - warningDiv.classList.add("toast"); + warningDiv.classList.add("toast", "toast-minor", "toast-warning"); warningDiv.innerHTML = "The comment you're replying to is over two months old. Are you sure you want to continue?"; clone.querySelector("form").prepend(warningDiv); diff --git a/tildes/tildes/templates/topic.jinja2 b/tildes/tildes/templates/topic.jinja2 index 4816c31..bf04481 100644 --- a/tildes/tildes/templates/topic.jinja2 +++ b/tildes/tildes/templates/topic.jinja2 @@ -214,7 +214,7 @@ data-js-confirm-leave-page-unsaved > {% if old_topic_warning %} -
The topic you're replying to is over two months old. Are you sure you want to continue?
+
The topic you're replying to is over two months old. Are you sure you want to continue?
{% endif %} diff --git a/tildes/tildes/views/topic.py b/tildes/tildes/views/topic.py index 3b859b0..24bcbdf 100644 --- a/tildes/tildes/views/topic.py +++ b/tildes/tildes/views/topic.py @@ -6,7 +6,7 @@ from collections import namedtuple from typing import Any, Optional, Union -from datetime import datetime, timedelta, timezone +from datetime import timedelta from marshmallow import missing, ValidationError from marshmallow.fields import Boolean, String from pyramid.httpexceptions import HTTPFound @@ -28,7 +28,7 @@ from tildes.enums import ( TopicSortOption, ) from tildes.lib.database import ArrayOfLtree -from tildes.lib.datetime import SimpleHoursPeriod +from tildes.lib.datetime import SimpleHoursPeriod, utc_now from tildes.models.comment import Comment, CommentNotification, CommentTree from tildes.models.group import Group, GroupWikiPage from tildes.models.log import LogComment, LogTopic @@ -377,7 +377,7 @@ def get_topic(request: Request, comment_order: CommentTreeSortOption) -> dict: old_topic_warning = False - if datetime.now(timezone.utc) - topic.created_time > timedelta(days=62): + if utc_now() - topic.created_time > timedelta(days=62): old_topic_warning = True return {