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) =>
|
||||
sendCommand("register_homeserver_push", request.toJson());
|
||||
|
||||
Future<void> deregisterPusher(DeregisterPusherRequest request) =>
|
||||
sendCommand("register_homeserver_push", {
|
||||
...request.toJson(),
|
||||
"kind": null,
|
||||
});
|
||||
Future<void> deregisterPusher(DeregisterPusherRequest request) => sendCommand(
|
||||
"register_homeserver_push",
|
||||
{...request.toJson(), "kind": null},
|
||||
);
|
||||
|
||||
Future<MessageContent> uploadMedia(UploadMediaRequest request) async =>
|
||||
.fromJson(await sendCommand("upload_media", request.toJson()));
|
||||
|
||||
Future<File> downloadMedia(DownloadMediaRequest request) async {
|
||||
if (accountId == null &&
|
||||
!isInBackground &&
|
||||
ref.read(ClientStateController.provider)?.isLoggedIn != true) {
|
||||
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:material_ui/material_ui.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/rooms.dart";
|
||||
import "package:nexus/controllers/sidebar_page.dart";
|
||||
|
|
@ -63,6 +64,17 @@ class NotificationController
|
|||
AndroidFlutterLocalNotificationsPlugin
|
||||
>()
|
||||
?.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
|
||||
|
|
@ -95,10 +107,8 @@ class NotificationController
|
|||
|
||||
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 _androidGroup = "nexus.federated.nexus.MESSAGES";
|
||||
|
||||
/// Dismisses the notifications shown for [threadIds].
|
||||
Future<void> dismiss(ISet<String> threadIds) async {
|
||||
|
|
@ -131,7 +141,6 @@ class NotificationController
|
|||
navigatorKey.currentState?.popUntil((route) => route.isFirst);
|
||||
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, final rowId] => (accountId, int.tryParse(rowId)),
|
||||
// From before notifications were per account
|
||||
|
|
@ -334,7 +343,7 @@ class NotificationController
|
|||
await controller.show(
|
||||
id: 0,
|
||||
title: "Nexus",
|
||||
payload: _summaryPayload,
|
||||
payload: payload,
|
||||
notificationDetails: const .new(
|
||||
android: .new(
|
||||
_messagesChannel,
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import "package:flutter_riverpod/flutter_riverpod.dart";
|
|||
import "package:flutter_riverpod/misc.dart";
|
||||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/controllers/active_account.dart";
|
||||
import "package:nexus/controllers/launch_scope.dart";
|
||||
import "package:nexus/controllers/notification_request.dart";
|
||||
|
||||
/// Runs [child] as one account, in a [ProviderScope] of its own that's
|
||||
|
|
@ -23,6 +24,7 @@ class const AccountScope({
|
|||
accountId: initialAccountId,
|
||||
notificationRowId: null,
|
||||
));
|
||||
final isLaunch = useState(true);
|
||||
|
||||
return ProviderScope(
|
||||
key: ValueKey(active.value.accountId),
|
||||
|
|
@ -30,14 +32,17 @@ class const AccountScope({
|
|||
observers: observers,
|
||||
overrides: [
|
||||
ActiveAccountController.provider.overrideWith(
|
||||
() => ActiveAccountController(
|
||||
active.value.accountId,
|
||||
(next) => active.value = next,
|
||||
),
|
||||
() => ActiveAccountController(active.value.accountId, (next) {
|
||||
isLaunch.value = false;
|
||||
active.value = next;
|
||||
}),
|
||||
),
|
||||
NotificationRequestController.provider.overrideWithBuild(
|
||||
(_, _) => active.value.notificationRowId,
|
||||
),
|
||||
LaunchScopeController.provider.overrideWithBuild(
|
||||
(_, _) => isLaunch.value,
|
||||
),
|
||||
...overrides,
|
||||
],
|
||||
child: child,
|
||||
|
|
|
|||
Loading…
Reference in a new issue