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 Me gusta

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 Me gusta

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

2 Me gusta

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 me gusta

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 Me gusta

Sigo pensando que es un gran plugin, pero parece que dejó de funcionar después de actualizar Discourse.

Hola!

Soy consciente de esto y también de cambiar las marcas de tiempo del tema. Sin embargo, he usado este plugin antes y dejó de funcionar, pero creo que es una característica bastante importante:

A veces habrá temas que la gente actualiza y no son realmente spam, pero tampoco querrás que aparezcan primero en el feed. Por lo tanto, actualizar a la publicación anterior es bastante útil, en lugar de eliminar la publicación.

Por ejemplo, digamos que respondo a una publicación que habla sobre una característica de Discourse de 2017. Es posible que no quieras cerrar el tema ni deslistarlo, ni tampoco quieras eliminar mi respuesta, pero quizás no quieras que se actualice para que otros usuarios piensen que en realidad son “noticias”. O si hay una discusión acalorada que pueda causar alguna provocación pero no requiera marcarla, es posible que no quieras que vuelva a aparecer en la parte superior del tablero de discusión.
Solo dos ejemplos que se me ocurren.

¿Hay alguna forma elegante de lograr esto?

El plugin todavía funciona aquí, por si acaso. Lo uso todo el tiempo.

¡Qué extraño! Dejó de funcionar después de que actualicé Discourse. Estoy en la versión 3.2.0.beta2-dev, ¿eso cambia algo?

1 me gusta

Actualicé Discourse a 3.2.0.beta2-dev y no puedo hacer que el plugin funcione. Puedo instalarlo y activarlo, pero la opción “Reset Bump To Here” no aparece.

@LeoDavidson ¿qué versión estás ejecutando?

1 me gusta

El widget post-admin-menu ha sido “eliminado” recientemente en favor de un componente glimmer aquí admin-post-menu.gjs.

La forma correcta de añadir un botón es usar la API addPostAdminMenuButton en su lugar:

	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 me gusta

Discourse dice que estoy en 3.2.0.beta2-dev (38c8fc6136)

Si alguien quiere enviar una pull request, la aceptaré. No tengo tiempo para probar esto yo mismo por el momento, al menos mientras todavía me funcione. Lo miraré en el futuro yo mismo si nadie lo hace antes, pero probablemente estaré ocupado durante unas semanas por ahora.

2 Me gusta

¡Claro, haré un PR más tarde! :slight_smile:

3 Me gusta

¡Gracias! Mantennos informados :innocent:

1 me gusta

Hice el PR :+1:

5 Me gusta

¡Muchas gracias! Se ve bien y se ha fusionado.

4 Me gusta