Skip to content

fix: file attachments not displayed on forwarded messages#7379

Open
OtavioStasiak wants to merge 7 commits into
developfrom
fix.file-attachments-not-displayed-on-fowarded-messages
Open

fix: file attachments not displayed on forwarded messages#7379
OtavioStasiak wants to merge 7 commits into
developfrom
fix.file-attachments-not-displayed-on-fowarded-messages

Conversation

@OtavioStasiak
Copy link
Copy Markdown
Contributor

@OtavioStasiak OtavioStasiak commented Jun 2, 2026

Proposed changes

When a message containing a file attachment (PDF, document, etc.) is forwarded to another room or
user, the file was not displayed on iOS and Android — only the text part of the message was
visible. The same forwarded message rendered correctly on web and desktop.

Root cause

A forwarded message wraps the original message as a nested attachment:

  attachments: [{
    author_name: 'rocket.cat', message_link: '...', text: '',
    attachments: [{ type: 'file', title: 'document.pdf', title_link: '...' }] // the real file
  }]

At the top level, Message.tsx renders both and over the same array. These use
complementary filters that partition attachments between them: handles quote-style
attachments (plain files, documents, text replies) and handles media
(image/audio/video/actions/nested). Together they cover everything.

But inside Reply.tsx (the component that renders the forwarded wrapper), the nested attachments
were passed only to . Its removeQuote filter keeps media only, so a nested plain
file/document — which has no image_url/audio_url/video_url — was silently dropped. Images survived
solely because they carry image_url, which is why the bug looked file-type dependent.

Issue(s)

Closes #7363
https://rocketchat.atlassian.net/browse/NATIVE-1231

How to test or reproduce

  • Open the app;
  • Send a attachment in a room;
  • Forward the attachment to another room;

Screenshots

Before After
Simulator Screenshot - iPhone 16 - 2026-06-02 at 20 02 51 Simulator Screenshot - iPhone 16 - 2026-06-02 at 19 59 13

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

Summary by CodeRabbit

  • New Features

    • Replies now show quoted content from the original message for clearer context.
    • Forwarded/nested attachments (audio, video, files) are better recognized and displayed in message examples.
  • Bug Fixes / Improvements

    • Attachment handling improved to more reliably separate quoted text from media/actions, reducing incorrect hides or misclassification.

@OtavioStasiak OtavioStasiak marked this pull request as ready for review June 2, 2026 23:05
@OtavioStasiak OtavioStasiak temporarily deployed to approve_e2e_testing June 2, 2026 23:05 — with GitHub Actions Inactive
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

Walkthrough

Reply now renders Quote to display forwarded message attachments; attachment classification predicates were centralized into utils with tests; storybook entries added for nested forwarded audio, video, and double-forwarded file cases (normal and large-font).

Changes

Forwarded Message Quote Display

Layer / File(s) Summary
Attachment predicates and tests
app/containers/message/Components/Attachments/utils.ts, app/containers/message/Components/Attachments/utils.test.ts
Adds isQuoteAttachment and isContentAttachment predicates and unit tests that validate classification across attachment shapes.
Components updated to use predicates
app/containers/message/Components/Attachments/Attachments.tsx, app/containers/message/Components/Attachments/Quote.tsx
Attachments and Quote now import and use the shared predicate helpers instead of local inline predicates.
Quote component integration in Reply
app/containers/message/Components/Attachments/Reply.tsx
Reply imports Quote and renders it with attachment.attachments, getCustomEmoji, timeFormat, and showAttachment props before rendering Attachments.
Story test coverage for forwarded attachments
app/containers/message/Message.stories.tsx
Story definitions expanded with forwarded message scenarios (nested audio, nested video, double-forwarded file) for both normal and large-font message story variants.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: bug

🚥 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 title clearly and accurately summarizes the main change: fixing file attachments not being displayed on forwarded messages, which is the core objective of this PR.
Linked Issues check ✅ Passed The code changes comprehensively address the linked issue #7363 objectives: identifying and fixing the nested attachment filtering logic to ensure file attachments in forwarded messages display on mobile, with new test coverage.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing nested attachment rendering: Reply.tsx renders Quote component, utils extract attachment predicates, Attachments.tsx uses new filters, Quote.tsx uses extracted predicates, and stories/tests provide comprehensive coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 (2)
  • NATIVE-1231: Request failed with status code 401
  • CF4E-4978: 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.

@OtavioStasiak OtavioStasiak changed the title fix: file attachments not displayed on forwarded messages regression: file attachments not displayed on forwarded messages Jun 2, 2026
@OtavioStasiak OtavioStasiak changed the title regression: file attachments not displayed on forwarded messages fix: file attachments not displayed on forwarded messages Jun 2, 2026
@OtavioStasiak OtavioStasiak temporarily deployed to approve_e2e_testing June 3, 2026 16:01 — with GitHub Actions Inactive
Comment thread app/containers/message/Components/Attachments/Reply.tsx
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 `@app/containers/message/Components/Attachments/utils.ts`:
- Line 11: The predicates drop attachments with collapsed: false because they
check collapsed by truthiness (e.g., if (file.collapsed) or !!file.collapsed);
change these checks in isContentAttachment (and the other predicate at the
second occurrence) to test for the presence of the boolean instead (e.g., typeof
file.collapsed === 'boolean' or file.collapsed !== undefined) so attachments
with collapsed: false are preserved and will reach the Attachments branch that
expects a boolean collapsed flag.
🪄 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: c09fb9de-dfb7-4975-b466-cfd6e2aad307

📥 Commits

Reviewing files that changed from the base of the PR and between 831d086 and a420edc.

