RocketChat / RocketChat/Rocket.Chat.ReactNative

feature: Implement Download Caching for Chat Attachments

Open
#6,730 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

🎉 feature
Dominant language
TypeScript
Stars
2.4k
Forks
1.5k
Avg merge
1d 18h
Merged PRs (30d)
90

Description

Feature Description
  • Implement a caching system for chat attachment downloads that stores files locally after first download, allowing subsequent access to use cached versions instead of re-downloading. This will significantly improve user experience by reducing download times, saving data usage, and eliminating redundant downloads for the same file.

poc:-

https://github.com/user-attachments/assets/4e5d2f2e-fc7c-404a-96ac-92db54558df4

Motivation and Use Case

Current Problem:

  • Users must wait for full download every time they access an attachment (PDF, images, documents, etc.)
  • Multiple downloads occur for the same file if accessed multiple times
  • Unnecessary data usage and battery drain
  • Poor user experience with slow file access in chat

Use Cases:

  • Frequent Reference: Users accessing the same important documents multiple times during a work session
  • Offline Access: Users wanting to quickly access previously viewed files without internet
  • Data Conservation: Users on limited data plans wanting to avoid repeated downloads
  • Quick Review: Users rapidly switching between different attachments in a conversation
Implementation Ideas

Based on the current implementation provided:
export const fileDownload = async ( url: string, attachment?: IAttachment, fileName?: string ): Promise<string> => { let path = ${FileSystem.documentDirectory}; if (fileName) { path = ${path}${sanitizeFileName(fileName)}; } if (attachment?.title) { path = ${path}${sanitizeFileName(attachment.title)}`;
}

// Check if file exists in cache first using existing cache system
const cache = await getMediaCache({
type: 'other' as const,
mimeType: attachment?.format,
urlToCache: url
});

if (cache?.exists) {
return cache.uri; // Return cached file URI if exists
}

// Create download options for media file
const option = {
messageId: url,
type: 'other' as const,
downloadUrl: url
};

// Download file if not cached
const uri = await downloadMediaFile(option);
return uri;
};`

profile
Qwen3-Coder
12:47 am
Feature Request: Implement Download Caching for Chat Attachments
Feature Description
Implement a caching system for chat attachment downloads that stores files locally after first download, allowing subsequent access to use cached versions instead of re-downloading. This will significantly improve user experience by reducing download times, saving data usage, and eliminating redundant downloads for the same file.

Motivation and Use Case
Current Problem:

Users must wait for full download every time they access an attachment (PDF, images, documents, etc.)
Multiple downloads occur for the same file if accessed multiple times
Unnecessary data usage and battery drain
Poor user experience with slow file access in chat
Use Cases:

Frequent Reference: Users accessing the same important documents multiple times during a work session
Offline Access: Users wanting to quickly access previously viewed files without internet
Data Conservation: Users on limited data plans wanting to avoid repeated downloads
Quick Review: Users rapidly switching between different attachments in a conversation
Implementation Ideas
Based on the current implementation provided:

export const fileDownload = async (
 url: string, 
 attachment?: IAttachment, 
 fileName?:  string
): Promise<string> => {
 let path = `${FileSystem.documentDirectory}`;
 if (fileName) {
   path = `${path}${sanitizeFileName(fileName)}`;
 }
 if (attachment?.title) {
   path = `${path}${sanitizeFileName(attachment.title)}`;
 }

 // Check if file exists in cache first using existing cache system
 const cache = await getMediaCache({ 
   type: 'other' as const, 
   mimeType: attachment?.format, 
   urlToCache: url 
 });

 if (cache?.exists) {
   return cache.uri; // Return cached file URI if exists
 }
 
 // Create download options for media file
 const option = {
   messageId: url,
   type: 'other' as const,
   downloadUrl: url
 };

 // Download file if not cached
 const uri = await downloadMediaFile(option);
 return uri;
};

Key Implementation Benefits:

  • Leverages existing cache system: Uses the existing getMediaCache function for consistency
  • Simple cache check: Checks if file exists before initiating download
  • Integrates with existing download logic: Uses downloadMediaFile for actual download
  • Maintains backward compatibility: Works with existing attachment handling
  • Efficient: Only downloads when necessary, returns cached version otherwise
Is this feature available in the API or web version?

Available in API

Rocket.Chat Server Version

NA

Rocket.Chat App Version

4.66.0

Device Name

POCO M2 Pro

OS Version

Android

Additional Context

This feature will particularly benefit users who:

  • Work with document-heavy conversations
  • Have limited internet connectivity
  • Need quick access to frequently referenced files
  • Want to conserve mobile data usage

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the fileDownload entry point and read the existing getMediaCache and downloadMediaFile implementations, then trace how chat attachments invoke downloads. Done means a previously downloaded attachment is served from local cache on later access while uncached attachments still download normally; verify the behavior through the existing attachment flow.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
mobile
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.