(대부분 Creating a component to show last-chance warning when replying to old topics 에서 복사해옴)
저는 과거에 좀처럼 죽은 스레드를 되살리는(necro-bumping) 문제가 있었던 커뮤니티를 운영하고 있습니다.
저는 warn_reviving_old_topic_age (설정되어 있음)에 대해 잘 알고 있지만, 많은 사용자가 경고 알림을 확인하지 못하는 것 같습니다. 또한, 오래된 스레드를 되살리는 것이 유용한 경우가 실제로 존재하기 때문에 전역적인 토픽 타이머를 도입하고 싶지도 않습니다.
이전 솔루션은 이 컴포넌트를 기반으로 한 “확실합니까?” 대화상자에서 게시를 차단하는 것이었습니다:
하지만 해당 컴포넌트는 깨져 있다는 표시가 되어 있고(실제로 우리 버전도 깨져 있습니다). 원래 지원 요청에 대한 조언에 따라 unformatted code detector를 살펴보기 시작했는데, 매우 유용했지만 마지막 단계를 넘어서지 못하고 있습니다.
현재 다음과 같은 코드를 작성했습니다:
import { withPluginApi } from "discourse/lib/plugin-api";
import { inject as service } from "@ember/service";
export default {
name: "discourse-necro-warnings",
initialize() {
withPluginApi("0.8.8", (api) => {
api.modifyClass("service:composer", (Superclass) => class extends Superclass {
save(...args) {
let lastPostedAt = moment(this.model?.topic?.last_posted_at);
let now = moment();
let diff = now - lastPostedAt;
console.log(diff)
let d = moment.duration(settings.death_timer);
if((diff >= d) && !skipWarning) {
// TODO: i18n
let diffH = moment.duration(diff).humanize();
let confirmationMessage = `The last post in this thread was ${diffH} ago. Are you sure you want to bump this thread?`;
this.dialog.yesNoConfirm({
message: confirmationMessage,
didConfirm: () => {
super.save(...args)
}
});
} else {
super.save(...args);
}
}
});
});
},
};
하지만 작동하지 않는 것 같습니다. 디버그 로그를 추가해 보니 this.model?.topic?.last_posted_at이 실제로 undefined인 것을 확인했고, 확인 대화상자가 작동하는지 여부도 알 수 없습니다.
조언을 주시면 감사하겠습니다. 토픽의 현재 뱀(bump) 날짜(있다면)의 ISO 문자열만 얻으면 진행할 수 있을 것 같습니다.