瀏覽代碼

Replace collection.name usage with collection.displayName

Neeraj Gupta 2 年之前
父節點
當前提交
e2e1d7ef13

+ 3 - 2
lib/models/collection.dart

@@ -9,6 +9,7 @@ class Collection {
   final User? owner;
   final String encryptedKey;
   final String? keyDecryptionNonce;
+  @Deprecated("Use collectionName instead")
   final String? name;
   // encryptedName & nameDecryptionNonce will be null for collections
   // created before we started encrypting collection name
@@ -38,6 +39,8 @@ class Collection {
 
   set magicMetadata(val) => _mmd = val;
 
+  String get displayName => decryptedName ?? name ?? "Unnamed collection";
+
   Collection(
     this.id,
     this.owner,
@@ -97,8 +100,6 @@ class Collection {
     return (owner?.id ?? 0) == userID;
   }
 
-  String get collectionName => name ?? "Unnamed collection";
-
   void updateSharees(List<User> newSharees) {
     sharees?.clear();
     sharees?.addAll(newSharees);

+ 6 - 5
lib/models/duplicate_files.dart

@@ -55,11 +55,12 @@ class DuplicateFiles {
 
   sortByCollectionName() {
     files.sort((first, second) {
-      final firstName =
-          collectionsService.getCollectionByID(first.collectionID!)!.name ?? '';
-      final secondName =
-          collectionsService.getCollectionByID(second.collectionID!)!.name ??
-              '';
+      final firstName = collectionsService
+          .getCollectionByID(first.collectionID!)!
+          .displayName;
+      final secondName = collectionsService
+          .getCollectionByID(second.collectionID!)!
+          .displayName;
       return firstName.compareTo(secondName);
     });
   }

+ 1 - 1
lib/models/search/album_search_result.dart

@@ -14,7 +14,7 @@ class AlbumSearchResult extends SearchResult {
 
   @override
   String name() {
-    return collectionWithThumbnail.collection.name!;
+    return collectionWithThumbnail.collection.displayName;
   }
 
   @override

+ 1 - 1
lib/services/search_service.dart

@@ -76,7 +76,7 @@ class SearchService {
 
       if (!c.collection.isHidden() &&
           c.collection.type != CollectionType.uncategorized &&
-          c.collection.name!.toLowerCase().contains(
+          c.collection.displayName.toLowerCase().contains(
                 query.toLowerCase(),
               )) {
         collectionSearchResults.add(AlbumSearchResult(c));

+ 1 - 1
lib/ui/actions/collection/collection_sharing_actions.dart

@@ -81,7 +81,7 @@ class CollectionActions {
       title: S.of(context).removePublicLink,
       body:
           //'This will remove the public link for accessing "${collection.name}".',
-          S.of(context).disableLinkMessage(collection.collectionName),
+          S.of(context).disableLinkMessage(collection.displayName),
     );
     if (actionResult?.action != null) {
       if (actionResult!.action == ButtonAction.error) {

+ 3 - 3
lib/ui/collection_action_sheet.dart

@@ -218,7 +218,7 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
               final searchResults = _searchQuery.isNotEmpty
                   ? collectionsWithThumbnail
                       .where(
-                        (element) => element.collection.name!
+                        (element) => element.collection.displayName
                             .toLowerCase()
                             .contains(_searchQuery),
                       )
@@ -263,8 +263,8 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {
     );
     collectionsWithThumbnail.sort((first, second) {
       return compareAsciiLowerCaseNatural(
-        first.collection.name ?? "",
-        second.collection.name ?? "",
+        first.collection.displayName,
+        second.collection.displayName,
       );
     });
     return collectionsWithThumbnail;

+ 1 - 1
lib/ui/collections/collection_item_widget.dart

@@ -62,7 +62,7 @@ class CollectionItem extends StatelessWidget {
             children: [
               const SizedBox(height: 2),
               Text(
-                (c.collection.collectionName).trim(),
+                (c.collection.displayName).trim(),
                 style: enteTextTheme.small,
                 overflow: TextOverflow.ellipsis,
               ),

+ 2 - 2
lib/ui/collections_gallery_widget.dart

@@ -107,8 +107,8 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget>
       (first, second) {
         if (sortKey == AlbumSortKey.albumName) {
           return compareAsciiLowerCaseNatural(
-            first.collection.name!,
-            second.collection.name!,
+            first.collection.displayName,
+            second.collection.displayName,
           );
         } else if (sortKey == AlbumSortKey.newestPhoto) {
           return (second.thumbnail?.creationTime ?? -1 * intMaxValue)

+ 6 - 4
lib/ui/collections_list_widget.dart

@@ -181,12 +181,14 @@ class CollectionsListWidget extends StatelessWidget {
       late final String toastMessage;
       bool shouldNavigateToCollection = false;
       if (actionType == CollectionActionType.addFiles) {
-        toastMessage = S.of(context).addedSuccessfullyTo(item.collection.name!);
+        toastMessage =
+            S.of(context).addedSuccessfullyTo(item.collection.displayName);
         shouldNavigateToCollection = true;
       } else if (actionType == CollectionActionType.moveFiles ||
           actionType == CollectionActionType.restoreFiles ||
           actionType == CollectionActionType.unHide) {
-        toastMessage = S.of(context).movedSuccessfullyTo(item.collection.name!);
+        toastMessage =
+            S.of(context).movedSuccessfullyTo(item.collection.displayName);
         shouldNavigateToCollection = true;
       } else {
         toastMessage = "";
@@ -275,7 +277,7 @@ class CollectionsListWidget extends StatelessWidget {
               .updateShareUrl(collection, {'enableCollect': true}).then(
             (value) => showShortToast(
               context,
-              S.of(context).collaborativeLinkCreatedFor(collection.name!),
+              S.of(context).collaborativeLinkCreatedFor(collection.displayName),
             ),
           );
           return true;
@@ -293,7 +295,7 @@ class CollectionsListWidget extends StatelessWidget {
     if (result) {
       showShortToast(
         context,
-        S.of(context).collaborativeLinkCreatedFor(collection.name!),
+        S.of(context).collaborativeLinkCreatedFor(collection.displayName),
       );
       if (Configuration.instance.getUserID() == collection.owner!.id) {
         unawaited(

+ 1 - 1
lib/ui/components/album_list_item_widget.dart

@@ -52,7 +52,7 @@ class AlbumListItemWidget extends StatelessWidget {
                   child: Column(
                     crossAxisAlignment: CrossAxisAlignment.start,
                     children: [
-                      Text(item.collection.collectionName),
+                      Text(item.collection.displayName),
                       FutureBuilder<int>(
                         future: FilesDB.instance.collectionFileCount(
                           item.collection.id,

+ 2 - 2
lib/ui/shared_collections_gallery.dart

@@ -343,7 +343,7 @@ class OutgoingCollectionItem extends StatelessWidget {
                   Row(
                     children: [
                       Text(
-                        c.collection.name!,
+                        c.collection.displayName,
                         style: const TextStyle(
                           fontSize: 16,
                         ),
@@ -449,7 +449,7 @@ class IncomingCollectionItem extends StatelessWidget {
               Container(
                 constraints: BoxConstraints(maxWidth: sideOfThumbnail - 40),
                 child: Text(
-                  c.collection.name!,
+                  c.collection.displayName,
                   style: albumTitleTextStyle,
                   overflow: TextOverflow.ellipsis,
                 ),

+ 1 - 1
lib/ui/sharing/album_participants_page.dart

@@ -83,7 +83,7 @@ class _AlbumParticipantsPageState extends State<AlbumParticipantsPage> {
         slivers: <Widget>[
           TitleBarWidget(
             flexibleSpaceTitle: TitleBarTitleWidget(
-              title: "${widget.collection.name}",
+              title: widget.collection.displayName,
             ),
             flexibleSpaceCaption:
                 S.of(context).albumParticipantsCount(participants),

+ 1 - 1
lib/ui/sharing/share_collection_page.dart

@@ -288,7 +288,7 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
     return Scaffold(
       appBar: AppBar(
         title: Text(
-          widget.collection.name ?? "Unnamed",
+          widget.collection.displayName,
           style: Theme.of(context).textTheme.headline5?.copyWith(fontSize: 16),
         ),
         elevation: 0,

+ 1 - 1
lib/ui/tools/deduplicate_page.dart

@@ -480,7 +480,7 @@ class _DeduplicatePageState extends State<DeduplicatePage> {
             child: Text(
               CollectionsService.instance
                   .getCollectionByID(file.collectionID!)!
-                  .name!,
+                  .displayName,
               style:
                   Theme.of(context).textTheme.caption!.copyWith(fontSize: 12),
               overflow: TextOverflow.ellipsis,

+ 1 - 1
lib/ui/viewer/file_details/albums_item_widget.dart

@@ -83,7 +83,7 @@ class AlbumsItemWidget extends StatelessWidget {
         collections.add(c!);
         chipButtons.add(
           ChipButtonWidget(
-            c.isHidden() ? S.of(context).hidden : c.name,
+            c.isHidden() ? S.of(context).hidden : c.displayName,
             onTap: () {
               if (c.isHidden()) {
                 return;

+ 2 - 2
lib/ui/viewer/gallery/collection_page.dart

@@ -73,14 +73,14 @@ class CollectionPage extends StatelessWidget {
       tagPrefix: tagPrefix,
       selectedFiles: _selectedFiles,
       initialFiles: initialFiles,
-      albumName: c.collection.name,
+      albumName: c.collection.displayName,
     );
     return Scaffold(
       appBar: PreferredSize(
         preferredSize: const Size.fromHeight(50.0),
         child: GalleryAppBarWidget(
           appBarTypeValue,
-          c.collection.name,
+          c.collection.displayName,
           _selectedFiles,
           collection: c.collection,
         ),