From 4bb06f0e16c046c214d54b4a7ac23a069b092ce0 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Wed, 15 Dec 2021 17:16:41 +0200 Subject: [PATCH] FEATURE: Show notice if user can accept an answer (#175) Implements a a notice that will show for old topics with no accepted answers. --- .../connectors/topic-navigation/no-answer.hbs | 6 +++ .../topic-navigation/no-answer.js.es6 | 40 +++++++++++++++++++ config/locales/client.en.yml | 4 ++ 3 files changed, 50 insertions(+) create mode 100644 assets/javascripts/discourse/connectors/topic-navigation/no-answer.hbs create mode 100644 assets/javascripts/discourse/connectors/topic-navigation/no-answer.js.es6 diff --git a/assets/javascripts/discourse/connectors/topic-navigation/no-answer.hbs b/assets/javascripts/discourse/connectors/topic-navigation/no-answer.hbs new file mode 100644 index 0000000..e9b2d12 --- /dev/null +++ b/assets/javascripts/discourse/connectors/topic-navigation/no-answer.hbs @@ -0,0 +1,6 @@ +{{#if show}} + {{#topic-navigation-popup}} +

{{i18n "solved.no_answer.title"}}

+

{{i18n "solved.no_answer.description"}}

+ {{/topic-navigation-popup}} +{{/if}} diff --git a/assets/javascripts/discourse/connectors/topic-navigation/no-answer.js.es6 b/assets/javascripts/discourse/connectors/topic-navigation/no-answer.js.es6 new file mode 100644 index 0000000..f14a353 --- /dev/null +++ b/assets/javascripts/discourse/connectors/topic-navigation/no-answer.js.es6 @@ -0,0 +1,40 @@ +import { later } from "@ember/runloop"; + +// 7 days in milliseconds +const MAX_DURATION_WITH_NO_ANSWER = 7 * 24 * 60 * 60 * 1000; + +export default { + setupComponent(args, component) { + component.set("show", false); + + later(() => { + if ( + !component.element || + component.isDestroying || + component.isDestroyed + ) { + return; + } + + const topic = args.topic; + const currentUser = component.currentUser; + + // show notice if: + // - user can accept answer + // - it does not have an accepted answer + // - topic is old + // - topic has at least one reply from another user that can be accepted + if ( + !topic.accepted_answer && + currentUser && + topic.user_id === currentUser.id && + moment() - moment(topic.created_at) > MAX_DURATION_WITH_NO_ANSWER && + topic.postStream.posts.some( + (post) => post.user_id !== currentUser.id && post.can_accept_answer + ) + ) { + component.set("show", true); + } + }, 2000); + }, +}; diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 90b548b..8abc253 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -27,6 +27,10 @@ en: no_solved_topics_title: "You haven’t solved any topics yet" no_solved_topics_body: "When you provide a helpful reply to a topic, your reply might be selected as the solution by the topic owner or staff." + no_answer: + title: Has your question been answered? + description: "Highlight the answer and help others by using the solution button below the correct reply." + topic_statuses: solved: help: "This topic has a solution"