UUID dispatch before link/legacy — didvanplus + monthly with link now route correctly

This commit is contained in:
Mohamad Mahdi Jebeli 2026-06-22 10:47:19 +03:30
parent 7710b5cab8
commit 8336987f86
1 changed files with 107 additions and 112 deletions

View File

@ -234,32 +234,26 @@ class HomeWidgetRepository {
dynamic args; dynamic args;
bool openComments = localData.notificationType.toString() == "2"; bool openComments = localData.notificationType.toString() == "2";
if (localData.link.toString().isEmpty || // ---------------- UUID dispatch (FIRST) ----------------
localData.link.toString() == "null") { // Content from the new content-service uses UUIDs. We must decide on
// ---------------- UUID short-circuit ---------------- // the destination BEFORE checking `link`, because some categories
// Content from the new content-service uses UUIDs. The legacy routes // (didvanplus / video / monthly) legitimately ship with a `link` (the
// below assume int IDs and can't be reached for UUID content. Route // media URL) and would otherwise get sent to a generic WebView, which
// by `type` to the matching detail screen, all of which know how to // breaks Arvan signed URLs.
// hydrate from content-service when given `contentUuid`.
// //
// Exception: trend / technology / startup intentionally render in // Exception: trend / technology / startup are NOT in-app screens
// their dedicated webview those fall through to the legacy switch // they live on app.didvan.com and we open them in a WebView, even
// below so the URL is constructed and opened in a WebView even when // when the id is a UUID.
// the id is a UUID.
const _webViewTypes = {'trend', 'technology', 'startup'}; const _webViewTypes = {'trend', 'technology', 'startup'};
final _isWebViewType = _webViewTypes.contains(localData.type); final _isWebViewType = _webViewTypes.contains(localData.type);
if (_isUuid(localData.id) && !_isWebViewType) { final _isUuidId = _isUuid(localData.id);
// Per-category routing for new (UUID-based) content. Each branch final _hasLink = localData.link != null &&
// sends the user to that category's native detail screen, all of localData.link!.isNotEmpty &&
// which can hydrate from content-service via `contentUuid`. localData.link!.toString() != 'null';
//
// Categories whose detail screen isn't UUID-aware yet fall through if (_isUuidId && !_isWebViewType) {
// to InfographyDetails (the generic content reader). When you wire
// a new screen, add another case here.
final type = localData.type ?? ''; final type = localData.type ?? '';
switch (type) { switch (type) {
// Hard news / story / poyesh / swot all live in the NewsDetails
// pager same UI, different category filter.
case 'news': case 'news':
case 'story': case 'story':
case 'poyesh': case 'poyesh':
@ -273,8 +267,6 @@ class HomeWidgetRepository {
}; };
break; break;
// Infography & banner: the existing InfographyDetails already
// knows how to load by UUID.
case 'infography': case 'infography':
case 'banner': case 'banner':
route = Routes.infographyDetails; route = Routes.infographyDetails;
@ -285,7 +277,6 @@ class HomeWidgetRepository {
}; };
break; break;
// Podcast detail page.
case 'podcast': case 'podcast':
route = Routes.studioDetails; route = Routes.studioDetails;
args = { args = {
@ -295,7 +286,6 @@ class HomeWidgetRepository {
}; };
break; break;
// Video / video-cast detail page.
case 'video': case 'video':
route = Routes.videoDetails; route = Routes.videoDetails;
args = { args = {
@ -304,19 +294,22 @@ class HomeWidgetRepository {
}; };
break; break;
// Monthly notifications normally arrive with `link` populated and
// go to PDFViewer in the `else` branch below. Reaching here means
// there's no PDF URL yet — show the list so the user can browse.
case 'monthly': case 'monthly':
// PDF URL is in `link`; if present, open PdfViewer directly.
if (_hasLink) {
route = Routes.pdfViewer;
args = {
'pdfUrl': localData.link,
'title': localData.title ?? 'ماهنامه',
};
} else {
route = Routes.monthlyList; route = Routes.monthlyList;
}
break; break;
case 'didvanplus': case 'didvanplus':
// Open the player directly. We don't have a full DidvanPlusModel // Open the player directly with a synthesized model.
// here (no record in the legacy DB), so we synthesize one from if (_hasLink) {
// the notification payload the player only reads file/image/
// title/description.
if (localData.link != null && localData.link!.isNotEmpty) {
route = Routes.didvanPlusVideo; route = Routes.didvanPlusVideo;
args = DidvanPlusModel( args = DidvanPlusModel(
id: 0, // unused for navigation id: 0, // unused for navigation
@ -327,7 +320,6 @@ class HomeWidgetRepository {
publishedAt: DateTime.now().toIso8601String(), publishedAt: DateTime.now().toIso8601String(),
); );
} else { } else {
// Fallback: no video URL just show the list.
route = Routes.didvanPlusList; route = Routes.didvanPlusList;
} }
break; break;
@ -353,7 +345,10 @@ class HomeWidgetRepository {
if (kDebugMode) { if (kDebugMode) {
print("UUID notification routed: type=$type → route=$route"); print("UUID notification routed: type=$type → route=$route");
} }
} else if (localData.type == null || localData.type!.isEmpty) { } else if (!_hasLink) {
// Legacy int-id branch: no link, fall through to per-type detail
// pages keyed by int id (or home if no type).
if (localData.type == null || localData.type!.isEmpty) {
if (kDebugMode) { if (kDebugMode) {
print("=== NAVIGATION ABORTED ==="); print("=== NAVIGATION ABORTED ===");
print("Reason: Notification type is null or empty"); print("Reason: Notification type is null or empty");