files_split.dart 999 B

123456789101112131415161718192021222324252627282930313233343536
  1. import 'package:photos/models/file.dart';
  2. class FilesSplit {
  3. final List<File> pendingUploads;
  4. final List<File> ownedByCurrentUser;
  5. final List<File> ownedByOtherUsers;
  6. FilesSplit({
  7. required this.pendingUploads,
  8. required this.ownedByCurrentUser,
  9. required this.ownedByOtherUsers,
  10. });
  11. int get totalFileOwnedCount =>
  12. pendingUploads.length + ownedByCurrentUser.length;
  13. static FilesSplit split(Iterable<File> files, int currentUserID) {
  14. final List<File> ownedByCurrentUser = [],
  15. ownedByOtherUsers = [],
  16. pendingUploads = [];
  17. for (var f in files) {
  18. if (f.ownerID == null || f.uploadedFileID == null) {
  19. pendingUploads.add(f);
  20. } else if (f.ownerID == currentUserID) {
  21. ownedByCurrentUser.add(f);
  22. } else {
  23. ownedByOtherUsers.add(f);
  24. }
  25. }
  26. return FilesSplit(
  27. pendingUploads: pendingUploads,
  28. ownedByCurrentUser: ownedByCurrentUser,
  29. ownedByOtherUsers: ownedByOtherUsers,
  30. );
  31. }
  32. }