Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Route notification to memory

laurenspriem8171d561689a
diff --git a/mobile/lib/services/memories_cache_service.dart b/mobile/lib/services/memories_cache_service.dart
index 6c2e2a76a6..e3bcc5c32c 100644
--- a/mobile/lib/services/memories_cache_service.dart
+++ b/mobile/lib/services/memories_cache_service.dart
@@ -444,6 +444,8 @@ class MemoriesCacheService {
"No memories found in cache, force updating cache. Possible severe caching issue",
);
await updateCache(forced: true);
+ } else {
+ _logger.info("Found memories in cache");
}
if (_cachedMemories == null || _cachedMemories!.isEmpty) {
_logger
@@ -499,6 +501,39 @@ class MemoriesCacheService {
);
}
+ Future<void> goToMemoryFromMemoryID(
+ BuildContext context,
+ String memoryID,
+ ) async {
+ final allMemories = await getMemories();
+ if (allMemories.isEmpty) return;
+ int memoryIdx = 0;
+ bool found = false;
+ memoryLoop:
+ for (final memory in _cachedMemories!) {
+ if (memory.id == memoryID) {
+ found = true;
+ break memoryLoop;
+ }
+ memoryIdx++;
+ }
+ if (!found) {
+ _logger.warning(
+ "Could not find memory with memoryID: $memoryID",
+ );
+ return;
+ }
+ await routeToPage(
+ context,
+ FullScreenMemoryDataUpdater(
+ initialIndex: 0,
+ memories: allMemories[memoryIdx].memories,
+ child: FullScreenMemory(allMemories[memoryIdx].title, 0),
+ ),
+ forceCustomPageRoute: true,
+ );
+ }
+
Future<MemoriesCache?> _readCacheFromDisk() async {
_logger.info("Reading memories cache result from disk");
final file = File(await _getCachePath());
diff --git a/mobile/lib/ui/tabs/home_widget.dart b/mobile/lib/ui/tabs/home_widget.dart
index 1e74fb26d5..2e8f510480 100644
--- a/mobile/lib/ui/tabs/home_widget.dart
+++ b/mobile/lib/ui/tabs/home_widget.dart
@@ -853,22 +853,31 @@ class _HomeWidgetState extends State<HomeWidget> {
final String? payload = notificationResponse.payload;
if (payload != null) {
debugPrint('notification payload: $payload');
- final collectionID = Uri.parse(payload).queryParameters["collectionID"];
- if (collectionID != null) {
- final collection = CollectionsService.instance
- .getCollectionByID(int.parse(collectionID))!;
- final thumbnail =
- await CollectionsService.instance.getCover(collection);
+ if (payload.toLowerCase().contains("onthisday")) {
+ final String memoryID = payload.substring(payload.indexOf("_") + 1);
// ignore: unawaited_futures
- routeToPage(
+ await memoriesCacheService.goToMemoryFromMemoryID(
context,
- CollectionPage(
- CollectionWithThumbnail(
- collection,
- thumbnail,
- ),
- ),
+ memoryID,
);
+ } else {
+ final collectionID = Uri.parse(payload).queryParameters["collectionID"];
+ if (collectionID != null) {
+ final collection = CollectionsService.instance
+ .getCollectionByID(int.parse(collectionID))!;
+ final thumbnail =
+ await CollectionsService.instance.getCover(collection);
+ // ignore: unawaited_futures
+ routeToPage(
+ context,
+ CollectionPage(
+ CollectionWithThumbnail(
+ collection,
+ thumbnail,
+ ),
+ ),
+ );
+ }
}
}
}