Browse Source

fix(mobile): Sorted shared album and added share user doesn't reflect change in album view (#1955)

* fix: sorted shared album

* Added TODO comment for tomorrow work

* update album shared property after adding user

---------

Co-authored-by: Fynn Petersen-Frey <zoodyy@users.noreply.github.com>
Alex 2 năm trước cách đây
mục cha
commit
416e30ede2

+ 10 - 2
mobile/lib/modules/album/providers/shared_album.provider.dart

@@ -37,12 +37,20 @@ class SharedAlbumNotifier extends StateNotifier<List<Album>> {
   }
 
   Future<void> getAllSharedAlbums() async {
-    var albums = await _db.albums.filter().sharedEqualTo(true).findAll();
+    var albums = await _db.albums
+        .filter()
+        .sharedEqualTo(true)
+        .sortByCreatedAtDesc()
+        .findAll();
     if (!const ListEquality().equals(albums, state)) {
       state = albums;
     }
     await _albumService.refreshRemoteAlbums(isShared: true);
-    albums = await _db.albums.filter().sharedEqualTo(true).findAll();
+    albums = await _db.albums
+        .filter()
+        .sharedEqualTo(true)
+        .sortByCreatedAtDesc()
+        .findAll();
     if (!const ListEquality().equals(albums, state)) {
       state = albums;
     }

+ 5 - 1
mobile/lib/modules/album/services/album.service.dart

@@ -211,7 +211,11 @@ class AlbumService {
       if (result != null) {
         album.sharedUsers
             .addAll((await _db.users.getAllById(sharedUserIds)).cast());
-        await _db.writeTxn(() => album.sharedUsers.save());
+        album.shared = result.shared;
+        await _db.writeTxn(() async {
+          await _db.albums.put(album);
+          await album.sharedUsers.save();
+        });
         return true;
       }
     } catch (e) {

+ 1 - 1
mobile/lib/shared/services/sync.service.dart

@@ -501,7 +501,6 @@ Triple<List<Asset>, List<Asset>, List<Asset>> _diffAssets(
           (!a.isLocal && b.isLocal) ||
           (!a.isRemote && b.isRemote)) {
         toUpdate.add(b.updateFromDb(a));
-        debugPrint("both");
         return true;
       }
       return false;
@@ -554,5 +553,6 @@ bool _hasAlbumResponseDtoChanged(AlbumResponseDto dto, Album a) {
       dto.albumName != a.name ||
       dto.albumThumbnailAssetId != a.thumbnail.value?.remoteId ||
       dto.shared != a.shared ||
+      dto.sharedUsers.length != a.sharedUsers.length ||
       DateTime.parse(dto.updatedAt).toUtc() != a.modifiedAt.toUtc();
 }