Przeglądaj źródła

Fix: show correct file owner

Neeraj Gupta 2 lat temu
rodzic
commit
e953968a82

+ 28 - 0
lib/services/collections_service.dart

@@ -5,6 +5,7 @@ import 'dart:convert';
 import 'dart:math';
 import 'dart:math';
 import 'dart:typed_data';
 import 'dart:typed_data';
 
 
+import 'package:collection/collection.dart';
 import 'package:dio/dio.dart';
 import 'package:dio/dio.dart';
 import 'package:flutter/foundation.dart';
 import 'package:flutter/foundation.dart';
 import 'package:flutter_sodium/flutter_sodium.dart';
 import 'package:flutter_sodium/flutter_sodium.dart';
@@ -55,6 +56,7 @@ class CollectionsService {
   final _localPathToCollectionID = <String, int>{};
   final _localPathToCollectionID = <String, int>{};
   final _collectionIDToCollections = <int, Collection>{};
   final _collectionIDToCollections = <int, Collection>{};
   final _cachedKeys = <int, Uint8List>{};
   final _cachedKeys = <int, Uint8List>{};
+  final _cachedUserIdToUser = <int, User>{};
   Collection cachedDefaultHiddenCollection;
   Collection cachedDefaultHiddenCollection;
 
 
   CollectionsService._privateConstructor() {
   CollectionsService._privateConstructor() {
@@ -219,6 +221,32 @@ class CollectionsService {
         .toList();
         .toList();
   }
   }
 
 
+  User getFileOwner(int userID, int collectionID) {
+    if (_cachedUserIdToUser.containsKey(userID)) {
+      return _cachedUserIdToUser[userID];
+    }
+    if (collectionID != null) {
+      final Collection collection = getCollectionByID(collectionID);
+      if (collection != null) {
+        if (collection.owner.id == userID) {
+          _cachedUserIdToUser[userID] = collection.owner;
+        } else {
+          final matchingUser = collection.getSharees().firstWhereOrNull(
+                (u) => u.id == userID,
+              );
+          if (matchingUser != null) {
+            _cachedUserIdToUser[userID] = collection.owner;
+          }
+        }
+      }
+    }
+    return _cachedUserIdToUser[userID] ??
+        User(
+          id: userID,
+          email: "unknown@unknown.com",
+        );
+  }
+
   Future<List<CollectionWithThumbnail>> getCollectionsWithThumbnails({
   Future<List<CollectionWithThumbnail>> getCollectionsWithThumbnails({
     bool includedOwnedByOthers = false,
     bool includedOwnedByOthers = false,
     // includeCollabCollections will include collections where the current user
     // includeCollabCollections will include collections where the current user

+ 3 - 5
lib/ui/viewer/file/thumbnail_widget.dart

@@ -11,10 +11,10 @@ import 'package:photos/db/files_db.dart';
 import 'package:photos/db/trash_db.dart';
 import 'package:photos/db/trash_db.dart';
 import 'package:photos/events/files_updated_event.dart';
 import 'package:photos/events/files_updated_event.dart';
 import 'package:photos/events/local_photos_updated_event.dart';
 import 'package:photos/events/local_photos_updated_event.dart';
-import 'package:photos/models/collection.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file.dart';
 import 'package:photos/models/file_type.dart';
 import 'package:photos/models/file_type.dart';
 import 'package:photos/models/trash_file.dart';
 import 'package:photos/models/trash_file.dart';
+import 'package:photos/services/collections_service.dart';
 import 'package:photos/services/favorites_service.dart';
 import 'package:photos/services/favorites_service.dart';
 import 'package:photos/ui/viewer/file/file_icons_widget.dart';
 import 'package:photos/ui/viewer/file/file_icons_widget.dart';
 import 'package:photos/utils/file_util.dart';
 import 'package:photos/utils/file_util.dart';
@@ -122,10 +122,8 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
         // cover
         // cover
         contentChildren.add(
         contentChildren.add(
           OwnerAvatarOverlayIcon(
           OwnerAvatarOverlayIcon(
-            User(
-              id: widget.file.ownerID,
-              email: 'n@ente.io',
-            ),
+            CollectionsService.instance
+                .getFileOwner(widget.file.ownerID, widget.file.collectionID),
           ),
           ),
         );
         );
       }
       }