forked from Nexus/nexus
notif fixups
This commit is contained in:
parent
78c6b2ef46
commit
1c533b5330
4 changed files with 38 additions and 14 deletions
|
|
@ -414,17 +414,17 @@ class ClientController(final String? accountId) extends AsyncNotifier<int> {
|
||||||
Future<void> registerPusher(RegisterPusherRequest request) =>
|
Future<void> registerPusher(RegisterPusherRequest request) =>
|
||||||
sendCommand("register_homeserver_push", request.toJson());
|
sendCommand("register_homeserver_push", request.toJson());
|
||||||
|
|
||||||
Future<void> deregisterPusher(DeregisterPusherRequest request) =>
|
Future<void> deregisterPusher(DeregisterPusherRequest request) => sendCommand(
|
||||||
sendCommand("register_homeserver_push", {
|
"register_homeserver_push",
|
||||||
...request.toJson(),
|
{...request.toJson(), "kind": null},
|
||||||
"kind": null,
|
);
|
||||||
});
|
|
||||||
|
|
||||||
Future<MessageContent> uploadMedia(UploadMediaRequest request) async =>
|
Future<MessageContent> uploadMedia(UploadMediaRequest request) async =>
|
||||||
.fromJson(await sendCommand("upload_media", request.toJson()));
|
.fromJson(await sendCommand("upload_media", request.toJson()));
|
||||||
|
|
||||||
Future<File> downloadMedia(DownloadMediaRequest request) async {
|
Future<File> downloadMedia(DownloadMediaRequest request) async {
|
||||||
if (accountId == null &&
|
if (accountId == null &&
|
||||||
|
!isInBackground &&
|
||||||
ref.read(ClientStateController.provider)?.isLoggedIn != true) {
|
ref.read(ClientStateController.provider)?.isLoggedIn != true) {
|
||||||
throw StateError("Can't download media while logged out");
|
throw StateError("Can't download media while logged out");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
lib/controllers/launch_scope.dart
Normal file
10
lib/controllers/launch_scope.dart
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||||
|
|
||||||
|
class LaunchScopeController extends Notifier<bool> {
|
||||||
|
@override
|
||||||
|
bool build() => true;
|
||||||
|
|
||||||
|
static final provider = NotifierProvider<LaunchScopeController, bool>(
|
||||||
|
LaunchScopeController.new,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||||
import "package:flutter/services.dart";
|
import "package:flutter/services.dart";
|
||||||
import "package:material_ui/material_ui.dart";
|
import "package:material_ui/material_ui.dart";
|
||||||
import "package:nexus/controllers/active_account.dart";
|
import "package:nexus/controllers/active_account.dart";
|
||||||
|
import "package:nexus/controllers/launch_scope.dart";
|
||||||
import "package:nexus/controllers/portal.dart";
|
import "package:nexus/controllers/portal.dart";
|
||||||
import "package:nexus/controllers/rooms.dart";
|
import "package:nexus/controllers/rooms.dart";
|
||||||
import "package:nexus/controllers/sidebar_page.dart";
|
import "package:nexus/controllers/sidebar_page.dart";
|
||||||
|
|
@ -63,6 +64,17 @@ class NotificationController
|
||||||
AndroidFlutterLocalNotificationsPlugin
|
AndroidFlutterLocalNotificationsPlugin
|
||||||
>()
|
>()
|
||||||
?.deleteNotificationChannel(channelId: "messages");
|
?.deleteNotificationChannel(channelId: "messages");
|
||||||
|
|
||||||
|
// Taps that launched the app don't reach the callback above
|
||||||
|
if (!isInBackground && ref.read(LaunchScopeController.provider)) {
|
||||||
|
if (await notifications.getNotificationAppLaunchDetails()
|
||||||
|
case NotificationAppLaunchDetails(
|
||||||
|
didNotificationLaunchApp: true,
|
||||||
|
notificationResponse: NotificationResponse(:final payload?),
|
||||||
|
)) {
|
||||||
|
_open(payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reading a room, here or on another client, dismisses its notifications
|
// Reading a room, here or on another client, dismisses its notifications
|
||||||
|
|
@ -95,10 +107,8 @@ class NotificationController
|
||||||
|
|
||||||
static String payloadFor(String accountId, int rowId) => "$accountId:$rowId";
|
static String payloadFor(String accountId, int rowId) => "$accountId:$rowId";
|
||||||
|
|
||||||
static const _androidGroup = "nexus.federated.nexus.MESSAGES";
|
|
||||||
static const _summaryPayload = "summary";
|
|
||||||
|
|
||||||
static const _messagesChannel = "messages_v2";
|
static const _messagesChannel = "messages_v2";
|
||||||
|
static const _androidGroup = "nexus.federated.nexus.MESSAGES";
|
||||||
|
|
||||||
/// Dismisses the notifications shown for [threadIds].
|
/// Dismisses the notifications shown for [threadIds].
|
||||||
Future<void> dismiss(ISet<String> threadIds) async {
|
Future<void> dismiss(ISet<String> threadIds) async {
|
||||||
|
|
@ -131,7 +141,6 @@ class NotificationController
|
||||||
navigatorKey.currentState?.popUntil((route) => route.isFirst);
|
navigatorKey.currentState?.popUntil((route) => route.isFirst);
|
||||||
ref.read(SidebarPageController.provider.notifier).set(.notifications);
|
ref.read(SidebarPageController.provider.notifier).set(.notifications);
|
||||||
|
|
||||||
// The summary's payload has no row, so it only opens the notifications
|
|
||||||
final (accountId, rowId) = switch (payload.split(":")) {
|
final (accountId, rowId) = switch (payload.split(":")) {
|
||||||
[final accountId, final rowId] => (accountId, int.tryParse(rowId)),
|
[final accountId, final rowId] => (accountId, int.tryParse(rowId)),
|
||||||
// From before notifications were per account
|
// From before notifications were per account
|
||||||
|
|
@ -334,7 +343,7 @@ class NotificationController
|
||||||
await controller.show(
|
await controller.show(
|
||||||
id: 0,
|
id: 0,
|
||||||
title: "Nexus",
|
title: "Nexus",
|
||||||
payload: _summaryPayload,
|
payload: payload,
|
||||||
notificationDetails: const .new(
|
notificationDetails: const .new(
|
||||||
android: .new(
|
android: .new(
|
||||||
_messagesChannel,
|
_messagesChannel,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import "package:flutter_riverpod/flutter_riverpod.dart";
|
||||||
import "package:flutter_riverpod/misc.dart";
|
import "package:flutter_riverpod/misc.dart";
|
||||||
import "package:material_ui/material_ui.dart";
|
import "package:material_ui/material_ui.dart";
|
||||||
import "package:nexus/controllers/active_account.dart";
|
import "package:nexus/controllers/active_account.dart";
|
||||||
|
import "package:nexus/controllers/launch_scope.dart";
|
||||||
import "package:nexus/controllers/notification_request.dart";
|
import "package:nexus/controllers/notification_request.dart";
|
||||||
|
|
||||||
/// Runs [child] as one account, in a [ProviderScope] of its own that's
|
/// Runs [child] as one account, in a [ProviderScope] of its own that's
|
||||||
|
|
@ -23,6 +24,7 @@ class const AccountScope({
|
||||||
accountId: initialAccountId,
|
accountId: initialAccountId,
|
||||||
notificationRowId: null,
|
notificationRowId: null,
|
||||||
));
|
));
|
||||||
|
final isLaunch = useState(true);
|
||||||
|
|
||||||
return ProviderScope(
|
return ProviderScope(
|
||||||
key: ValueKey(active.value.accountId),
|
key: ValueKey(active.value.accountId),
|
||||||
|
|
@ -30,14 +32,17 @@ class const AccountScope({
|
||||||
observers: observers,
|
observers: observers,
|
||||||
overrides: [
|
overrides: [
|
||||||
ActiveAccountController.provider.overrideWith(
|
ActiveAccountController.provider.overrideWith(
|
||||||
() => ActiveAccountController(
|
() => ActiveAccountController(active.value.accountId, (next) {
|
||||||
active.value.accountId,
|
isLaunch.value = false;
|
||||||
(next) => active.value = next,
|
active.value = next;
|
||||||
),
|
}),
|
||||||
),
|
),
|
||||||
NotificationRequestController.provider.overrideWithBuild(
|
NotificationRequestController.provider.overrideWithBuild(
|
||||||
(_, _) => active.value.notificationRowId,
|
(_, _) => active.value.notificationRowId,
|
||||||
),
|
),
|
||||||
|
LaunchScopeController.provider.overrideWithBuild(
|
||||||
|
(_, _) => isLaunch.value,
|
||||||
|
),
|
||||||
...overrides,
|
...overrides,
|
||||||
],
|
],
|
||||||
child: child,
|
child: child,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue