FEATURE: Show notice if user can accept an answer (#175)

Implements a a notice that will show for old topics with no accepted
answers.
This commit is contained in:
Bianca Nenciu 2021-12-15 17:16:41 +02:00 committed by GitHub
parent 8635fed3d6
commit 4bb06f0e16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,6 @@
{{#if show}}
{{#topic-navigation-popup}}
<h3>{{i18n "solved.no_answer.title"}}</h3>
<p>{{i18n "solved.no_answer.description"}}</p>
{{/topic-navigation-popup}}
{{/if}}

View File

@ -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);
},
};

View File

@ -27,6 +27,10 @@ en:
no_solved_topics_title: "You havent 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"