Bevestigingsvenster toevoegen bij het reageren op oude onderwerpen

(largely copy-pasted from Last-chance warning when replying to old topics)

I’m running a community that historically has a bit of a problem with necro-bumping threads.

I am familiar with warn_reviving_old_topic_age (and we do have it set), but it seems that many users aren’t seeing the alert. We also don’t want to institute global topic timers because there really are use cases where reviving the old thread is useful.

Our previous solution was to block posting on an “are you sure” dialog based on this component:

but that component is marked as broken (and indeed our version is broken as well). As per the advice in my original support request, I’ve started looking at the unformatted code detector, which has been very useful, but I’m struggling to get over the finish line.

Currently, I have something looking like this:

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

but it doesn’t seem to be working. Adding some debug logs confirms that this.model?.topic?.last_posted_at is indeed undefined, and I have no idea whether the confirmation dialog works either.

Any advice would be appreciated! I think just getting an ISO string of the topic’s current bump date (if any) would be enough for me to make progress.

2 likes