From d4c7d06693ca61ac0bfa14d9cc3d2e66d6cc8fff Mon Sep 17 00:00:00 2001 From: primozratej Date: Tue, 21 Jan 2025 22:00:17 +0100 Subject: [PATCH] Update UrlProviderHandler with go.humhub.com logic --- lib/flavored/util/intent_plugin.f.dart | 4 ++-- lib/util/intent/intent_plugin.dart | 4 ++-- lib/util/intent/mail_link_provider.dart | 27 +++++++++++++++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/flavored/util/intent_plugin.f.dart b/lib/flavored/util/intent_plugin.f.dart index 802791a..0973383 100644 --- a/lib/flavored/util/intent_plugin.f.dart +++ b/lib/flavored/util/intent_plugin.f.dart @@ -57,7 +57,7 @@ class IntentPluginFState extends ConsumerState { // the foreground or in the background. _sub = uriLinkStream.listen((Uri? uri) async { if (!mounted && uri == null) return; - _latestUri = await MailProviderHandler.handleUniversalLink(uri!) ?? uri; + _latestUri = await UrlProviderHandler.handleUniversalLink(uri!) ?? uri; String? redirectUrl = _latestUri?.toString(); if (redirectUrl != null && navigatorKey.currentState != null) { tryNavigateWithOpener(redirectUrl); @@ -88,7 +88,7 @@ class IntentPluginFState extends ConsumerState { Uri? uri = await getInitialUri(); if (uri == null) return; setState(() => _initialUri = uri); - _latestUri = await MailProviderHandler.handleUniversalLink(uri) ?? uri; + _latestUri = await UrlProviderHandler.handleUniversalLink(uri) ?? uri; String? redirectUrl = _latestUri.toString(); if (navigatorKey.currentState != null) { tryNavigateWithOpener(redirectUrl); diff --git a/lib/util/intent/intent_plugin.dart b/lib/util/intent/intent_plugin.dart index d23c3d0..85936f6 100644 --- a/lib/util/intent/intent_plugin.dart +++ b/lib/util/intent/intent_plugin.dart @@ -58,7 +58,7 @@ class IntentPluginState extends ConsumerState { // the foreground or in the background. _sub = uriLinkStream.listen((Uri? uri) async { if (!mounted && uri == null) return; - _latestUri = await MailProviderHandler.handleUniversalLink(uri!) ?? uri; + _latestUri = await UrlProviderHandler.handleUniversalLink(uri!) ?? uri; String redirectUrl = _latestUri.toString(); if (navigatorKey.currentState != null) { tryNavigateWithOpener(redirectUrl); @@ -90,7 +90,7 @@ class IntentPluginState extends ConsumerState { final uri = await getInitialUri(); if (uri == null || !mounted) return; setState(() => _initialUri = uri); - _latestUri = await MailProviderHandler.handleUniversalLink(uri) ?? uri; + _latestUri = await UrlProviderHandler.handleUniversalLink(uri) ?? uri; String? redirectUrl = _latestUri.toString(); if (navigatorKey.currentState != null) { tryNavigateWithOpener(redirectUrl); diff --git a/lib/util/intent/mail_link_provider.dart b/lib/util/intent/mail_link_provider.dart index c162690..8470bbf 100644 --- a/lib/util/intent/mail_link_provider.dart +++ b/lib/util/intent/mail_link_provider.dart @@ -2,19 +2,37 @@ import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:loggy/loggy.dart'; -class MailProviderHandler { +class UrlProviderHandler { static Future handleUniversalLink(Uri url) async { - if (_isBrevoUrl(url)) { + if (_isHumHubUrl(url)) { + return _handleHumHubUrl(url); + } else if (_isBrevoUrl(url)) { return await _handleUniversalLinkBrevo(url); - } else { - return null; } + return null; + } + + static bool _isHumHubUrl(Uri url) { + return url.toString().contains('go.humhub.com'); } static bool _isBrevoUrl(Uri url) { return url.toString().contains('r.mail.inforisque.fr'); } + static Uri? _handleHumHubUrl(Uri url) { + try { + final urlParam = url.queryParameters['url']; + if (urlParam != null) { + return Uri.parse(Uri.decodeComponent(urlParam)); + } + return null; + } catch (e) { + logError('Error while handling HumHub URL: $e'); + return null; + } + } + static Future _handleUniversalLinkBrevo(Uri url) async { try { final response = await http.get( @@ -34,3 +52,4 @@ class MailProviderHandler { } } } +