Url Composer Templates

Thanks for pointing that out @NateDhaliwal

No, it just sniffs the url looking for a specific string and pre-fills the the composer with one of a few a templates when it finds that string.

The Docus plugin puts that string into urls as one of its functions, but this component will work with any string or delivery mechanism someone wants to use, so it can stand alone. I’ll update the readme to explain that.

For example, you could tell it to look for: ‘/tag/introductions’ and it would become a tag template component. Or you could use it as i am to put that template into tag-intersections, like: tags/intersection/introductions/webdevs

I’ll move the string it looks for into the admin section so it’s easier for others to modify and use without digging into the code.

Tbh, i’ve been struggling with a bug with it for the past few days and have been pulling my (little remaining hair out) and probably shouldn’t have shared it just yet. It always puts a template in when it finds that string in the url.

Sometimes you want it every time it finds that string, sometimes you only want it if there’s no other threads already there, and sometimes you only want it if that specific user hasn’t already created a thread in that location.

What’s happening now:

The initializer watches for a tag/string in the URL and auto-opens a template in Discourse whenever it sees a match. That works fine when I always want to open a template, but it falls apart when I need conditions like “don’t open if any topic already exists” or “don’t open if this user already posted.”

What I’ve attempted:

  • I introduced a settings.auto_open_check_user_only flag. When it’s on, the code searches for tags:tag1+tag2 @username; when it’s off, it searches for tags:tag1+tag2 only. The goal was to distinguish between “any topic exists” and “this user’s topic exists.”
  • I added a 500 ms delay before turning draft-saving back on to avoid clashes with Discourse’s auto-save.
  • I started logging basic info (trigger ID, template name) so I could at least see when the auto-open fires.

I Suspect the Issues are:

  • Discourse’s search API returns results before the search index updates, so the system keeps thinking “no topics exist” even right after a user posts.
  • Filtering by @username doesn’t help if the username doesn’t match exactly or the tags don’t line up with the template settings.
  • I never cancel Discourse’s pending draft timers, so even though I block saves for 500 ms, the queued saves still run later and bring the draft/composer back.

I’m Currently Trying:

  • After calling deleteDraft, immediately cancel Discourse’s _saveDraft debounce so old drafts can’t reappear.
  • Creating a short-lived cache remembering “I already created a topic here with these tags” to cover the search-index lag.
  • Creating 3 modes that can be chosen in the Admin section

always
Opens the template every time the tag(s) match. No searches, no checks—just open the composer.

ifNoTopics
Uses Discourse search to ask: Is there already any topic with these tags?

  • If yes → don’t open.
  • If no → open.
    Good for “only one topic should exist” situations.

ifUserHasNoTopic
Searches for: Has this specific user already created a topic with these tags?

  • If yes → don’t open.
  • If no → open.
    Useful when each user should get their own personal thread.

If anyone has any suggestions how they would approach creating those settings i would love to hear them.