forked from Nexus/nexus
add wip deregistering
This commit is contained in:
parent
0122feae1d
commit
129f0794f2
7 changed files with 113 additions and 40 deletions
|
|
@ -11,7 +11,6 @@ import "package:nexus/controllers/client.dart";
|
|||
import "package:nexus/controllers/client_state.dart";
|
||||
import "package:nexus/models/content/message.dart";
|
||||
import "package:nexus/models/content/sticker.dart";
|
||||
import "package:nexus/models/requests/get_event.dart";
|
||||
import "package:nexus/models/requests/register_pusher.dart";
|
||||
import "package:unifiedpush/unifiedpush.dart";
|
||||
import "package:unifiedpush_storage_shared_preferences/storage.dart";
|
||||
|
|
@ -52,9 +51,10 @@ class UnifiedPushController extends AsyncNotifier<bool> {
|
|||
json.decode(String.fromCharCodes(message.content)),
|
||||
);
|
||||
|
||||
if (event.unreadType?.shouldNotify != true ||
|
||||
if (event == null ||
|
||||
event.unreadType?.shouldNotify != true ||
|
||||
(!isInBackground &&
|
||||
await windowManager.isFocused() &&
|
||||
await windowManager.isFocused().onError((_, _) => false) &&
|
||||
ref.watch(KeyController.provider(KeyController.roomKey)) ==
|
||||
event.roomId)) {
|
||||
return;
|
||||
|
|
@ -77,9 +77,7 @@ class UnifiedPushController extends AsyncNotifier<bool> {
|
|||
id: event.eventId.hashCode & 0x7fffffff,
|
||||
title: room?.metadata?.name ?? "New Event",
|
||||
icon: icon,
|
||||
payload: json.encode(
|
||||
GetEventRequest(eventId: event.eventId, roomId: event.roomId),
|
||||
),
|
||||
payload: event.eventId,
|
||||
body: switch (event.content) {
|
||||
MessageContent(:final body?) ||
|
||||
StickerContent(:final body) => body,
|
||||
|
|
@ -128,6 +126,24 @@ class UnifiedPushController extends AsyncNotifier<bool> {
|
|||
if (!alreadyRegistered) ref.invalidateSelf();
|
||||
}
|
||||
|
||||
Future<void> deregister() async {
|
||||
final clientState = ref.watch(ClientStateController.provider);
|
||||
final key = await UnifiedPushStorageSharedPreferences().keys.get(
|
||||
clientState!.deviceId!,
|
||||
);
|
||||
|
||||
if (key == null) return;
|
||||
|
||||
await ref
|
||||
.watch(ClientController.provider.notifier)
|
||||
.deregisterPusher(
|
||||
.new(appId: "nexus.federated.nexus", pushKey: key.split("=").first),
|
||||
);
|
||||
|
||||
await UnifiedPush.unregister(clientState.deviceId!);
|
||||
ref.invalidateSelf();
|
||||
}
|
||||
|
||||
static final provider = AsyncNotifierProvider<UnifiedPushController, bool>(
|
||||
UnifiedPushController.new,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue