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