Only reacts to events of the same account

This commit is contained in:
Ming Ming 2021-11-21 21:48:30 +08:00
parent c63b473034
commit 5e8c8a1fde
2 changed files with 37 additions and 15 deletions

View file

@ -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;
}
}

View file

@ -182,10 +182,12 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
// no data in this bloc, ignore
return;
}
_refreshThrottler.trigger(
maxResponceTime: const Duration(seconds: 3),
maxPendingCount: 10,
);
if (_isAccountOfInterest(ev.account)) {
_refreshThrottler.trigger(
maxResponceTime: const Duration(seconds: 3),
maxPendingCount: 10,
);
}
}
void _onFileRemovedEvent(FileRemovedEvent ev) {
@ -193,7 +195,8 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
// 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,8 +209,9 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
// no data in this bloc, ignore
return;
}
if (ev.destination
.startsWith(remote_storage_util.getRemoteAlbumsDir(ev.account))) {
if (_isAccountOfInterest(ev.account) &&
ev.destination
.startsWith(remote_storage_util.getRemoteAlbumsDir(ev.account))) {
_refreshThrottler.trigger(
maxResponceTime: const Duration(seconds: 3),
maxPendingCount: 10,
@ -220,7 +224,9 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
// no data in this bloc, ignore
return;
}
add(const _ListAlbumBlocExternalEvent());
if (_isAccountOfInterest(ev.account)) {
add(const _ListAlbumBlocExternalEvent());
}
}
void _onShareCreatedEvent(ShareCreatedEvent ev) =>
@ -230,13 +236,15 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
_onShareChanged(ev.account, ev.share);
void _onShareChanged(Account account, Share share) {
final webdavPath = file_util.unstripPath(account, share.path);
if (webdavPath
.startsWith(remote_storage_util.getRemoteAlbumsDir(account))) {
_refreshThrottler.trigger(
maxResponceTime: const Duration(seconds: 3),
maxPendingCount: 10,
);
if (_isAccountOfInterest(account)) {
final webdavPath = file_util.unstripPath(account, share.path);
if (webdavPath
.startsWith(remote_storage_util.getRemoteAlbumsDir(account))) {
_refreshThrottler.trigger(
maxResponceTime: const Duration(seconds: 3),
maxPendingCount: 10,
);
}
}
}
@ -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;