fix: make readonly permission reactive in RoomView
When an admin grants the "post-readonly" permission while a user is in a read-only room, the composer stays disabled until they navigate away or restart the app. The UI doesn't update immediately.
Issue(s) Fixes bug: #6802
Solution
- Updated
isReadOnlyto accept the permission as a parameter instead of reading it statically. - Made RoomView subscribe to permission changes from Redux.
- Added detection so the component re-renders when the permission changes.
- The composer now enables/disables immediately when permissions change.
Changes
- Modified
isReadOnlyto acceptpostReadOnlyPermissionas an optional parameter. - Updated RoomView to get the permission from Redux props.
- Added permission change detection in
shouldComponentUpdate. - The component now updates immediately when the permission changes
Summary by CodeRabbit
-
Refactor
- Read-only logic updated to honor an optional post-readonly permission source, keeping backward compatibility.
- Room view now reacts to changes in that permission so read-only status and UI updates happen more reliably when permissions change.
Walkthrough
Adds an optional postReadOnlyPermission parameter that flows from Redux into RoomView props and is forwarded to the isReadOnly helper; isReadOnly and its internal canPostReadOnly use the provided permission when present, otherwise fall back to the existing Redux snapshot.
Changes
| Cohort / File(s) | Summary |
|---|---|
Helper Function Enhancement app/lib/methods/helpers/isReadOnly.ts |
Extended isReadOnly(room, username) β isReadOnly(room, username, postReadOnlyPermission?: string[]). canPostReadOnly now accepts/uses the optional permission argument and falls back to the stored Redux snapshot when undefined. |
Interface Definition app/views/RoomView/definitions.ts |
Added optional prop postReadOnlyPermission?: string[] to IRoomViewProps. |
Component Integration app/views/RoomView/index.tsx |
Mapped state.permissions['post-readonly'] β postReadOnlyPermission in mapStateToProps; included the prop in shouldComponentUpdate comparisons and passed it into isReadOnly in setReadOnly. |
Sequence Diagram
sequenceDiagram
participant Redux as Redux State
participant Component as RoomView (mapStateToProps)
participant Helper as isReadOnly()
Redux->>Component: postReadOnlyPermission (state.permissions['post-readonly'])
Component->>Component: shouldComponentUpdate checks prop change
rect rgb(240,248,255)
Note over Component,Helper: Read-only evaluation (new flow)
Component->>Helper: setReadOnly(..., postReadOnlyPermission)
Helper->>Helper: canPostReadOnly(postReadOnlyPermission?)
alt permission provided
Helper-->>Component: use provided permission β determine RO
else fallback
Helper->>Redux: read permission snapshot
Helper-->>Component: determine RO from snapshot
end
end
Estimated code review effort
π― 3 (Moderate) | β±οΈ ~20 minutes
- Verify
state.permissions['post-readonly']access and typing inmapStateToProps. - Inspect
shouldComponentUpdatedequal comparison to ensure it includes the new prop correctly. - Confirm
isReadOnlyandcanPostReadOnlyhandleundefinedpermission consistently and preserve previous behavior.
Suggested reviewers
- diegolmello
Poem
π° I hopped through Redux fields today,
found a permission along the way.
I carried it gentle, soft and light,
through props and helpers β out of sight.
Optional, tidy β then all was right. π©β¨
Pre-merge checks and finishing touches
β Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
| Title check | β Passed | The title accurately summarizes the main change: making the readonly permission reactive in RoomView by fixing a bug where permission changes weren't immediately reflected in the UI. |
| Docstring Coverage | β Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
β¨ Finishing touches
- [ ] π Generate docstrings
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
π Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Jira integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
π₯ Commits
Reviewing files that changed from the base of the PR and between 67cb546c17c12f93109050c48f909df991e836ce and 401bb5e7d5a339b72b208b624d4403d383452525.
π Files selected for processing (1)
-
app/lib/methods/helpers/isReadOnly.ts(1 hunks)
π§ Files skipped from review as they are similar to previous changes (1)
- app/lib/methods/helpers/isReadOnly.ts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.