Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 01e0724

Browse files
committedNov 2, 2024
feat[UP]: Add settings migration
1 parent 6d09286 commit 01e0724

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed
 

‎lib/main.dart

-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ void main() async {
2525
final store = await SharedPreferences.getInstance();
2626
final clients = await ClientManager.getClients(store: store);
2727

28-
//TODO: migrate single client push settings to multiclient settings
29-
3028
// If the app starts in detached mode, we assume that it is in
3129
// background fetch mode for processing push notifications. This is
3230
// currently only supported on Android.

‎lib/utils/background_push.dart

+25-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class BackgroundPush {
197197
)) {
198198
Logs().i('[Push] Pusher already set');
199199
} else {
200-
Logs().i('Need to set new pusher');
200+
Logs().i('[Push] Need to set new pusher');
201201
oldTokens.add(token);
202202
if (client.isLogged()) {
203203
setNewPusher = true;
@@ -253,6 +253,27 @@ class BackgroundPush {
253253

254254
Future<void> setupPush(List<Client> clients) async {
255255
Logs().d("SetupPush");
256+
257+
{
258+
// migrate single client push settings to multiclient settings
259+
final endpoint = matrix!.store.getString(SettingKeys.unifiedPushEndpoint);
260+
if (endpoint != null) {
261+
matrix!.store.setString(
262+
clients.first.clientName + SettingKeys.unifiedPushEndpoint,
263+
endpoint);
264+
matrix!.store.remove(SettingKeys.unifiedPushEndpoint);
265+
}
266+
267+
final registered =
268+
matrix!.store.getBool(SettingKeys.unifiedPushRegistered);
269+
if (registered != null) {
270+
matrix!.store.setBool(
271+
clients.first.clientName + SettingKeys.unifiedPushRegistered,
272+
registered);
273+
matrix!.store.remove(SettingKeys.unifiedPushRegistered);
274+
}
275+
}
276+
256277
if (clients.first.onLoginStateChanged.value != LoginState.loggedIn ||
257278
!PlatformInfos.isMobile ||
258279
matrix == null) {
@@ -420,7 +441,9 @@ class BackgroundPush {
420441
client: client,
421442
);
422443
await matrix?.store.setString(
423-
client.clientName + SettingKeys.unifiedPushEndpoint, newEndpoint);
444+
client.clientName + SettingKeys.unifiedPushEndpoint,
445+
newEndpoint,
446+
);
424447
await matrix?.store
425448
.setBool(client.clientName + SettingKeys.unifiedPushRegistered, true);
426449
}

0 commit comments

Comments
 (0)
Please sign in to comment.