Bump Reset plugin - Annotated to help new devs

AI-generated summary

LeoDavidson introduced the Bump Reset plugin, designed to help Discourse admins reset a thread’s bump time to any specific post’s timestamp via an admin menu button. The plugin also serves as an extensively commented educational resource for new developers, featuring simple logic split between client and server files. While initially useful for avoiding accidental bumps during edits, Leo noted that Discourse 2.1+ introduced similar native features, though the plugin offers more granular control (resetting to arbitrary posts rather than just the last one).

Users reported compatibility issues after upgrading to Discourse 3.2.0, where the plugin’s button failed to appear due to changes in the post-admin-menu widget. Arkshine identified the need to switch to the addPostAdminMenuButton API and submitted a pull request to update the code. LeoDavidson merged the fix but expressed frustration with Discourse’s frequent breaking changes, ultimately announcing the plugin’s future deletion and his decision to stop supporting the platform. Arkshine offered further assistance to maintain the project.

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: GitHub - LeoDavidson/discourse-reset-bump: A Discourse plugin to quickly reset a thread's bump time to that of a post in the thread. · GitHub

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!

23개의 좋아요

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개의 좋아요

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

2개의 좋아요

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개의 좋아요

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개의 좋아요

여전히 훌륭한 플러그인이라고 생각하는데, discourse를 업데이트한 후부터 작동하지 않는 것 같아요?

안녕하세요!

이 글과 주제 타임스탬프를 변경하는 방법에 대해 알고 있습니다. 하지만 이전에 이 플러그인을 사용했을 때 작동을 멈췄던 적이 있고, 꽤 중요한 기능이라고 생각합니다:

때로는 사람들이 주제를 위로 끌어올리는데, 스팸은 아니지만 피드에 맨 위에 표시되기를 원하지 않는 경우가 있습니다. 따라서 게시물을 삭제하는 대신 이전 게시물까지 끌어올리는 기능이 매우 유용합니다.

예를 들어, 2017년에 디스코urs의 특정 기능에 대해 논의하던 게시물에 답변을 남겼다고 가정해 보겠습니다. 주제를 닫거나 목록에서 제외하고 싶지도 않을 뿐만 아니라, 제 답변을 삭제하고 싶지도 않을 수 있지만, 다른 사용자가 실제로 "뉴스"인 것처럼 오해하지 않도록 끌어올리는 것을 방지하고 싶을 수 있습니다. 또는 일부 도발적인 요소를 포함할 수 있지만 신고할 정도는 아닌 격렬한 논쟁이 있을 경우, 다시 토론 보드의 맨 위로 올라오지 않도록 하고 싶을 수 있습니다.

머릿속에 떠오른 두 가지 예시입니다.

이것을 구현할 수 있는 우아한 방법이 있을까요?

참고로, 여기서는 플러그인이 여전히 작동합니다. 항상 사용하고 있어요.

정말 이상하네요! discourse를 업그레이드한 후부터 작동이 안 돼요. 3.2.0.beta2-dev 버전을 사용 중인데, 이게 관련이 있을까요?

1개의 좋아요

discourse를 3.2.0.beta2-dev로 업그레이드했는데 플러그인이 작동하지 않습니다. 설치와 활성화는 가능하지만 “Reset Bump To Here” 옵션이 표시되지 않습니다.

@LeoDavidson님은 어떤 버전을 사용 중이신가요?

1개의 좋아요

post-admin-menu 위젯은 최근 여기의 admin-post-menu.gjs 글리머 컴포넌트로 대체되었습니다.

버튼을 추가하는 올바른 방법은 addPostAdminMenuButton API를 사용하는 것입니다:

	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',
		};
	});
2개의 좋아요

Discourse에서 3.2.0.beta2-dev(38c8fc6136)라고 표시되고 있습니다.

누군가 풀 리퀘스트를 보내주신다면 받아들일 것입니다. 현재는 제가 직접 테스트할 시간이 없습니다. 적어도 제가 사용하는 환경에서는 아직 잘 작동하고 있기 때문입니다. 그때까지 아무도 하지 않으면 나중에 제가 직접 살펴보겠지만, 당분간 몇 주간 바쁠 것 같습니다.

3개의 좋아요

네, 나중에 PR 올릴게요! :slight_smile:

3개의 좋아요

고마워요! 소식 알려주세요 :innocent:

1개의 좋아요

PR를 만들었습니다 :+1:

7개의 좋아요

감사합니다! 잘 되어 있고 병합되었습니다.

5개의 좋아요

이 플러그인은 향후 삭제될 예정입니다. 사용을 삼가 주세요.

Discourse 팀이 플러그인을 깨뜨리는 변경사항을 계속 도입하는 것에 지쳤습니다. 대부분은 자신들의 편의를 조금 더 높이기 위해 의도적으로 그렇게 하면서, 다른 모든 사람에게 많은 추가 업무를 떠넘기고 있습니다.

더 이상 이 플랫폼을 지원하는 데 시간을 낭비하지 않겠습니다.

3개의 좋아요

도와드릴게요! DEV: Remove .es6 extension and add lint config - Pull Request #3 - LeoDavidson/discourse-reset-bump - GitHub

3개의 좋아요