mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Streamline code
This commit is contained in:
parent
c979d644e7
commit
843497a708
4 changed files with 10 additions and 11 deletions
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/stream_extension.dart';
|
||||
import 'package:nc_photos_plugin/nc_photos_plugin.dart';
|
||||
|
||||
class NativeEventListener<T> {
|
||||
|
@ -12,10 +13,7 @@ class NativeEventListener<T> {
|
|||
_log.warning("[begin] Already listening");
|
||||
return;
|
||||
}
|
||||
_subscription = _mappedStream
|
||||
.where((event) => event is T)
|
||||
.cast<T>()
|
||||
.listen(listener);
|
||||
_subscription = _mappedStream.whereType<T>().listen(listener);
|
||||
}
|
||||
|
||||
void end() {
|
||||
|
@ -28,7 +26,7 @@ class NativeEventListener<T> {
|
|||
}
|
||||
|
||||
static late final _mappedStream =
|
||||
NativeEvent.stream.where((event) => event is NativeEventObject).map((ev) {
|
||||
NativeEvent.stream.whereType<NativeEventObject>().map((ev) {
|
||||
switch (ev.event) {
|
||||
case FileExifUpdatedEvent._id:
|
||||
return FileExifUpdatedEvent.fromEvent(ev);
|
||||
|
|
3
app/lib/stream_extension.dart
Normal file
3
app/lib/stream_extension.dart
Normal file
|
@ -0,0 +1,3 @@
|
|||
extension StreamExtension on Stream {
|
||||
Stream<U> whereType<U>() => where((event) => event is U).cast<U>();
|
||||
}
|
|
@ -11,6 +11,7 @@ import 'package:nc_photos/entity/album/provider.dart';
|
|||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/event/event.dart';
|
||||
import 'package:nc_photos/iterable_extension.dart';
|
||||
import 'package:nc_photos/stream_extension.dart';
|
||||
import 'package:nc_photos/use_case/list_album.dart';
|
||||
import 'package:nc_photos/use_case/list_share.dart';
|
||||
import 'package:nc_photos/use_case/remove_from_album.dart';
|
||||
|
@ -54,10 +55,7 @@ class Remove {
|
|||
}
|
||||
|
||||
Future<void> _cleanUpAlbums(Account account, List<File> removes) async {
|
||||
final albums = await ListAlbum(_c)(account)
|
||||
.where((event) => event is Album)
|
||||
.cast<Album>()
|
||||
.toList();
|
||||
final albums = await ListAlbum(_c)(account).whereType<Album>().toList();
|
||||
// figure out which files need to be unshared with whom
|
||||
final unshares = <FileServerIdentityComparator, Set<CiString>>{};
|
||||
// clean up only make sense for static albums
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:nc_photos/entity/album/item.dart';
|
|||
import 'package:nc_photos/entity/album/provider.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/share.dart';
|
||||
import 'package:nc_photos/stream_extension.dart';
|
||||
import 'package:nc_photos/use_case/list_album.dart';
|
||||
import 'package:nc_photos/use_case/list_share.dart';
|
||||
import 'package:nc_photos/use_case/remove_share.dart';
|
||||
|
@ -35,8 +36,7 @@ class UnshareFileFromAlbum {
|
|||
"[call] Unshare ${files.length} files from album '${album.name}' with ${unshareWith.length} users");
|
||||
// list albums with shares identical to any element in [unshareWith]
|
||||
final otherAlbums = await ListAlbum(_c)(account)
|
||||
.where((event) => event is Album)
|
||||
.cast<Album>()
|
||||
.whereType<Album>()
|
||||
.where((a) =>
|
||||
!a.albumFile!.compareServerIdentity(album.albumFile!) &&
|
||||
a.provider is AlbumStaticProvider &&
|
||||
|
|
Loading…
Reference in a new issue