mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-27 20:44:12 +01:00
feat: support push for multi accounts
Signed-off-by: The one with the braid <the-one@with-the-braid.cf>
This commit is contained in:
parent
78a5206ba7
commit
49e3beb39e
@ -23,6 +23,7 @@ import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
@ -46,7 +47,7 @@ class NoTokenException implements Exception {
|
||||
}
|
||||
|
||||
class BackgroundPush {
|
||||
static BackgroundPush? _instance;
|
||||
static final Map<int, BackgroundPush?> _instance = {};
|
||||
final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin =
|
||||
FlutterLocalNotificationsPlugin();
|
||||
Client client;
|
||||
@ -56,7 +57,9 @@ class BackgroundPush {
|
||||
void Function(String errorMsg, {Uri? link})? onFcmError;
|
||||
L10n? l10n;
|
||||
Store? _store;
|
||||
|
||||
Store get store => _store ??= Store();
|
||||
|
||||
Future<void> loadLocale() async {
|
||||
// inspired by _lookupL10n in .dart_tool/flutter_gen/gen_l10n/l10n.dart
|
||||
l10n ??= (context != null ? L10n.of(context!) : null) ??
|
||||
@ -96,8 +99,8 @@ class BackgroundPush {
|
||||
}
|
||||
|
||||
factory BackgroundPush.clientOnly(Client client) {
|
||||
_instance ??= BackgroundPush._(client);
|
||||
return _instance!;
|
||||
_instance[client.id!] ??= BackgroundPush._(client);
|
||||
return _instance[client.id!]!;
|
||||
}
|
||||
|
||||
factory BackgroundPush(
|
||||
@ -236,7 +239,7 @@ class BackgroundPush {
|
||||
return;
|
||||
}
|
||||
_wentToRoomOnStartup = true;
|
||||
goToRoom(details.notificationResponse);
|
||||
goToRoom(details.notificationResponse, client.id);
|
||||
});
|
||||
}
|
||||
|
||||
@ -280,8 +283,13 @@ class BackgroundPush {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> goToRoom(NotificationResponse? response) async {
|
||||
Future<void> goToRoom(NotificationResponse? response, [int? clientId]) async {
|
||||
try {
|
||||
final context = this.context;
|
||||
if (context != null) {
|
||||
Matrix.of(context).setActiveClient(client);
|
||||
}
|
||||
|
||||
final roomId = response?.payload;
|
||||
Logs().v('[Push] Attempting to go to room $roomId...');
|
||||
if (router == null || roomId == null) {
|
||||
@ -381,6 +389,7 @@ class BackgroundPush {
|
||||
/// sort by [roomId] which is a String. To make sure that we don't have duplicated
|
||||
/// IDs we map the [roomId] to a number and store this number.
|
||||
late Map<String, int> idMap;
|
||||
|
||||
Future<void> _loadIdMap() async {
|
||||
idMap = Map<String, int>.from(json.decode(
|
||||
(await store.getItem(SettingKeys.notificationCurrentIds)) ?? '{}'));
|
||||
@ -407,6 +416,7 @@ class BackgroundPush {
|
||||
}
|
||||
|
||||
bool _clearingPushLock = false;
|
||||
|
||||
Future<void> _onClearingPush({bool getFromServer = true}) async {
|
||||
if (_clearingPushLock) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user