mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-23 01:06:21 +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 'dart:convert';
|
||||||
|
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
|
import 'package:nc_photos/stream_extension.dart';
|
||||||
import 'package:nc_photos_plugin/nc_photos_plugin.dart';
|
import 'package:nc_photos_plugin/nc_photos_plugin.dart';
|
||||||
|
|
||||||
class NativeEventListener<T> {
|
class NativeEventListener<T> {
|
||||||
|
@ -12,10 +13,7 @@ class NativeEventListener<T> {
|
||||||
_log.warning("[begin] Already listening");
|
_log.warning("[begin] Already listening");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_subscription = _mappedStream
|
_subscription = _mappedStream.whereType<T>().listen(listener);
|
||||||
.where((event) => event is T)
|
|
||||||
.cast<T>()
|
|
||||||
.listen(listener);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void end() {
|
void end() {
|
||||||
|
@ -28,7 +26,7 @@ class NativeEventListener<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
static late final _mappedStream =
|
static late final _mappedStream =
|
||||||
NativeEvent.stream.where((event) => event is NativeEventObject).map((ev) {
|
NativeEvent.stream.whereType<NativeEventObject>().map((ev) {
|
||||||
switch (ev.event) {
|
switch (ev.event) {
|
||||||
case FileExifUpdatedEvent._id:
|
case FileExifUpdatedEvent._id:
|
||||||
return FileExifUpdatedEvent.fromEvent(ev);
|
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/entity/file.dart';
|
||||||
import 'package:nc_photos/event/event.dart';
|
import 'package:nc_photos/event/event.dart';
|
||||||
import 'package:nc_photos/iterable_extension.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_album.dart';
|
||||||
import 'package:nc_photos/use_case/list_share.dart';
|
import 'package:nc_photos/use_case/list_share.dart';
|
||||||
import 'package:nc_photos/use_case/remove_from_album.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 {
|
Future<void> _cleanUpAlbums(Account account, List<File> removes) async {
|
||||||
final albums = await ListAlbum(_c)(account)
|
final albums = await ListAlbum(_c)(account).whereType<Album>().toList();
|
||||||
.where((event) => event is Album)
|
|
||||||
.cast<Album>()
|
|
||||||
.toList();
|
|
||||||
// figure out which files need to be unshared with whom
|
// figure out which files need to be unshared with whom
|
||||||
final unshares = <FileServerIdentityComparator, Set<CiString>>{};
|
final unshares = <FileServerIdentityComparator, Set<CiString>>{};
|
||||||
// clean up only make sense for static albums
|
// 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/album/provider.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/entity/share.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_album.dart';
|
||||||
import 'package:nc_photos/use_case/list_share.dart';
|
import 'package:nc_photos/use_case/list_share.dart';
|
||||||
import 'package:nc_photos/use_case/remove_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");
|
"[call] Unshare ${files.length} files from album '${album.name}' with ${unshareWith.length} users");
|
||||||
// list albums with shares identical to any element in [unshareWith]
|
// list albums with shares identical to any element in [unshareWith]
|
||||||
final otherAlbums = await ListAlbum(_c)(account)
|
final otherAlbums = await ListAlbum(_c)(account)
|
||||||
.where((event) => event is Album)
|
.whereType<Album>()
|
||||||
.cast<Album>()
|
|
||||||
.where((a) =>
|
.where((a) =>
|
||||||
!a.albumFile!.compareServerIdentity(album.albumFile!) &&
|
!a.albumFile!.compareServerIdentity(album.albumFile!) &&
|
||||||
a.provider is AlbumStaticProvider &&
|
a.provider is AlbumStaticProvider &&
|
||||||
|
|
Loading…
Reference in a new issue