-
Notifications
You must be signed in to change notification settings - Fork 373
fix(ui): correctly save videos to gallery on mobile #2386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit fixes an issue where videos downloaded from attachments were not correctly saved to the device's gallery on mobile platforms. The `saveFile` method in `StreamAttachmentHandler` now uses `Gal.putVideo` for video files and `Gal.putImage` for image files. If the file type is neither image nor video, it's saved to the app's directory without being copied to the gallery. Additionally, the temporary file is now only deleted if it was successfully copied to the gallery.
WalkthroughIntroduces mime-type based handling for saving attachments: images go to Gal.putImage, videos to Gal.putVideo, others are left untouched. Temporary files are deleted only after a successful gallery copy. Adds a CHANGELOG entry noting the mobile video save fix. No public APIs changed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant UI as Attachment UI
participant Handler as StreamAttachmentHandler (IO)
participant Gal as Gal plugin
User->>UI: Download attachment
UI->>Handler: downloadAttachment(file, mimeType)
alt mimeType starts with image/
Handler->>Gal: putImage(path)
Gal-->>Handler: success/failure
opt on success
Handler->>Handler: delete temp file
end
else mimeType starts with video/
Handler->>Gal: putVideo(path)
Gal-->>Handler: success/failure
opt on success
Handler->>Handler: delete temp file
end
else other mimeType
Handler-->>UI: return original path (no gallery copy, no delete)
end
Handler-->>UI: result (path or error)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ 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). (9)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/stream_chat_flutter/CHANGELOG.md (1)
6-7: Changelog entry looks good; consider tightening phrasing.Optional: “Fixed videos not being saved to the gallery on Android and iOS.” reads a bit tighter. Current entry is fine if you prefer existing style.
packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart (1)
201-206: Good MIME‑based routing; add a fallback whenmimeTypeis null.On some downloads
XFile.mimeTypecan be null. Fall back to inferring from the file path to avoid silently skipping gallery copy for valid images/videos.Apply within this hunk:
- final copyToGallery = switch (file.mimeType) { - final type? when type.startsWith('image/') => Gal.putImage, - final type? when type.startsWith('video/') => Gal.putVideo, - _ => null, - }; + final inferredMime = file.mimeType ?? lookupMimeType(path); + final copyToGallery = switch (inferredMime) { + final type? when type.startsWith('image/') => Gal.putImage, + final type? when type.startsWith('video/') => Gal.putVideo, + _ => null, + };Add the import (outside this hunk):
import 'package:mime/mime.dart';
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/stream_chat_flutter/CHANGELOG.md(1 hunks)packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart(1 hunks)
⏰ 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). (8)
- GitHub Check: analyze_legacy_versions
- GitHub Check: build (android)
- GitHub Check: test
- GitHub Check: stream_chat_localizations
- GitHub Check: analyze
- GitHub Check: stream_chat_flutter
- GitHub Check: stream_chat_flutter_core
- GitHub Check: stream_chat_persistence
🔇 Additional comments (1)
packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart (1)
207-213: Returned path may be deleted — confirm callers & API contractRepo search: callers in packages/stream_chat_flutter/lib/src/context_menu_items/download_menu_item.dart (call at ~line 28) and packages/stream_chat_flutter/lib/src/attachment/file_attachment.dart (call at ~line 186) invoke downloadAttachment(...) and ignore the returned path; tests mock downloadAttachment to return 'filePath'; the base contract (packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_base.dart:63) documents returning a file path. The IO impl (packages/stream_chat_flutter/lib/src/attachment/handler/stream_attachment_handler_io.dart — snippet that deletes the temp file after copying to gallery) still returns that now-deleted path.
Either stop deleting the temp file here (delegate cleanup) or change the API to return a structured result (e.g., {copiedToGallery: true, path}) and update the docs/tests to reflect that the returned path may be removed.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2386 +/- ##
==========================================
- Coverage 63.85% 63.84% -0.01%
==========================================
Files 413 413
Lines 25859 25862 +3
==========================================
Hits 16511 16511
- Misses 9348 9351 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Submit a pull request
Fixes: #2357
Description of the pull request
This PR fixes an issue where videos downloaded from attachments were not correctly saved to the device's gallery on mobile platforms.
The
saveFilemethod inStreamAttachmentHandlernow usesGal.putVideofor video files andGal.putImagefor image files. If the file type is neither image nor video, it's saved to the app's directory without being copied to the gallery.Additionally, the temporary file is now only deleted if it was successfully copied to the gallery.
Summary by CodeRabbit
Bug Fixes
Documentation