From a705e606d1ed6431c7f1445031ccdf8583e7efb3 Mon Sep 17 00:00:00 2001 From: Terence Zafindratafa Date: Mon, 3 Jun 2024 08:28:04 +0200 Subject: [PATCH] fixup! fixup! TW-1702: update room operator override to fit nullsafety requirements --- .../download_manager/download_manager.dart | 24 +++++++++---------- .../manager/storage_directory_manager.dart | 2 -- .../mixins/download_file_on_mobile_mixin.dart | 4 +--- ...nload_file_on_mobile_mixin_test.mocks.dart | 24 ++++++------------- ...download_file_on_web_mixin_test.mocks.dart | 24 ++++++------------- 5 files changed, 27 insertions(+), 51 deletions(-) diff --git a/lib/utils/manager/download_manager/download_manager.dart b/lib/utils/manager/download_manager/download_manager.dart index 4f828da0b0..a283163d0a 100644 --- a/lib/utils/manager/download_manager/download_manager.dart +++ b/lib/utils/manager/download_manager/download_manager.dart @@ -26,14 +26,14 @@ class DownloadManager { final workingQueue = getIt.get(); - final Map eventIdMapDownloadFileInfo = {}; + final Map _eventIdMapDownloadFileInfo = {}; void cancelDownload(String eventId) { - final cancelToken = eventIdMapDownloadFileInfo[eventId]?.cancelToken; + final cancelToken = _eventIdMapDownloadFileInfo[eventId]?.cancelToken; if (cancelToken != null) { try { cancelToken.cancel(); - eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( + _eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( Left( DownloadFileFailureState( exception: CancelDownloadingException(), @@ -44,7 +44,7 @@ class DownloadManager { Logs().e( 'DownloadManager::cancelDownload(): $e', ); - eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( + _eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( Left( DownloadFileFailureState(exception: e), ), @@ -60,7 +60,7 @@ class DownloadManager { ) { final streamController = StreamController>(); - eventIdMapDownloadFileInfo[event.eventId] = DownloadFileInfo( + _eventIdMapDownloadFileInfo[event.eventId] = DownloadFileInfo( eventId: event.eventId, cancelToken: CancelToken(), downloadStateStreamController: streamController, @@ -69,25 +69,25 @@ class DownloadManager { } Stream>? getDownloadStateStream(String eventId) { - return eventIdMapDownloadFileInfo[eventId]?.downloadStream; + return _eventIdMapDownloadFileInfo[eventId]?.downloadStream; } Future clear(String eventId) async { try { - await eventIdMapDownloadFileInfo[eventId] + await _eventIdMapDownloadFileInfo[eventId] ?.downloadStateStreamController .close(); } catch (e) { Logs().e( 'DownloadManager::_clear(): $e', ); - eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( + _eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add( Left( DownloadFileFailureState(exception: e), ), ); } finally { - eventIdMapDownloadFileInfo.remove(eventId); + _eventIdMapDownloadFileInfo.remove(eventId); Logs().i( 'DownloadManager::clear with $eventId successfully', ); @@ -100,14 +100,14 @@ class DownloadManager { bool isFirstPriority = false, }) async { _initDownloadFileInfo(event); - final streamController = eventIdMapDownloadFileInfo[event.eventId] + final streamController = _eventIdMapDownloadFileInfo[event.eventId] ?.downloadStateStreamController; - final cancelToken = eventIdMapDownloadFileInfo[event.eventId]?.cancelToken; + final cancelToken = _eventIdMapDownloadFileInfo[event.eventId]?.cancelToken; if (streamController == null || cancelToken == null) { Logs().e( 'DownloadManager::download(): streamController or cancelToken is null', ); - eventIdMapDownloadFileInfo[event.eventId] + _eventIdMapDownloadFileInfo[event.eventId] ?.downloadStateStreamController .add( Left( diff --git a/lib/utils/manager/storage_directory_manager.dart b/lib/utils/manager/storage_directory_manager.dart index 6cb8bc6913..a45902f8f5 100644 --- a/lib/utils/manager/storage_directory_manager.dart +++ b/lib/utils/manager/storage_directory_manager.dart @@ -13,8 +13,6 @@ class StorageDirectoryManager { static StorageDirectoryManager get instance => _instance; - factory StorageDirectoryManager() => _instance; - Future getFileStoreDirectory() async { try { try { diff --git a/lib/widgets/mixins/download_file_on_mobile_mixin.dart b/lib/widgets/mixins/download_file_on_mobile_mixin.dart index 11a1db8228..2f6db249b7 100644 --- a/lib/widgets/mixins/download_file_on_mobile_mixin.dart +++ b/lib/widgets/mixins/download_file_on_mobile_mixin.dart @@ -18,8 +18,6 @@ import 'package:matrix/matrix.dart'; mixin DownloadFileOnMobileMixin on State { final downloadManager = getIt.get(); - final storageDirectoryManager = StorageDirectoryManager(); - final downloadFileStateNotifier = ValueNotifier( const NotDownloadPresentationState(), ); @@ -69,7 +67,7 @@ mixin DownloadFileOnMobileMixin on State { } Future checkFileInDownloadsInApp() async { - final filePath = await storageDirectoryManager.getFilePathInAppDownloads( + final filePath = await StorageDirectoryManager.instance.getFilePathInAppDownloads( eventId: event.eventId, fileName: event.filename, ); diff --git a/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart b/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart index 8db9968b6c..921c812633 100644 --- a/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart +++ b/test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart @@ -8,16 +8,14 @@ import 'dart:convert' as _i6; import 'dart:io' as _i2; import 'dart:typed_data' as _i7; -import 'package:dartz/dartz.dart' as _i10; -import 'package:fluffychat/app_state/failure.dart' as _i11; -import 'package:fluffychat/app_state/success.dart' as _i12; -import 'package:fluffychat/utils/manager/download_manager/download_file_info.dart' - as _i9; +import 'package:dartz/dartz.dart' as _i9; +import 'package:fluffychat/app_state/failure.dart' as _i10; +import 'package:fluffychat/app_state/success.dart' as _i11; import 'package:fluffychat/utils/manager/download_manager/download_manager.dart' as _i8; import 'package:fluffychat/utils/manager/download_manager/downloading_worker_queue.dart' as _i3; -import 'package:matrix/matrix.dart' as _i13; +import 'package:matrix/matrix.dart' as _i12; import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/src/dummies.dart' as _i4; @@ -994,14 +992,6 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { ), ) as _i3.DownloadWorkerQueue); - @override - Map get eventIdMapDownloadFileInfo => - (super.noSuchMethod( - Invocation.getter(#eventIdMapDownloadFileInfo), - returnValue: {}, - returnValueForMissingStub: {}, - ) as Map); - @override void cancelDownload(String? eventId) => super.noSuchMethod( Invocation.method( @@ -1012,7 +1002,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { ); @override - _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>? getDownloadStateStream( + _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>? getDownloadStateStream( String? eventId) => (super.noSuchMethod( Invocation.method( @@ -1020,7 +1010,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { [eventId], ), returnValueForMissingStub: null, - ) as _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>?); + ) as _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>?); @override _i5.Future clear(String? eventId) => (super.noSuchMethod( @@ -1034,7 +1024,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { @override _i5.Future download({ - required _i13.Event? event, + required _i12.Event? event, bool? getThumbnail = false, bool? isFirstPriority = false, }) => diff --git a/test/mixin/download/download_file_on_web_mixin_test.mocks.dart b/test/mixin/download/download_file_on_web_mixin_test.mocks.dart index dfaf094139..3f00dd45f7 100644 --- a/test/mixin/download/download_file_on_web_mixin_test.mocks.dart +++ b/test/mixin/download/download_file_on_web_mixin_test.mocks.dart @@ -8,16 +8,14 @@ import 'dart:convert' as _i6; import 'dart:io' as _i2; import 'dart:typed_data' as _i7; -import 'package:dartz/dartz.dart' as _i10; -import 'package:fluffychat/app_state/failure.dart' as _i11; -import 'package:fluffychat/app_state/success.dart' as _i12; -import 'package:fluffychat/utils/manager/download_manager/download_file_info.dart' - as _i9; +import 'package:dartz/dartz.dart' as _i9; +import 'package:fluffychat/app_state/failure.dart' as _i10; +import 'package:fluffychat/app_state/success.dart' as _i11; import 'package:fluffychat/utils/manager/download_manager/download_manager.dart' as _i8; import 'package:fluffychat/utils/manager/download_manager/downloading_worker_queue.dart' as _i3; -import 'package:matrix/matrix.dart' as _i13; +import 'package:matrix/matrix.dart' as _i12; import 'package:mockito/mockito.dart' as _i1; import 'package:mockito/src/dummies.dart' as _i4; @@ -994,14 +992,6 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { ), ) as _i3.DownloadWorkerQueue); - @override - Map get eventIdMapDownloadFileInfo => - (super.noSuchMethod( - Invocation.getter(#eventIdMapDownloadFileInfo), - returnValue: {}, - returnValueForMissingStub: {}, - ) as Map); - @override void cancelDownload(String? eventId) => super.noSuchMethod( Invocation.method( @@ -1012,7 +1002,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { ); @override - _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>? getDownloadStateStream( + _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>? getDownloadStateStream( String? eventId) => (super.noSuchMethod( Invocation.method( @@ -1020,7 +1010,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { [eventId], ), returnValueForMissingStub: null, - ) as _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>?); + ) as _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>?); @override _i5.Future clear(String? eventId) => (super.noSuchMethod( @@ -1034,7 +1024,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager { @override _i5.Future download({ - required _i13.Event? event, + required _i12.Event? event, bool? getThumbnail = false, bool? isFirstPriority = false, }) =>