How can I access composePrivateMessage from a post menu button?

AI-generated summary

tarek is seeking help to access composePrivateMessage from a post menu button. They want to add “reply” and “reply all” buttons to each post in a topic, with “reply” mimicking the default behaviour of clicking on a post author’s card and then “message”. Despite finding the correct action in application.js, they are struggling to implement it as a clickable button due to their limited familiarity with Rails.

Hello,

I wrote a plugin for mailing list type behaviour, where emails can be replied to (only the sender) and reply-all (to the whole topic). I want to recreate this in the web UI as well by having a “reply” and “reply all” button on each post in the topic. The “reply” would mimic clicking on a post author’s card and then “message”. This is the default behaviour it gives:

Despite writing the plugin above, I am not very familiar with rails and struggle significantly with it. I think I found the correct ‘action’ here. It is composePrivateMessage, which is found in /discourse/app/assets/javascripts/discourse/app/routes/application.js. As indicated by the path, it’s a route, which is throwing me off, and I am struggling to turn that into a clickable button.

Here is what I have right now:

  api.addPostMenuButton("reply-privately", (attrs, state) => {
    return {
      action: composePrivateMessage(user, post),
      title: "reply-privately",
      icon: "reply",
      position: "last",
      className: "reply-privately",
    };
  });

Any thoughts on how to make the ‘action’ fit into the ‘route’?

1 Like