mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 18:38:48 +01:00
Only reacts to events of the same account
This commit is contained in:
parent
c63b473034
commit
5e8c8a1fde
2 changed files with 37 additions and 15 deletions
|
@ -127,4 +127,15 @@ class AccountSettings with EquatableMixin {
|
|||
|
||||
extension AccountExtension on Account {
|
||||
String get url => "$scheme://$address";
|
||||
|
||||
/// Compare the server identity of two Accounts
|
||||
///
|
||||
/// Return true if two Accounts point to the same user on server. Be careful
|
||||
/// that this does NOT mean that the two Accounts are identical (e.g., they
|
||||
/// can have difference password)
|
||||
bool compareServerIdentity(Account other) {
|
||||
return scheme == other.scheme &&
|
||||
address == other.address &&
|
||||
username == other.username;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,18 +182,21 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
|
|||
// no data in this bloc, ignore
|
||||
return;
|
||||
}
|
||||
if (_isAccountOfInterest(ev.account)) {
|
||||
_refreshThrottler.trigger(
|
||||
maxResponceTime: const Duration(seconds: 3),
|
||||
maxPendingCount: 10,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _onFileRemovedEvent(FileRemovedEvent ev) {
|
||||
if (state is ListAlbumBlocInit) {
|
||||
// no data in this bloc, ignore
|
||||
return;
|
||||
}
|
||||
if (file_util.isAlbumFile(ev.account, ev.file)) {
|
||||
if (_isAccountOfInterest(ev.account) &&
|
||||
file_util.isAlbumFile(ev.account, ev.file)) {
|
||||
_refreshThrottler.trigger(
|
||||
maxResponceTime: const Duration(seconds: 3),
|
||||
maxPendingCount: 10,
|
||||
|
@ -206,7 +209,8 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
|
|||
// no data in this bloc, ignore
|
||||
return;
|
||||
}
|
||||
if (ev.destination
|
||||
if (_isAccountOfInterest(ev.account) &&
|
||||
ev.destination
|
||||
.startsWith(remote_storage_util.getRemoteAlbumsDir(ev.account))) {
|
||||
_refreshThrottler.trigger(
|
||||
maxResponceTime: const Duration(seconds: 3),
|
||||
|
@ -220,8 +224,10 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
|
|||
// no data in this bloc, ignore
|
||||
return;
|
||||
}
|
||||
if (_isAccountOfInterest(ev.account)) {
|
||||
add(const _ListAlbumBlocExternalEvent());
|
||||
}
|
||||
}
|
||||
|
||||
void _onShareCreatedEvent(ShareCreatedEvent ev) =>
|
||||
_onShareChanged(ev.account, ev.share);
|
||||
|
@ -230,6 +236,7 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
|
|||
_onShareChanged(ev.account, ev.share);
|
||||
|
||||
void _onShareChanged(Account account, Share share) {
|
||||
if (_isAccountOfInterest(account)) {
|
||||
final webdavPath = file_util.unstripPath(account, share.path);
|
||||
if (webdavPath
|
||||
.startsWith(remote_storage_util.getRemoteAlbumsDir(account))) {
|
||||
|
@ -239,6 +246,7 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<ListAlbumBlocState> _queryOffline(ListAlbumBlocQuery ev) =>
|
||||
_queryWithAlbumDataSource(
|
||||
|
@ -303,6 +311,9 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
|
|||
}
|
||||
}
|
||||
|
||||
bool _isAccountOfInterest(Account account) =>
|
||||
state.account == null || state.account!.compareServerIdentity(account);
|
||||
|
||||
late AppEventListener<AlbumUpdatedEvent> _albumUpdatedListener;
|
||||
late AppEventListener<FileRemovedEvent> _fileRemovedListener;
|
||||
late AppEventListener<AlbumCreatedEvent> _albumCreatedListener;
|
||||
|
|
Loading…
Reference in a new issue