Fix: show correct file owner

This commit is contained in:
Neeraj Gupta 2022-12-16 10:18:15 +05:30
parent 40d8d215cc
commit e953968a82
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
2 changed files with 31 additions and 5 deletions

View file

@ -5,6 +5,7 @@ import 'dart:convert';
import 'dart:math';
import 'dart:typed_data';
import 'package:collection/collection.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_sodium/flutter_sodium.dart';
@ -55,6 +56,7 @@ class CollectionsService {
final _localPathToCollectionID = <String, int>{};
final _collectionIDToCollections = <int, Collection>{};
final _cachedKeys = <int, Uint8List>{};
final _cachedUserIdToUser = <int, User>{};
Collection cachedDefaultHiddenCollection;
CollectionsService._privateConstructor() {
@ -219,6 +221,32 @@ class CollectionsService {
.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({
bool includedOwnedByOthers = false,
// includeCollabCollections will include collections where the current user

View file

@ -11,10 +11,10 @@ import 'package:photos/db/files_db.dart';
import 'package:photos/db/trash_db.dart';
import 'package:photos/events/files_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_type.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/ui/viewer/file/file_icons_widget.dart';
import 'package:photos/utils/file_util.dart';
@ -122,10 +122,8 @@ class _ThumbnailWidgetState extends State<ThumbnailWidget> {
// cover
contentChildren.add(
OwnerAvatarOverlayIcon(
User(
id: widget.file.ownerID,
email: 'n@ente.io',
),
CollectionsService.instance
.getFileOwner(widget.file.ownerID, widget.file.collectionID),
),
);
}