Skip to content

Commit

Permalink
fixup! fixup! TW-1702: update room operator override to fit nullsafet…
Browse files Browse the repository at this point in the history
…y requirements
  • Loading branch information
Te-Z committed Jun 3, 2024
1 parent 7f6ebdc commit a705e60
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 51 deletions.
24 changes: 12 additions & 12 deletions lib/utils/manager/download_manager/download_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class DownloadManager {

final workingQueue = getIt.get<DownloadWorkerQueue>();

final Map<String, DownloadFileInfo> eventIdMapDownloadFileInfo = {};
final Map<String, DownloadFileInfo> _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(),
Expand All @@ -44,7 +44,7 @@ class DownloadManager {
Logs().e(
'DownloadManager::cancelDownload(): $e',
);
eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add(
_eventIdMapDownloadFileInfo[eventId]?.downloadStateStreamController.add(
Left(
DownloadFileFailureState(exception: e),
),
Expand All @@ -60,7 +60,7 @@ class DownloadManager {
) {
final streamController = StreamController<Either<Failure, Success>>();

eventIdMapDownloadFileInfo[event.eventId] = DownloadFileInfo(
_eventIdMapDownloadFileInfo[event.eventId] = DownloadFileInfo(
eventId: event.eventId,
cancelToken: CancelToken(),
downloadStateStreamController: streamController,
Expand All @@ -69,25 +69,25 @@ class DownloadManager {
}

Stream<Either<Failure, Success>>? getDownloadStateStream(String eventId) {
return eventIdMapDownloadFileInfo[eventId]?.downloadStream;
return _eventIdMapDownloadFileInfo[eventId]?.downloadStream;
}

Future<void> 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',
);
Expand All @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions lib/utils/manager/storage_directory_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class StorageDirectoryManager {

static StorageDirectoryManager get instance => _instance;

factory StorageDirectoryManager() => _instance;

Future<String> getFileStoreDirectory() async {
try {
try {
Expand Down
4 changes: 1 addition & 3 deletions lib/widgets/mixins/download_file_on_mobile_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import 'package:matrix/matrix.dart';
mixin DownloadFileOnMobileMixin<T extends StatefulWidget> on State<T> {
final downloadManager = getIt.get<DownloadManager>();

final storageDirectoryManager = StorageDirectoryManager();

final downloadFileStateNotifier = ValueNotifier<DownloadPresentationState>(
const NotDownloadPresentationState(),
);
Expand Down Expand Up @@ -69,7 +67,7 @@ mixin DownloadFileOnMobileMixin<T extends StatefulWidget> on State<T> {
}

Future<void> checkFileInDownloadsInApp() async {
final filePath = await storageDirectoryManager.getFilePathInAppDownloads(
final filePath = await StorageDirectoryManager.instance.getFilePathInAppDownloads(
eventId: event.eventId,
fileName: event.filename,
);
Expand Down
24 changes: 7 additions & 17 deletions test/mixin/download/download_file_on_mobile_mixin_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -994,14 +992,6 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager {
),
) as _i3.DownloadWorkerQueue);

@override
Map<String, _i9.DownloadFileInfo> get eventIdMapDownloadFileInfo =>
(super.noSuchMethod(
Invocation.getter(#eventIdMapDownloadFileInfo),
returnValue: <String, _i9.DownloadFileInfo>{},
returnValueForMissingStub: <String, _i9.DownloadFileInfo>{},
) as Map<String, _i9.DownloadFileInfo>);

@override
void cancelDownload(String? eventId) => super.noSuchMethod(
Invocation.method(
Expand All @@ -1012,15 +1002,15 @@ 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(
#getDownloadStateStream,
[eventId],
),
returnValueForMissingStub: null,
) as _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>?);
) as _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>?);

@override
_i5.Future<void> clear(String? eventId) => (super.noSuchMethod(
Expand All @@ -1034,7 +1024,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager {

@override
_i5.Future<void> download({
required _i13.Event? event,
required _i12.Event? event,
bool? getThumbnail = false,
bool? isFirstPriority = false,
}) =>
Expand Down
24 changes: 7 additions & 17 deletions test/mixin/download/download_file_on_web_mixin_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -994,14 +992,6 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager {
),
) as _i3.DownloadWorkerQueue);

@override
Map<String, _i9.DownloadFileInfo> get eventIdMapDownloadFileInfo =>
(super.noSuchMethod(
Invocation.getter(#eventIdMapDownloadFileInfo),
returnValue: <String, _i9.DownloadFileInfo>{},
returnValueForMissingStub: <String, _i9.DownloadFileInfo>{},
) as Map<String, _i9.DownloadFileInfo>);

@override
void cancelDownload(String? eventId) => super.noSuchMethod(
Invocation.method(
Expand All @@ -1012,15 +1002,15 @@ 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(
#getDownloadStateStream,
[eventId],
),
returnValueForMissingStub: null,
) as _i5.Stream<_i10.Either<_i11.Failure, _i12.Success>>?);
) as _i5.Stream<_i9.Either<_i10.Failure, _i11.Success>>?);

@override
_i5.Future<void> clear(String? eventId) => (super.noSuchMethod(
Expand All @@ -1034,7 +1024,7 @@ class MockDownloadManager extends _i1.Mock implements _i8.DownloadManager {

@override
_i5.Future<void> download({
required _i13.Event? event,
required _i12.Event? event,
bool? getThumbnail = false,
bool? isFirstPriority = false,
}) =>
Expand Down

0 comments on commit a705e60

Please sign in to comment.