[mob] Allow manual upload of videos when global video upload is disabled

This commit is contained in:
Neeraj Gupta 2024-04-09 09:32:37 +05:30
parent c6a0af7cbc
commit 7cec46ef3d
2 changed files with 29 additions and 1 deletions

View file

@ -52,6 +52,15 @@ class RemoteSyncService {
bool _isExistingSyncSilent = false;
static const kHasSyncedArchiveKey = "has_synced_archive";
/* This setting is used to maintain a list of local IDs for videos that the user has manually
marked for upload, even if the global video upload setting is currently disabled.
When the global video upload setting is disabled, we typically ignore all video uploads. However, for videos that have been added to this list, we
want to still allow them to be uploaded, despite the global setting being disabled.
This allows users to queue up videos for upload, and have them successfully upload
even if they later toggle the global video upload setting to disabled.
*/
static const _ignoreBackUpSettingsForIDs_ = "ignoreBackUpSettingsForIDs";
final String _isFirstRemoteSyncDone = "isFirstRemoteSyncDone";
// 28 Sept, 2021 9:03:20 AM IST
@ -189,6 +198,18 @@ class RemoteSyncService {
return _prefs.containsKey(_isFirstRemoteSyncDone);
}
Future<bool> whiteListVideoForUpload(EnteFile file) async {
if (file.fileType == FileType.video &&
!_config.shouldBackupVideos() &&
file.localID != null) {
final List<String> whitelistedIDs =
_prefs.getStringList(_ignoreBackUpSettingsForIDs_) ?? <String>[];
whitelistedIDs.add(file.localID!);
return _prefs.setStringList(_ignoreBackUpSettingsForIDs_, whitelistedIDs);
}
return false;
}
Future<void> _pullDiff() async {
_logger.info("Pulling remote diff");
final isFirstSync = !_collectionsService.hasSyncedCollections();
@ -524,8 +545,13 @@ class RemoteSyncService {
final List<EnteFile> filesToBeUploaded = [];
int ignoredForUpload = 0;
int skippedVideos = 0;
final whitelistedIDs =
(_prefs.getStringList(_ignoreBackUpSettingsForIDs_) ?? <String>[])
.toSet();
for (var file in originalFiles) {
if (shouldRemoveVideos && file.fileType == FileType.video) {
if (shouldRemoveVideos &&
(file.fileType == FileType.video &&
!whitelistedIDs.contains(file.localID))) {
skippedVideos++;
continue;
}

View file

@ -125,6 +125,8 @@ class _UpdateIconWidgetState extends State<UploadIconWidget> {
.id;
await FilesDB.instance.insert(widget.file);
}
await RemoteSyncService.instance
.whiteListVideoForUpload(widget.file);
RemoteSyncService.instance.sync().ignore();
if (mounted) {
setState(() {