framework icon indicating copy to clipboard operation
framework copied to clipboard

[2.x] fix(tags): update tag metadata when a pending discussion is approved

Open karl-bullock opened this issue 5 months ago • 0 comments

Fixes #4776

Problem

With flarum/approval active, a discussion/post created pending approval is treated as is_private, so UpdateTagMetadata correctly skips it on Started/Posted. But nothing updates the tag once the content is approved, so the tag's discussion_count and last_posted_discussion_id are left permanently stale (e.g. the /tags tile shows a wrong count and no latest discussion).

Fix

UpdateTagMetadata now also handles approval's PostWasApproved:

  • First post approved → +1 (the discussion becomes counted); otherwise 0 (refresh last-posted for an approved reply).
  • Registered by class-string, so there is no hard dependency on flarum/approval — if it isn't installed the event simply never fires.
  • PostWasApproved is also handled by approval's own UpdateDiscussionAfterPostApproval, which is what flips is_private. To stay independent of listener order, this acts immediately when the discussion is already visible, otherwise defers via afterSave so the refresh runs once approval persists the change.

Verification

Clean Flarum 2.0.0-rc.4 (only core + tags + approval):

  1. A member without startWithoutApproval starts a discussion → pending (is_private = true); tag stays count=0, last_posted_discussion_id=null (correct while pending).
  2. Admin approves → discussion is visible, and the tag now shows count=1 and the correct last_posted_discussion_id.

Before this change both stayed 0 / null after approval. An admin's auto-approved discussion (control) is unaffected.

karl-bullock avatar Jun 20 '26 23:06 karl-bullock