|
@@ -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
|