⛔ Files ignored due to path filters (1)
  • app/containers/message/__snapshots__/Message.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • app/containers/message/Components/Attachments/Attachments.tsx
  • app/containers/message/Components/Attachments/Quote.tsx
  • app/containers/message/Components/Attachments/utils.test.ts
  • app/containers/message/Components/Attachments/utils.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: ESLint and Test / run-eslint-and-test
  • GitHub Check: format
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts,jsx,tsx}: Use descriptive names for functions, variables, and classes that clearly convey their purpose
Write comments that explain the 'why' behind code decisions, not the 'what'
Keep functions small and focused on a single responsibility
Use const by default, let when reassignment is needed, and avoid var
Prefer async/await over .then() chains for handling asynchronous operations
Use explicit error handling with try/catch blocks for async operations
Avoid deeply nested code; refactor complex logic into helper functions

Files:

  • app/containers/message/Components/Attachments/utils.test.ts
  • app/containers/message/Components/Attachments/Quote.tsx
  • app/containers/message/Components/Attachments/Attachments.tsx
  • app/containers/message/Components/Attachments/utils.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript for type safety; add explicit type annotations to function parameters and return types
Prefer interfaces over type aliases for defining object shapes in TypeScript
Use enums for sets of related constants rather than magic strings or numbers

Use TypeScript with strict mode and baseUrl set to app/ for import resolution

Files:

  • app/containers/message/Components/Attachments/utils.test.ts
  • app/containers/message/Components/Attachments/Quote.tsx
  • app/containers/message/Components/Attachments/Attachments.tsx
  • app/containers/message/Components/Attachments/utils.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: Use Prettier with tabs, single quotes, 130 char width, no trailing commas, arrow parens avoid, bracket same line
Use @rocket.chat/eslint-config base with React, React Native, TypeScript, Jest plugins

Files:

  • app/containers/message/Components/Attachments/utils.test.ts
  • app/containers/message/Components/Attachments/Quote.tsx
  • app/containers/message/Components/Attachments/Attachments.tsx
  • app/containers/message/Components/Attachments/utils.ts
app/containers/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Reusable UI components should be placed in app/containers/ directory

Files:

  • app/containers/message/Components/Attachments/utils.test.ts
  • app/containers/message/Components/Attachments/Quote.tsx
  • app/containers/message/Components/Attachments/Attachments.tsx
  • app/containers/message/Components/Attachments/utils.ts
🧠 Learnings (1)
📚 Learning: 2026-04-30T17:07:51.020Z
Learnt from: diegolmello
Repo: RocketChat/Rocket.Chat.ReactNative PR: 7274
File: app/lib/services/voip/MediaCallEvents.ts:0-0
Timestamp: 2026-04-30T17:07:51.020Z
Learning: In this Rocket.Chat React Native codebase, the ESLint rule `no-void: error` is enforced. When you see a promise returned from an async call that is not awaited (a “floating promise”), do not silence it with the `void somePromise()` pattern. Instead, handle the promise explicitly by attaching `.catch(...)` (or otherwise awaiting/handling the error) so unhandled-rejection risks are addressed in a way that satisfies the existing ESLint configuration.

Applied to files:

  • app/containers/message/Components/Attachments/utils.test.ts
  • app/containers/message/Components/Attachments/Quote.tsx
  • app/containers/message/Components/Attachments/Attachments.tsx
  • app/containers/message/Components/Attachments/utils.ts
🔇 Additional comments (3)
app/containers/message/Components/Attachments/utils.test.ts (1)

4-56: LGTM!

app/containers/message/Components/Attachments/Attachments.tsx (1)

14-14: LGTM!

Also applies to: 22-22

app/containers/message/Components/Attachments/Quote.tsx (1)

10-10: LGTM!

Also applies to: 18-18

export const isQuoteAttachment = (file?: IAttachment): boolean => {
if (!file) return false;

if (file.collapsed) return false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Confirm collapsed: false attachments aren't silently dropped.

Both predicates treat collapsed by truthiness (if (file.collapsed) and !!file.collapsed), but the Attachments render branch keys off typeof file.collapsed === 'boolean' (Attachments.tsx Line 72), i.e. it intends to render CollapsibleQuote for both true and false. With the new filter, an attachment whose only "content" signal is collapsed: false (no media/actions/nested) returns false from isContentAttachment and gets filtered out before reaching that branch — so at the top level (where only Attachments runs, not Quote) it would render nothing. If the previous removeQuote kept such items, this is a regression.

If confirmed, align the predicates with the render branch:

🔧 Possible fix
-	if (file.collapsed) return false;
+	if (typeof file.collapsed === 'boolean') return false;
-	return hasOwnMedia(file) || !!file.collapsed || !!file.actions?.length || !!file.attachments?.length;
+	return hasOwnMedia(file) || typeof file.collapsed === 'boolean' || !!file.actions?.length || !!file.attachments?.length;

Verify the previous removeQuote predicate's collapsed handling:

#!/bin/bash
# Inspect prior implementation of removeQuote to compare collapsed handling
git log --oneline -5 -- app/containers/message/Components/Attachments/Attachments.tsx
git show HEAD~1:app/containers/message/Components/Attachments/Attachments.tsx 2>/dev/null | rg -n -B2 -A15 'removeQuote'

Also applies to: 35-35

🤖 Prompt for 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.

In `@app/containers/message/Components/Attachments/utils.ts` at line 11, The
predicates drop attachments with collapsed: false because they check collapsed
by truthiness (e.g., if (file.collapsed) or !!file.collapsed); change these
checks in isContentAttachment (and the other predicate at the second occurrence)
to test for the presence of the boolean instead (e.g., typeof file.collapsed ===
'boolean' or file.collapsed !== undefined) so attachments with collapsed: false
are preserved and will reach the Attachments branch that expects a boolean
collapsed flag.

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.

bug: File attachments not displayed in forwarded messages on mobile

2 participants