files_split.dart 996 B

1234567891011121314151617181920212223242526272829303132333435
  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 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. return FilesSplit(
  26. pendingUploads: pendingUploads,
  27. ownedByCurrentUser: ownedByCurrentUser,
  28. ownedByOtherUsers: ownedByOtherUsers,
  29. );
  30. }
  31. }