Compare username ignoring case

This commit is contained in:
Ming Ming 2021-10-29 19:46:51 +08:00
parent 99b0286b81
commit 2ad844292a
7 changed files with 31 additions and 14 deletions

View file

@ -465,7 +465,7 @@ extension FileExtension on File {
}
bool isOwned(String username) =>
ownerId == null || ownerId?.toLowerCase() == username.toLowerCase();
ownerId == null || ownerId!.equalsIgnoreCase(username.toLowerCase());
/// Return the path of this file with the DAV part stripped
///

View file

@ -23,4 +23,6 @@ extension StringExtension on String {
String trimAny(String characters) {
return trimLeftAny(characters).trimRightAny(characters);
}
bool equalsIgnoreCase(String other) => toLowerCase() == other.toLowerCase();
}

View file

@ -3,6 +3,7 @@ import 'package:nc_photos/account.dart';
import 'package:nc_photos/app_db.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/string_extension.dart';
class FindFile {
/// Find the [File] in the DB by [fileId]
@ -18,7 +19,9 @@ class FindFile {
// find the one owned by us
final dbItem = dbItems.firstWhere((element) {
final e = AppDbFileDbEntry.fromJson(element.cast<String, dynamic>());
return file_util.getUserDirName(e.file) == account.username;
return file_util
.getUserDirName(e.file)
.equalsIgnoreCase(account.username);
});
final dbEntry = AppDbFileDbEntry.fromJson(dbItem.cast<String, dynamic>());
return dbEntry.file;

View file

@ -6,6 +6,7 @@ import 'package:nc_photos/entity/face.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception.dart';
import 'package:nc_photos/string_extension.dart';
class PopulatePerson {
/// Return a list of files of the faces
@ -37,7 +38,9 @@ class PopulatePerson {
try {
dbItem = dbItems.firstWhere((element) {
final e = AppDbFileDbEntry.fromJson(element.cast<String, dynamic>());
return file_util.getUserDirName(e.file) == account.username;
return file_util
.getUserDirName(e.file)
.equalsIgnoreCase(account.username);
});
} on StateError catch (_) {
// not found

View file

@ -7,6 +7,7 @@ import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/album/item.dart';
import 'package:nc_photos/entity/album/provider.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/string_extension.dart';
/// Resync files inside an album with the file db
class ResyncAlbum {
@ -52,7 +53,9 @@ class ResyncAlbum {
try {
dbItem = dbItems.firstWhere((element) {
final e = AppDbFileDbEntry.fromJson(element.cast<String, dynamic>());
return file_util.getUserDirName(e.file) == account.username;
return file_util
.getUserDirName(e.file)
.equalsIgnoreCase(account.username);
});
} on StateError catch (_) {
// not found

View file

@ -17,6 +17,7 @@ import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/string_extension.dart';
import 'package:nc_photos/theme.dart';
import 'package:nc_photos/use_case/remove.dart';
import 'package:nc_photos/use_case/remove_share.dart';
@ -127,7 +128,8 @@ class _SharedFileViewerState extends State<SharedFileViewer> {
title: Text(widget.file.strippedPath),
),
),
if (widget.shares.first.uidOwner == widget.account.username) ...[
if (widget.shares.first.uidOwner
.equalsIgnoreCase(widget.account.username)) ...[
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(16),

View file

@ -19,6 +19,7 @@ import 'package:nc_photos/iterable_extension.dart';
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/pref.dart';
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/string_extension.dart';
import 'package:nc_photos/theme.dart';
import 'package:nc_photos/use_case/import_potential_shared_album.dart';
import 'package:nc_photos/widget/album_browser_util.dart' as album_browser_util;
@ -193,7 +194,8 @@ class _SharingBrowserState extends State<SharingBrowser> {
),
),
label: shares.first.share.filename,
description: shares.first.share.uidOwner == widget.account.username
description:
shares.first.share.uidOwner.equalsIgnoreCase(widget.account.username)
? L10n.global().fileLastSharedDescription(dateStr)
: L10n.global().fileLastSharedByOthersDescription(
shares.first.share.displaynameOwner, dateStr),
@ -247,7 +249,8 @@ class _SharingBrowserState extends State<SharingBrowser> {
),
),
label: firstItem.album.name,
description: shares.first.share.uidOwner == widget.account.username
description:
shares.first.share.uidOwner.equalsIgnoreCase(widget.account.username)
? L10n.global().fileLastSharedDescription(dateStr)
: L10n.global().albumLastSharedByOthersDescription(
shares.first.share.displaynameOwner, dateStr),
@ -294,7 +297,8 @@ class _SharingBrowserState extends State<SharingBrowser> {
// group shares of the same file
final map = <String, List<ListSharingItem>>{};
for (final i in items) {
final isSharedByMe = i.share.uidOwner == widget.account.username;
final isSharedByMe =
i.share.uidOwner.equalsIgnoreCase(widget.account.username);
final groupKey = "${i.share.path}?$isSharedByMe";
map[groupKey] ??= <ListSharingItem>[];
map[groupKey]!.add(i);