Convenient fn to check file owner

This commit is contained in:
Ming Ming 2021-07-22 14:16:56 +08:00
parent 002ede3392
commit dc5d6a4a8d
2 changed files with 4 additions and 4 deletions

View file

@ -415,6 +415,8 @@ extension FileExtension on File {
lastModified ?? lastModified ??
DateTime.now().toUtc(); DateTime.now().toUtc();
} }
bool isOwned(String username) => ownerId == null || ownerId == username;
} }
class FileRepo { class FileRepo {

View file

@ -586,8 +586,7 @@ class _AlbumViewerState extends State<AlbumViewer>
zip([_getAlbumItemsOf(album), _getAlbumItemsOf(widget.album)]).map((e) { zip([_getAlbumItemsOf(album), _getAlbumItemsOf(widget.album)]).map((e) {
if (e[0] is AlbumFileItem) { if (e[0] is AlbumFileItem) {
final item = e[0] as AlbumFileItem; final item = e[0] as AlbumFileItem;
if (item.file.ownerId != null && if (!item.file.isOwned(widget.account.username)) {
item.file.ownerId != widget.account.username) {
// don't propagate shared file not owned by this user, this is to // don't propagate shared file not owned by this user, this is to
// prevent multiple user having different properties to keep // prevent multiple user having different properties to keep
// overriding each others // overriding each others
@ -623,8 +622,7 @@ class _AlbumViewerState extends State<AlbumViewer>
final a = z[0], b = z[1]; final a = z[0], b = z[1];
bool isEqual; bool isEqual;
if (a is AlbumFileItem && b is AlbumFileItem) { if (a is AlbumFileItem && b is AlbumFileItem) {
if (a.file.ownerId != null && if (!a.file.isOwned(widget.account.username)) {
a.file.ownerId != widget.account.username) {
// ignore shared files // ignore shared files
continue; continue;
} }