Skip to content

feat: add new setting for encrypted PDFs size limit for previews#3329

Open
nazabucciarelli wants to merge 4 commits into
masterfrom
add-blob-allowed-protocol
Open

feat: add new setting for encrypted PDFs size limit for previews#3329
nazabucciarelli wants to merge 4 commits into
masterfrom
add-blob-allowed-protocol

Conversation

@nazabucciarelli
Copy link
Copy Markdown

@nazabucciarelli nazabucciarelli commented May 13, 2026

Relates to RocketChat/Rocket.Chat#40517

I added ‘blob:’ as a supported protocol in src/documentViewer/ipc.ts so that the sent blob is served by the PDF viewer in Electron. Also, a new setting for managing the max size for preview of encrypted PDFs was added following other settings as reference. e2ePdfPreviewSizeLimit setting title and description were approved by product team.

Related task: SUP-1022

Summary by CodeRabbit

  • New Features

    • New setting to limit PDF preview size in end-to-end encrypted rooms (numeric input, persisted, default 10 MB).
    • Desktop bridge exposes a method to read the current PDF preview size limit for integrations.
  • Bug Fixes

    • Document viewer accepts blob: document sources with origin validation for improved compatibility.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 81a1203f-6c3d-49a6-a805-82405b64802d

📥 Commits

Reviewing files that changed from the base of the PR and between 7709099 and 66625fd.

📒 Files selected for processing (6)
  • src/app/PersistableValues.ts
  • src/constants.ts
  • src/documentViewer/ipc.ts
  • src/servers/preload/e2ePdfPreviewSizeLimit.ts
  • src/ui/components/SettingsView/features/E2ePdfPreviewSizeLimit.tsx
  • src/ui/reducers/e2ePdfPreviewSizeLimit.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: check (windows-latest)
  • GitHub Check: check (ubuntu-latest)
  • GitHub Check: check (macos-latest)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Use TypeScript for all new code in this codebase unless explicitly told otherwise
Use Fuselage components from @rocket.chat/fuselage for all UI work — only create custom components when Fuselage doesn't provide the needed functionality
Check Theme.d.ts for valid color tokens when working with Fuselage components
Use optional chaining with fallbacks for platform-specific APIs instead of mocks (e.g., process.getuid?.() ?? 1000) to ensure code works across all platforms without requiring mocks
TypeScript code must use strict mode
Use React functional components with hooks instead of class components
Redux actions must follow the FSA (Flux Standard Action) pattern
Use camelCase for file naming
Use PascalCase for component file names (React components)
Write self-documenting code through clear naming — avoid unnecessary comments

Files:

  • src/constants.ts
  • src/servers/preload/e2ePdfPreviewSizeLimit.ts
  • src/documentViewer/ipc.ts
  • src/ui/reducers/e2ePdfPreviewSizeLimit.ts
  • src/app/PersistableValues.ts
  • src/ui/components/SettingsView/features/E2ePdfPreviewSizeLimit.tsx
🧠 Learnings (2)
📚 Learning: 2026-05-19T20:49:24.859Z
Learnt from: nazabucciarelli
Repo: RocketChat/Rocket.Chat.Electron PR: 3329
File: src/ui/reducers/e2ePdfPreviewSizeLimit.ts:14-16
Timestamp: 2026-05-19T20:49:24.859Z
Learning: In Rocket.Chat.Electron’s reducer files under src/ui/reducers/, reducers should not re-implement validation for action payloads. Assume the caller (UI component or dispatch site) has already validated the action payload and type/shape; reducers should trust the payload and update state directly. If validation is needed, add it at the dispatch site/caller rather than inside the reducer.

Applied to files:

  • src/ui/reducers/e2ePdfPreviewSizeLimit.ts
📚 Learning: 2026-05-19T20:49:24.859Z
Learnt from: nazabucciarelli
Repo: RocketChat/Rocket.Chat.Electron PR: 3329
File: src/ui/reducers/e2ePdfPreviewSizeLimit.ts:14-16
Timestamp: 2026-05-19T20:49:24.859Z
Learning: In the Rocket.Chat.Electron UI reducers under src/ui/reducers/, do not add/repeat input validation for action payloads inside reducers. Follow the existing codebase pattern: validate the action payload in the caller (e.g., the UI component or dispatch site) before dispatching. Reducers should trust the incoming payload and apply it directly to state. If adding/updating a reducer, ensure the corresponding caller performs the necessary validation (e.g., check numeric constraints like !isNaN(value) && value > 0 before dispatching the action).

