Rocket.Chat.ReactNative icon indicating copy to clipboard operation
Rocket.Chat.ReactNative copied to clipboard

fix: make readonly permission reactive in RoomView

Open deepak0x opened this issue 1 month ago β€’ 1 comments

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 isReadOnly to 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 isReadOnly to accept postReadOnlyPermission as 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.

deepak0x avatar Nov 16 '25 16:11 deepak0x

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 in mapStateToProps.
  • Inspect shouldComponentUpdate dequal comparison to ensure it includes the new prop correctly.
  • Confirm isReadOnly and canPostReadOnly handle undefined permission 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.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 16 '25 16:11 coderabbitai[bot]