diff --git a/CHANGELOG.md b/CHANGELOG.md index 662859a..fa4742a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 0.1.0 +## 0.1.1 - New: Groups can now collect flames as well - New: Background execution to pre-load messages diff --git a/lib/src/database/daos/mediafiles.dao.dart b/lib/src/database/daos/mediafiles.dao.dart index 1bbcc54..7f4ff8c 100644 --- a/lib/src/database/daos/mediafiles.dao.dart +++ b/lib/src/database/daos/mediafiles.dao.dart @@ -26,8 +26,9 @@ class MediaFilesDao extends DatabaseAccessor final rowId = await into(mediaFiles).insert(insertMediaFile); - return await (select(mediaFiles)..where((t) => t.rowId.equals(rowId))) - .getSingle(); + return await (select( + mediaFiles, + )..where((t) => t.rowId.equals(rowId))).getSingle(); } catch (e) { Log.error('Could not insert media file: $e'); return null; @@ -35,10 +36,9 @@ class MediaFilesDao extends DatabaseAccessor } Future deleteMediaFile(String mediaId) async { - await (delete(mediaFiles) - ..where( - (t) => t.mediaId.equals(mediaId), - )) + await (delete(mediaFiles)..where( + (t) => t.mediaId.equals(mediaId), + )) .go(); } @@ -46,8 +46,9 @@ class MediaFilesDao extends DatabaseAccessor String mediaId, MediaFilesCompanion updates, ) async { - await (update(mediaFiles)..where((c) => c.mediaId.equals(mediaId))) - .write(updates); + await (update( + mediaFiles, + )..where((c) => c.mediaId.equals(mediaId))).write(updates); } Future updateAllMediaFiles( @@ -57,14 +58,15 @@ class MediaFilesDao extends DatabaseAccessor } Future getMediaFileById(String mediaId) async { - return (select(mediaFiles)..where((t) => t.mediaId.equals(mediaId))) - .getSingleOrNull(); + return (select( + mediaFiles, + )..where((t) => t.mediaId.equals(mediaId))).getSingleOrNull(); } Future getDraftMediaFile() async { - final medias = await (select(mediaFiles) - ..where((t) => t.isDraftMedia.equals(true))) - .get(); + final medias = await (select( + mediaFiles, + )..where((t) => t.isDraftMedia.equals(true))).get(); if (medias.isEmpty) { return null; } @@ -72,65 +74,62 @@ class MediaFilesDao extends DatabaseAccessor } Stream watchMedia(String mediaId) { - return (select(mediaFiles)..where((t) => t.mediaId.equals(mediaId))) - .watchSingleOrNull(); + return (select( + mediaFiles, + )..where((t) => t.mediaId.equals(mediaId))).watchSingleOrNull(); } Future resetPendingDownloadState() async { - await (update(mediaFiles) - ..where( - (c) => c.downloadState.equals( - DownloadState.downloading.name, - ), - )) + await (update(mediaFiles)..where( + (c) => c.downloadState.equals( + DownloadState.downloading.name, + ), + )) .write( - const MediaFilesCompanion( - downloadState: Value(DownloadState.pending), - ), - ); + const MediaFilesCompanion( + downloadState: Value(DownloadState.pending), + ), + ); } Future> getAllMediaFilesPendingDownload() async { - return (select(mediaFiles) - ..where( - (t) => - t.downloadState.equals(DownloadState.pending.name) | - t.downloadState.equals(DownloadState.downloading.name), - )) + return (select(mediaFiles)..where( + (t) => + t.downloadState.equals(DownloadState.pending.name) | + t.downloadState.equals(DownloadState.downloading.name), + )) .get(); } Future> getAllMediaFilesReuploadRequested() async { - return (select(mediaFiles) - ..where( - (t) => t.downloadState.equals(DownloadState.reuploadRequested.name), - )) + return (select(mediaFiles)..where( + (t) => t.downloadState.equals(DownloadState.reuploadRequested.name), + )) .get(); } Future> getAllNonHashedStoredMediaFiles() async { - return (select(mediaFiles) - ..where( - (t) => t.stored.equals(true) & t.storedFileHash.isNull(), - )) + return (select(mediaFiles)..where( + (t) => t.stored.equals(true) & t.storedFileHash.isNull(), + )) .get(); } Future> getAllMediaFilesPendingUpload() async { - return (select(mediaFiles) - ..where( - (t) => (t.uploadState.equals(UploadState.initialized.name) | - t.uploadState.equals(UploadState.uploadLimitReached.name) | - t.uploadState.equals(UploadState.uploading.name) | - t.uploadState.equals(UploadState.preprocessing.name)), - )) + return (select(mediaFiles)..where( + (t) => + (t.uploadState.equals(UploadState.initialized.name) | + t.uploadState.equals(UploadState.uploadLimitReached.name) | + t.uploadState.equals(UploadState.uploading.name) | + t.uploadState.equals(UploadState.preprocessing.name)), + )) .get(); } Stream> watchAllStoredMediaFiles() { - final query = (select(mediaFiles)..where((t) => t.stored.equals(true))) - .join([]) - ..groupBy([mediaFiles.storedFileHash]); + final query = + (select(mediaFiles)..where((t) => t.stored.equals(true))).join([]) + ..groupBy([mediaFiles.storedFileHash]); return query.map((row) => row.readTable(mediaFiles)).watch(); } @@ -142,16 +141,15 @@ class MediaFilesDao extends DatabaseAccessor } Future updateAllRetransmissionUploadingState() async { - await (update(mediaFiles) - ..where( - (t) => - t.uploadState.equals(UploadState.uploading.name) & - t.reuploadRequestedBy.isNotNull(), - )) + await (update(mediaFiles)..where( + (t) => + t.uploadState.equals(UploadState.uploading.name) & + t.reuploadRequestedBy.isNotNull(), + )) .write( - const MediaFilesCompanion( - uploadState: Value(UploadState.preprocessing), - ), - ); + const MediaFilesCompanion( + uploadState: Value(UploadState.preprocessing), + ), + ); } } diff --git a/lib/src/services/api/mediafiles/upload.service.dart b/lib/src/services/api/mediafiles/upload.service.dart index 468533c..c15ae6c 100644 --- a/lib/src/services/api/mediafiles/upload.service.dart +++ b/lib/src/services/api/mediafiles/upload.service.dart @@ -30,10 +30,9 @@ Future finishStartedPreprocessing() async { final mediaFiles = await twonlyDB.mediaFilesDao .getAllMediaFilesPendingUpload(); - Log.info('There are ${mediaFiles.length} media files pending'); - for (final mediaFile in mediaFiles) { if (mediaFile.isDraftMedia) { + Log.info('Ignoring media files as it is a draft'); continue; } try { @@ -51,6 +50,9 @@ Future finishStartedPreprocessing() async { await twonlyDB.mediaFilesDao.deleteMediaFile(mediaFile.mediaId); continue; } + Log.info( + 'Finishing started preprocessing of ${mediaFile.mediaId} in state ${mediaFile.uploadState}.', + ); await startBackgroundMediaUpload(service); } catch (e) { Log.warn(e); diff --git a/lib/src/services/background/callback_dispatcher.background.dart b/lib/src/services/background/callback_dispatcher.background.dart index 15838fa..94980df 100644 --- a/lib/src/services/background/callback_dispatcher.background.dart +++ b/lib/src/services/background/callback_dispatcher.background.dart @@ -51,16 +51,16 @@ void callbackDispatcher() { Future initBackgroundExecution() async { SentryWidgetsFlutterBinding.ensureInitialized(); + globalApplicationCacheDirectory = (await getApplicationCacheDirectory()).path; + globalApplicationSupportDirectory = + (await getApplicationSupportDirectory()).path; + initLogger(); final user = await getUser(); if (user == null) return false; gUser = user; - globalApplicationCacheDirectory = (await getApplicationCacheDirectory()).path; - globalApplicationSupportDirectory = - (await getApplicationSupportDirectory()).path; - twonlyDB = TwonlyDB(); apiService = ApiService(); globalIsInBackgroundTask = true; @@ -92,7 +92,7 @@ Future handlePeriodicTask() async { await KeyValueStore.put(KeyValueKeys.lastPeriodicTaskExecution, { 'timestamp': DateTime.now().millisecondsSinceEpoch, }); - return false; + return true; }, ); diff --git a/pubspec.yaml b/pubspec.yaml index 7b07725..db27196 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: "twonly, a privacy-friendly way to connect with friends through sec publish_to: 'none' -version: 0.1.0+100 +version: 0.1.1+101 environment: sdk: ^3.11.0