feat(app): open chats from pipelines://chat/<id> notification links
The app routes pipelines://chat/<id> to that chat, alongside the existing pipelines://run/<id>, and Android registers the chat host so a tapped ntfy notification opens the app on it.
This commit is contained in:
@@ -32,15 +32,17 @@
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
<!-- The server publishes `pipelines://run/<id>` as a notification's
|
||||
click URL; it opens that run (lib/application/app_router.dart
|
||||
routeLocation). It only opens a run; it starts nothing. -->
|
||||
<!-- The server publishes `pipelines://run/<id>` and
|
||||
`pipelines://chat/<id>` as a notification's click URL; each
|
||||
opens that run or chat (lib/application/app_router.dart
|
||||
routeLocation). It only opens it; it starts nothing. -->
|
||||
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="pipelines" android:host="run" />
|
||||
<data android:scheme="pipelines" android:host="chat" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<!-- Don't delete the meta-data below.
|
||||
|
||||
@@ -26,12 +26,15 @@ class AppRouteParser extends RouteInformationParser<AppRoute> {
|
||||
/// `/runs/7/stage/plan?visit=1` keeps the query instead of losing it to
|
||||
/// `Uri.path`. A fragment is not part of an app route.
|
||||
///
|
||||
/// The native notification link `pipelines://run/<id>` (the URL the server
|
||||
/// publishes as the notification's click target, as the Android client
|
||||
/// registers it) is the run route `/runs/<id>`.
|
||||
/// The native notification links the server publishes as a notification's
|
||||
/// click target (and the apps register): `pipelines://run/<id>` is the run
|
||||
/// route `/runs/<id>` and `pipelines://chat/<id>` the chat route `/chat/<id>`.
|
||||
String routeLocation(Uri uri) {
|
||||
final path = uri.scheme == 'pipelines' && uri.host == 'run'
|
||||
final native = uri.scheme == 'pipelines';
|
||||
final path = native && uri.host == 'run'
|
||||
? '/runs${uri.path}'
|
||||
: native && uri.host == 'chat'
|
||||
? '/chat${uri.path}'
|
||||
: uri.path;
|
||||
return uri.hasQuery ? '$path?${uri.query}' : path;
|
||||
}
|
||||
@@ -218,7 +221,6 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
_route = route;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// The location a launch starts at: the browser location on the web, the
|
||||
|
||||
@@ -170,4 +170,13 @@ void main() {
|
||||
// Another scheme or host is not a run link.
|
||||
expect(routeLocation(Uri.parse('pipelines://other/42')), '/42');
|
||||
});
|
||||
|
||||
test('the native chat notification link opens its chat', () async {
|
||||
const parser = AppRouteParser();
|
||||
final chat = await parser.parseRouteInformation(
|
||||
RouteInformation(uri: Uri.parse('pipelines://chat/ses_abc123')),
|
||||
);
|
||||
expect(chat, AppRoute.chatSession('ses_abc123'));
|
||||
expect(chat.chatSessionId, 'ses_abc123');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user