Skip to content

Commit

Permalink
Merge pull request #271 from humhub/f-internal-71-notification-links-…
Browse files Browse the repository at this point in the history
…dont-open-the-related-humhub-instance

Update UrlProviderHandler with go.humhub.com logic
  • Loading branch information
marc-farre authored Jan 21, 2025
2 parents 57f6174 + d4c7d06 commit 7563df5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/flavored/util/intent_plugin.f.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class IntentPluginFState extends ConsumerState<IntentPluginF> {
// 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);
Expand Down Expand Up @@ -88,7 +88,7 @@ class IntentPluginFState extends ConsumerState<IntentPluginF> {
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);
Expand Down
4 changes: 2 additions & 2 deletions lib/util/intent/intent_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class IntentPluginState extends ConsumerState<IntentPlugin> {
// 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);
Expand Down Expand Up @@ -90,7 +90,7 @@ class IntentPluginState extends ConsumerState<IntentPlugin> {
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);
Expand Down
27 changes: 23 additions & 4 deletions lib/util/intent/mail_link_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Uri?> 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<Uri?> _handleUniversalLinkBrevo(Uri url) async {
try {
final response = await http.get(
Expand All @@ -34,3 +52,4 @@ class MailProviderHandler {
}
}
}

0 comments on commit 7563df5

Please sign in to comment.