Browse Source

Add warning when replying to old topics/comments

merge-requests/76/head
deing 6 years ago
parent
commit
30a8d92ead
No known key found for this signature in database GPG Key ID: DA34C790D267C164
  1. 14
      tildes/static/js/behaviors/comment-reply-button.js
  2. 3
      tildes/tildes/templates/topic.jinja2
  3. 7
      tildes/tildes/views/topic.py

14
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 // update Intercooler so it knows about this new form
Intercooler.processNodes(clone); Intercooler.processNodes(clone);

3
tildes/tildes/templates/topic.jinja2

@ -213,6 +213,9 @@
data-js-prevent-double-submit data-js-prevent-double-submit
data-js-confirm-leave-page-unsaved data-js-confirm-leave-page-unsaved
> >
{% if old_topic_warning %}
<div class="toast">The topic you're replying to is over two months old. Are you sure you want to continue?</div>
{% endif %}
<input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}"> <input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">
{{ markdown_textarea() }} {{ markdown_textarea() }}

7
tildes/tildes/views/topic.py

@ -6,6 +6,7 @@
from collections import namedtuple from collections import namedtuple
from typing import Any, Optional, Union from typing import Any, Optional, Union
from datetime import datetime, timedelta, timezone
from marshmallow import missing, ValidationError from marshmallow import missing, ValidationError
from marshmallow.fields import Boolean, String from marshmallow.fields import Boolean, String
from pyramid.httpexceptions import HTTPFound 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.uncollapse_new_comments(topic.last_visit_time)
tree.finalize_collapsing_maximized() tree.finalize_collapsing_maximized()
old_topic_warning = False
if datetime.now(timezone.utc) - topic.created_time > timedelta(days=62):
old_topic_warning = True
return { return {
"topic": topic, "topic": topic,
"log": log, "log": log,
@ -381,6 +387,7 @@ def get_topic(request: Request, comment_order: CommentTreeSortOption) -> dict:
"comment_order": comment_order, "comment_order": comment_order,
"comment_order_options": CommentTreeSortOption, "comment_order_options": CommentTreeSortOption,
"comment_label_options": CommentLabelOption, "comment_label_options": CommentLabelOption,
"old_topic_warning": old_topic_warning,
} }

Loading…
Cancel
Save