Applied to files:

  • src/ui/reducers/e2ePdfPreviewSizeLimit.ts
🔇 Additional comments (7)
src/documentViewer/ipc.ts (1)

18-28: LGTM!

src/constants.ts (1)

1-1: LGTM!

src/app/PersistableValues.ts (2)

110-112: LGTM!


209-212: LGTM!

src/ui/reducers/e2ePdfPreviewSizeLimit.ts (1)

8-21: LGTM!

src/servers/preload/e2ePdfPreviewSizeLimit.ts (1)

4-6: LGTM!

src/ui/components/SettingsView/features/E2ePdfPreviewSizeLimit.tsx (1)

22-74: LGTM!


Walkthrough

Adds a persisted numeric setting e2ePdfPreviewSizeLimit (state, migration, selector, actions, reducer, preload getter, UI, i18n) and expands the document viewer IPC allowlist to accept blob: URLs.

Changes

Blob URL Protocol Support

Layer / File(s) Summary
Blob protocol support in document viewer IPC handler
src/documentViewer/ipc.ts
The document-viewer/open-window allowed URL protocols are updated from ['http:', 'https:'] to ['http:', 'https:', 'blob:'], and blob URLs are origin-validated against the IPC event origin.

E2E PDF preview size limit

Layer / File(s) Summary
Persistable values and migration
src/constants.ts, src/app/PersistableValues.ts
Adds DEFAULT_E2E_PDF_PREVIEW_SIZE_LIMIT_MB = 10, introduces PersistableValues_4_14_0 with e2ePdfPreviewSizeLimit, and adds a '>=4.14.0' migration that defaults it to 10.
Actions, reducer, and store wiring
src/ui/actions.ts, src/ui/reducers/e2ePdfPreviewSizeLimit.ts, src/store/rootReducer.ts
Introduces SETTINGS_SET_E2E_PDF_PREVIEW_SIZE_LIMIT_CHANGED, the e2ePdfPreviewSizeLimit reducer (default 10), payload typing, and wires the reducer into rootReducer.
Persistable selector
src/app/selectors.ts
Adds e2ePdfPreviewSizeLimit to selectPersistableValues.
Preload getter and API exposure
src/servers/preload/e2ePdfPreviewSizeLimit.ts, src/servers/preload/api.ts
Adds getE2ePdfPreviewSizeLimit() (returns persisted value or 10) and exposes it on window.RocketChatDesktop with typings and registration.
Settings UI component and i18n
src/ui/components/SettingsView/features/E2ePdfPreviewSizeLimit.tsx, src/ui/components/SettingsView/GeneralTab.tsx, src/i18n/en.i18n.json
Adds E2ePdfPreviewSizeLimit component (numeric input, validation, dispatch), inserts it into GeneralTab, and adds English translation keys for title and description.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: feature

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely describes the main change: adding a new setting to control encrypted PDF preview size limits.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • SUP-1022: Request failed with status code 401

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.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 13, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/ui/reducers/e2ePdfPreviewSizeLimit.ts`:
- Around line 14-16: The reducer e2ePdfPreviewSizeLimit must validate that any
incoming value is a positive integer before updating state: for the load branch
where you read action.payload.e2ePdfPreviewSizeLimit and for the
SETTINGS_SET_E2E_PDF_PREVIEW_SIZE_LIMIT_CHANGED branch where you return
action.payload, check with Number.isInteger(value) && value > 0 (or equivalent)
and only commit that value; otherwise return the existing state. Update the
branches referencing action.payload.e2ePdfPreviewSizeLimit and the
SETTINGS_SET_E2E_PDF_PREVIEW_SIZE_LIMIT_CHANGED case to perform this validation
and fall back to state on invalid input.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a1c6b876-c1e5-4ee1-9fa4-464fbcaedf7f

📥 Commits

Reviewing files that changed from the base of the PR and between bf462cb and 7709099.

📒 Files selected for processing (10)
  • src/app/PersistableValues.ts
  • src/app/selectors.ts
  • src/i18n/en.i18n.json
  • src/servers/preload/api.ts
  • src/servers/preload/e2ePdfPreviewSizeLimit.ts
  • src/store/rootReducer.ts
  • src/ui/actions.ts
  • src/ui/components/SettingsView/GeneralTab.tsx
  • src/ui/components/SettingsView/features/E2ePdfPreviewSizeLimit.tsx
  • src/ui/reducers/e2ePdfPreviewSizeLimit.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: check (ubuntu-latest)
  • GitHub Check: check (windows-latest)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Use TypeScript for all new code in this codebase unless explicitly told otherwise
Use Fuselage components from @rocket.chat/fuselage for all UI work — only create custom components when Fuselage doesn't provide the needed functionality
Check Theme.d.ts for valid color tokens when working with Fuselage components
Use optional chaining with fallbacks for platform-specific APIs instead of mocks (e.g., process.getuid?.() ?? 1000) to ensure code works across all platforms without requiring mocks
TypeScript code must use strict mode
Use React functional components with hooks instead of class components
Redux actions must follow the FSA (Flux Standard Action) pattern
Use camelCase for file naming
Use PascalCase for component file names (React components)
Write self-documenting code through clear naming — avoid unnecessary comments

Files:

  • src/ui/reducers/e2ePdfPreviewSizeLimit.ts
  • src/store/rootReducer.ts
  • src/app/selectors.ts
  • src/servers/preload/e2ePdfPreviewSizeLimit.ts
  • src/ui/components/SettingsView/GeneralTab.tsx
  • src/ui/actions.ts
  • src/app/PersistableValues.ts
  • src/servers/preload/api.ts
  • src/ui/components/SettingsView/features/E2ePdfPreviewSizeLimit.tsx
🔇 Additional comments (9)
src/app/PersistableValues.ts (1)

109-115: LGTM!

Also applies to: 208-211

src/ui/actions.ts (1)

131-132: LGTM!

Also applies to: 271-271

src/store/rootReducer.ts (1)

24-24: LGTM!

Also applies to: 115-115

src/app/selectors.ts (1)

86-87: LGTM!

src/servers/preload/e2ePdfPreviewSizeLimit.ts (1)

3-4: LGTM!

src/servers/preload/api.ts (1)

21-21: LGTM!

Also applies to: 53-53, 100-100

src/ui/components/SettingsView/features/E2ePdfPreviewSizeLimit.tsx (1)

1-72: LGTM!

src/ui/components/SettingsView/GeneralTab.tsx (1)

5-5: LGTM!

Also applies to: 39-39

src/i18n/en.i18n.json (1)

339-342: LGTM!

Comment thread src/ui/reducers/e2ePdfPreviewSizeLimit.ts
@nazabucciarelli nazabucciarelli changed the title chore: add blob as allowed protocol for document viewer feat: add new setting for encrypted PDFs size limit for previews May 19, 2026
@nazabucciarelli nazabucciarelli requested a review from Copilot May 20, 2026 14:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an Electron-side setting and bridge method to control the maximum size (in MB) for PDF previews in end-to-end encrypted rooms, and expands the document viewer to accept blob: URLs so decrypted PDF blobs can be rendered in the embedded viewer.

Changes:

  • Added a persisted Redux setting (e2ePdfPreviewSizeLimit, default 10) with UI control in Settings > General.
  • Exposed the current limit via the preload bridge (RocketChatDesktop.getE2ePdfPreviewSizeLimit()).
  • Allowed blob: protocol in the document viewer open-window IPC handler.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/ui/reducers/e2ePdfPreviewSizeLimit.ts New reducer for storing the PDF preview size limit and loading it from persisted settings.
src/ui/components/SettingsView/GeneralTab.tsx Wires the new setting component into the General settings tab.
src/ui/components/SettingsView/features/E2ePdfPreviewSizeLimit.tsx New numeric input setting UI for the limit.
src/ui/actions.ts Adds the new UI action type and payload mapping.
src/store/rootReducer.ts Registers the new reducer in the root reducer.
src/servers/preload/e2ePdfPreviewSizeLimit.ts Adds a preload getter to read the setting from Redux safely.
src/servers/preload/api.ts Exposes the getter on the RocketChatDesktop preload API surface.
src/i18n/en.i18n.json Adds EN strings for the setting title/description.
src/documentViewer/ipc.ts Allows blob: URLs for opening the document viewer window.
src/app/selectors.ts Persists the new setting value as part of persistable values.
src/app/PersistableValues.ts Adds migration to introduce e2ePdfPreviewSizeLimit with a default value.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/documentViewer/ipc.ts
Comment thread src/ui/reducers/e2ePdfPreviewSizeLimit.ts Outdated
Comment thread src/ui/components/SettingsView/features/E2ePdfPreviewSizeLimit.tsx
Comment thread src/app/PersistableValues.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants