Bump Reset plugin - Annotated to help new devs

This plugin may be interesting to both Discourse admins and people learning how to write Discourse plugins. I’ve given each audience separate sections below.

For Discourse admins:

This plugin gives staff members a button to quickly reset a thread’s bump time to the original time of any post within the thread. The button is added to the admin menu (spanner icon) for each post:

This is useful if you make minor edits to the last post and don’t want the thread bumped or if the wrong person/post are currently marked as the latest in the thread due to a delete or un-delete of a later post.

The plugin doesn’t really let you do anything you could not do already (other than repairing the last post/poster if they go wrong), it just lets you do things more conveniently. The ability to change the timestamp of a thread is built in to Discourse, but the UI for doing so is modal and requires you to separately select the date and time. You can only see the detailed date and time of a post in another modal UI, and cannot copy and paste between the two UIs as they use different formats.

Each use of the Reset Bump To Here button will be logged in the Discourse staff actions log, including the topic and post IDs and URL, and old and new timestamps:

This can help detect abuse of the functionality (e.g. to hide new posts from other admins, rather than the intended use of avoiding bumps when making formatting-only fixes to old threads, or undoing a user’s gratuitous bump without deleting their message entirely).

Installation:

The plugin is on github as usual: https://github.com/LeoDavidson/discourse-reset-bump

Follow the Install a Plugin howto, using git clone https://github.com/leodavidson/discourse-reset-bump.git as the plugin command.

Once you’ve installed it, it will be enabled by default and can be disabled under the site’s admin / plugin settings area, via the reset_bump_enabled checkbox.

For new plugin developers:

  • The source code is simple, since what the plugin does is simple.
  • The code is extensively commented. Comments far outweigh code.
  • All logic is in just 2 files (1 client side, 1 server side).
  • I unpacked inline functions into normal top-level functions so you can more easily see the structure of things, and only have to deal with one concept at a time.

This is the first Discourse plugin I’ve written, the first Ruby (let alone Ruby on Rails), and the first time I’ve used Javascript as more than a stand-in for simple VBScript. I’ve got years of C++ and C# experience but found this a steep learning curve (but quite nice in the end). My aim was to properly understand what I was doing and to document the hows and whys to help the next person.

I’m still fuzzy on some concepts but I hope I got the important details right. Corrections to code or comments greatly appreciated.

In terms of what the plugin does:

  • Standard enable/disable setting.
  • Client side uses the newer withPluginApi initialization method.
  • Adds a button to the post admin menu (pictured above) below each post.
  • (Also has commented-out code showing how to add to the main post buttons, outside the menu.)
  • Client side checks for staff privileges (so the UI isn’t shown to people who can’t use it).
  • Button click triggers AJAX request to the server side.
  • Server side checks for staff privileges (can’t rely on client for that; it can be bypassed).
  • Server side checks the plugin is enabled (so if a security issue was found, the AJAX endpoint can be stubbed out quickly without having to restart the server).
  • Server side takes the post ID from the client and looks up the topic details (or returns an error for the client to display).
  • Server side updates the database records of the topic accordingly, and returns success if it worked.
  • Server side logs the action to the staff action log. (Working out the right place for the i18n translated action string was tricky here.)

All easy once you know how, but as a newbie it took me days of unravelling source code, (outdated) forum threads, multiple unfamiliar languages and frameworks, which was quite overwhelming.

I also recommend looking at other plugins to see how you can write things in a “nicer” (or at least more compact!) way once you understand what’s going on. This one’s code is meant to be easy to understand and not necessarily the “best” way to do things.

I hope it helps you!

22 Likes

I installed the plugin and am able to see the enable/disable setting, but … no button in the post adminstration :confused:

Using Discourse v1.7.2 +2

It’ll probably only work in Discourse 1.8.0 and above as I set the API version to the latest (since it’s the only one I’ve tested with).

Changing the withApi… 0.7 line to 0.6 near the bottom of the .es6 file might make things work, but hasn’t been tested. I might be depending on changes in the latest Discourse.

3 Likes

Okay, good to know! I’ll test it out on my development machine

2 Likes

This plugin is coming in very handy for a migrated forum that has a ton of formatting/editing that needs to be done on old topics/posts. Thank you!

An added feature that might come in handy to make things even more efficient, is to add an option “Reset bump to last post” when you are bulk selecting topics in a topic listing view. That way I could just go to the Latest view and pick through all recently edited posts to bump them all back to where they were in one action.

1 Like

It looks like similar (and more) functionality is now built in to Discourse:

So there is less reason to install this plugin anymore in terms of functionality.

That said:

  • It looks like the built-in functionality only lets you reset the bump date to the last post’s date, not to an arbitrary post’s date.
  • The built-in functionality also lets you reply without bumping, but lacks the ability to, say, prevent someone else’s reply from bumping the thread without deleting their reply.

So maybe some people will still want to use it.

Either way, plugin developers should still find the heavily annotated source code useful, even if what it actually does is now redundant.

5 Likes

I still think it’s a great plugin but it seems like it stopped working after updating discourse?

Hi!

So I’m aware of this and also changing the time stamps of the topic. However I have used this plugin before and it stopped working but I think it’s quite an important feature:

At times there will be topics which people bump up and they aren’t really spamming but also you might not want them to show up first on the feed. Therefore bumping up to the previous post is quite useful, instead of deleting the post.

For example, let’s say I reply on a post talking about a feature on discourse from 2017. You might not want to close the topic or unlist it, nor would you want to delete my reply, but you might not want it to bump so other users might start thinking it’s actually “news”. Or if there’s a heated discussion that may cause some provocation but doesn’t quite require flagging, you might want to not let it rise to the top of the discussion board again.
Just two example on top of my head.

Is there any elegant way to achieve this?

The plugin still works here, FWIW. I use it all the time.

That’s so strange! it stopped working after I upgraded discourse. I’m on 3.2.0.beta2-dev if that changes anything?

1 Like

I upgraded discourse to 3.2.0.beta2-dev and am unable to have the plugin working. I am able to install and activate it but the “Reset Bump To Here” option is not showing up.

@LeoDavidson what version are you running on ?

1 Like

The post-admin-menu widget has been “removed” recently in favor of a glimmer component here admin-post-menu.gjs.

The proper way to add a button is to use the addPostAdminMenuButton API instead:

	api.addPostAdminMenuButton((name, attrs) => {
		return {
			action: (post) => {
				const ajaxParams = {
					type: 'POST',
					data: { post_id: post.id }
				};

				ajax("/reset_bump", ajaxParams).catch(popupAjaxError);
			},
			icon: 'calendar-times',
			className: 'reset-bump',
			label: 'reset_bump.button_label',
		};
	});
1 Like

Discourse says I’m on 3.2.0.beta2-dev (38c8fc6136)

If anyone wants to send a pull request, I’ll accept it. Don’t have time to test this myself at the moment, at least while it’s still working for me. Will look in the future myself if no one does before then, but will likely be busy for a few weeks at the moment.

2 Likes

Sure, I will make a PR later! :slight_smile:

3 Likes

Thanks! Keep us posted :innocent:

1 Like

I made the PR :+1:

5 Likes

Many thanks! Looks good and has been merged.

4 Likes