Merge pull request #818 from ente-io/fix_potential_null_check_failure
Improve logging and add null checks at missing places
This commit is contained in:
commit
0bbe467750
|
@ -49,6 +49,13 @@ class Collection {
|
||||||
return mMdVersion > 0 && magicMetadata.visibility == visibilityArchive;
|
return mMdVersion > 0 && magicMetadata.visibility == visibilityArchive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hasLink returns true if there's any link attached to the collection
|
||||||
|
// including expired links
|
||||||
|
bool get hasLink => publicURLs != null && publicURLs!.isNotEmpty;
|
||||||
|
|
||||||
|
// hasSharees returns true if the collection is shared with other ente users
|
||||||
|
bool get hasSharees => sharees != null && sharees!.isNotEmpty;
|
||||||
|
|
||||||
bool isHidden() {
|
bool isHidden() {
|
||||||
if (isDefaultHidden()) {
|
if (isDefaultHidden()) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -374,8 +374,17 @@ class _CreateCollectionSheetState extends State<CreateCollectionSheet> {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
for (final file in widget.selectedFiles!.files) {
|
for (final file in widget.selectedFiles!.files) {
|
||||||
final File? currentFile =
|
File? currentFile;
|
||||||
await (FilesDB.instance.getFile(file.generatedID!));
|
if (file.uploadedFileID != null) {
|
||||||
|
currentFile = file;
|
||||||
|
} else if (file.generatedID != null) {
|
||||||
|
// when file is not uploaded, refresh the state from the db to
|
||||||
|
// ensure we have latest upload status for given file before
|
||||||
|
// queueing it up as pending upload
|
||||||
|
currentFile = await (FilesDB.instance.getFile(file.generatedID!));
|
||||||
|
} else if (file.generatedID == null) {
|
||||||
|
_logger.severe("generated id should not be null");
|
||||||
|
}
|
||||||
if (currentFile == null) {
|
if (currentFile == null) {
|
||||||
_logger.severe("Failed to find fileBy genID");
|
_logger.severe("Failed to find fileBy genID");
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -11,6 +11,7 @@ import 'package:photos/events/collection_updated_event.dart';
|
||||||
import 'package:photos/events/local_photos_updated_event.dart';
|
import 'package:photos/events/local_photos_updated_event.dart';
|
||||||
import 'package:photos/events/tab_changed_event.dart';
|
import 'package:photos/events/tab_changed_event.dart';
|
||||||
import 'package:photos/events/user_logged_out_event.dart';
|
import 'package:photos/events/user_logged_out_event.dart';
|
||||||
|
import 'package:photos/models/collection.dart';
|
||||||
import 'package:photos/models/collection_items.dart';
|
import 'package:photos/models/collection_items.dart';
|
||||||
import 'package:photos/models/gallery_type.dart';
|
import 'package:photos/models/gallery_type.dart';
|
||||||
import 'package:photos/services/collections_service.dart';
|
import 'package:photos/services/collections_service.dart';
|
||||||
|
@ -69,12 +70,22 @@ class _SharedCollectionGalleryState extends State<SharedCollectionGallery>
|
||||||
final List<CollectionWithThumbnail> outgoing = [];
|
final List<CollectionWithThumbnail> outgoing = [];
|
||||||
final List<CollectionWithThumbnail> incoming = [];
|
final List<CollectionWithThumbnail> incoming = [];
|
||||||
for (final file in files) {
|
for (final file in files) {
|
||||||
final c = CollectionsService.instance
|
if (file.collectionID == null) {
|
||||||
.getCollectionByID(file.collectionID!)!;
|
_logger.severe("collection id should not be null");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final Collection? c =
|
||||||
|
CollectionsService.instance.getCollectionByID(file.collectionID!);
|
||||||
|
if (c == null) {
|
||||||
|
_logger
|
||||||
|
.severe("shared collection is not cached ${file.collectionID}");
|
||||||
|
CollectionsService.instance
|
||||||
|
.fetchCollectionByID(file.collectionID!)
|
||||||
|
.ignore();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (c.owner!.id == Configuration.instance.getUserID()) {
|
if (c.owner!.id == Configuration.instance.getUserID()) {
|
||||||
if (c.sharees!.isNotEmpty ||
|
if (c.hasSharees || c.hasLink || c.isSharedFilesCollection()) {
|
||||||
c.publicURLs!.isNotEmpty ||
|
|
||||||
c.isSharedFilesCollection()) {
|
|
||||||
outgoing.add(
|
outgoing.add(
|
||||||
CollectionWithThumbnail(
|
CollectionWithThumbnail(
|
||||||
c,
|
c,
|
||||||
|
@ -113,8 +124,12 @@ class _SharedCollectionGalleryState extends State<SharedCollectionGallery>
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
return _getSharedCollectionsGallery(snapshot.data!);
|
return _getSharedCollectionsGallery(snapshot.data!);
|
||||||
} else if (snapshot.hasError) {
|
} else if (snapshot.hasError) {
|
||||||
_logger.shout(snapshot.error);
|
_logger.severe(
|
||||||
return Center(child: Text(snapshot.error.toString()));
|
"critical: failed to load share gallery",
|
||||||
|
snapshot.error,
|
||||||
|
snapshot.stackTrace,
|
||||||
|
);
|
||||||
|
return const Center(child: Text("Something went wrong."));
|
||||||
} else {
|
} else {
|
||||||
return const EnteLoadingWidget();
|
return const EnteLoadingWidget();
|
||||||
}
|
}
|
||||||
|
@ -268,27 +283,29 @@ class OutgoingCollectionItem extends StatelessWidget {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final sharees = <String?>[];
|
final shareesName = <String>[];
|
||||||
for (int index = 0; index < c.collection.sharees!.length; index++) {
|
if (c.collection.hasSharees) {
|
||||||
final sharee = c.collection.sharees![index]!;
|
for (int index = 0; index < c.collection.sharees!.length; index++) {
|
||||||
final name =
|
final sharee = c.collection.sharees![index]!;
|
||||||
(sharee.name?.isNotEmpty ?? false) ? sharee.name : sharee.email;
|
final String name =
|
||||||
if (index < 2) {
|
(sharee.name?.isNotEmpty ?? false) ? sharee.name! : sharee.email;
|
||||||
sharees.add(name);
|
if (index < 2) {
|
||||||
} else {
|
shareesName.add(name);
|
||||||
final remaining = c.collection.sharees!.length - index;
|
|
||||||
if (remaining == 1) {
|
|
||||||
// If it's the last sharee
|
|
||||||
sharees.add(name);
|
|
||||||
} else {
|
} else {
|
||||||
sharees.add(
|
final remaining = c.collection.sharees!.length - index;
|
||||||
"and " +
|
if (remaining == 1) {
|
||||||
remaining.toString() +
|
// If it's the last sharee
|
||||||
" other" +
|
shareesName.add(name);
|
||||||
(remaining > 1 ? "s" : ""),
|
} else {
|
||||||
);
|
shareesName.add(
|
||||||
|
"and " +
|
||||||
|
remaining.toString() +
|
||||||
|
" other" +
|
||||||
|
(remaining > 1 ? "s" : ""),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
|
@ -325,22 +342,22 @@ class OutgoingCollectionItem extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Padding(padding: EdgeInsets.all(2)),
|
const Padding(padding: EdgeInsets.all(2)),
|
||||||
c.collection.publicURLs!.isEmpty
|
c.collection.hasLink
|
||||||
? Container()
|
? (c.collection.publicURLs!.first!.isExpired
|
||||||
: (c.collection.publicURLs!.first!.isExpired
|
|
||||||
? const Icon(
|
? const Icon(
|
||||||
Icons.link,
|
Icons.link,
|
||||||
color: warning500,
|
color: warning500,
|
||||||
)
|
)
|
||||||
: const Icon(Icons.link)),
|
: const Icon(Icons.link))
|
||||||
|
: Container(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
sharees.isEmpty
|
shareesName.isEmpty
|
||||||
? Container()
|
? Container()
|
||||||
: Padding(
|
: Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(0, 4, 0, 0),
|
padding: const EdgeInsets.fromLTRB(0, 4, 0, 0),
|
||||||
child: Text(
|
child: Text(
|
||||||
"Shared with " + sharees.join(", "),
|
"Shared with " + shareesName.join(", "),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Theme.of(context).primaryColorLight,
|
color: Theme.of(context).primaryColorLight,
|
||||||
|
|
|
@ -46,7 +46,7 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
_sharees = widget.collection.sharees ?? [];
|
_sharees = widget.collection.sharees ?? [];
|
||||||
final bool hasUrl = widget.collection.publicURLs?.isNotEmpty ?? false;
|
final bool hasUrl = widget.collection.hasLink;
|
||||||
final children = <Widget>[];
|
final children = <Widget>[];
|
||||||
children.add(
|
children.add(
|
||||||
MenuSectionTitle(
|
MenuSectionTitle(
|
||||||
|
|
|
@ -12,7 +12,7 @@ description: ente photos application
|
||||||
# Read more about iOS versioning at
|
# Read more about iOS versioning at
|
||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
|
|
||||||
version: 0.7.8+408
|
version: 0.7.11+411
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.17.0 <3.0.0'
|
sdk: '>=2.17.0 <3.0.0'
|
||||||
|
|
Loading…
Reference in a new issue