[2.x] fix(api): surface event posts in discussion PATCH responses and route title via rename()#4658
Merged
Merged
Conversation
… route title via rename() Fixes two related 2.x regressions where discussion changes silently fail to surface in the UI: 1. Event posts created via `mergePost()` (sticky/tags/lock) were absent from PATCH responses. The 1.x `UpdateDiscussionController` refreshed the `posts` linkage and inlined modified posts on every update; the 2.x `DiscussionResource` rewrite dropped that. 2. Renaming a discussion no longer raised `Renamed`. The 2.x `DiscussionResource` title field delegated to the default attribute setter, bypassing `Discussion::rename()`. The `DiscussionRenamedLogger` listener never ran, so neither the `discussionRenamed` event post nor the notification fired. Together these broke the "rename -> event post appears -> author gets notified" flow that worked end-to-end in 1.x. Core fixes: - `DiscussionResource::posts` field now exposes linkage on update - `DiscussionResource::title` field now routes through `rename()` - `RenameDiscussionModal` chains redraw onto the `update()` promise Sticky/Tags/Lock JS: - Chain redraw onto the `stream.update()` promise (was firing synchronously, before the new post was in-store) Sticky/Tags realtime: - Register broadcasts via the Realtime extender so other users see the event posts as they happen, mirroring the existing `lock` template. Recipient permission is enforced per-user by the Realtime Generator (internal API request runs as the recipient). Closes #4620
…config build-typings was failing because the new `extendRealtime.ts` files import from `ext:flarum/realtime/forum/extenders/Realtime`, but neither extension's tsconfig.json mapped that module specifier to realtime's dist-typings. Mirror the mapping that flarum-lock already has.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two related 2.x regressions where discussion changes silently fail to surface in the UI:
mergePost()(sticky, tags, lock) are absent from PATCH responses. The 1.xUpdateDiscussionControllerrefreshedpostslinkage and inlined modified posts on every update; the 2.xDiscussionResourcerewrite dropped that. Result: the action originator sees no event post in their stream until reload — even though the post exists in the DB.Renamed. The 2.xDiscussionResourcedefines atitlefield that delegates to the default attribute setter, bypassingDiscussion::rename(). TheDiscussionRenamedLoggerlistener never runs, so nodiscussionRenamedevent post is created and no notification is sent to the discussion author.Together these regressions break the "rename → event post appears → original author gets notified" flow that worked end-to-end in 1.x.
Changes
Core
framework/core/src/Api/Resource/DiscussionResource.phppostsfield'swithLinkagepredicate to also fire on update. PATCH responses now carry the refreshedpostslinkage including any new event post id(s) added viamergePost(). Frontendstream.update()then seescount()grow andloadRange()fetches the new post(s) in a single batched GET.->set()callback on thetitlefield so updates route throughDiscussion::rename(). This restores theRenameddomain event, which in turn triggersDiscussionRenamedLoggerto create thediscussionRenamedevent post and dispatchDiscussionRenamedBlueprintnotifications.framework/core/js/src/forum/components/RenameDiscussionModal.tsx— Chainm.redraw()onto thestream.update()promise rather than calling it synchronously. Without this, the redraw fires beforeloadRange()resolves and the new event post stays invisible until something else triggers a redraw. Same pattern asflarum/realtime's existingwebsocketEventStreamUpdatehandler.Sticky, Tags, Lock (client timing)
addStickyControl.js,TagDiscussionModal.tsx,addLockControl.js— sameupdate().then(m.redraw)chaining fix. Lock had server-side realtime wired correctly but its client-side redraw timing was still off; sticky and tags had neither.Sticky, Tags (realtime broadcast)
extensions/sticky/extend.php— RegisterDiscussionWasStickied/DiscussionWasUnstickiedvia the Realtime extender'sbroadcastModelEvent, broadcasting as'stickiedEvent'. Other users viewing the discussion see the event post in real time.extensions/sticky/js/src/forum/extendRealtime.ts(new) — register'stickiedEvent'via the Realtime JS extender'sonDiscussionStreamEvent, mirroringflarum-lock.extensions/tags/extend.php— Same wiring forDiscussionWasTagged, broadcasting as'taggedEvent'. Recipient permission is enforced per-user by the Realtime extension's existingGenerator(it issues an internal API request as the recipient, so users without access to a discussion don't receive the broadcast).extensions/tags/js/src/forum/extendRealtime.ts(new) — register'taggedEvent'.Tests
framework/core/tests/integration/api/discussions/UpdateTest.php(new) — asserts that PATCHingtitlecreates adiscussionRenamedpost, that the PATCH response'spostslinkage contains its id, and that a no-op title change creates no event post.extensions/sticky/tests/integration/api/StickyDiscussionsTest.php— new test asserting that PATCHisSticky: truereturns a response whosepostslinkage contains both the original comment post and the newly-createddiscussionStickiedevent post.Manual verification
On a Flarum 2.0.0-rc.1 stack with
flarum-realtimeenabled:lockonly; now works for all four.discussionRenamednotification (provided the preference is enabled).Generator, which runs the payload-generation API request as the recipient.Closes #4620