From 1309b4051b7346b6cff065d54bc0f14e6b2dc3c5 Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Tue, 10 Oct 2023 17:02:03 +0200 Subject: [PATCH] Synchronize local state with back-end state at loading --- .../MatrixKit/Models/Account/MXKAccount.m | 48 +++++++------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/Riot/Modules/MatrixKit/Models/Account/MXKAccount.m b/Riot/Modules/MatrixKit/Models/Account/MXKAccount.m index 1f9cd150d..2d5ede9e8 100644 --- a/Riot/Modules/MatrixKit/Models/Account/MXKAccount.m +++ b/Riot/Modules/MatrixKit/Models/Account/MXKAccount.m @@ -851,45 +851,33 @@ - (void)loadCurrentApnsPusher:(void (^)(void))success failure:(void (^)(NSError // Tchap: email notifications - (void)loadCurrentEmailPusher:(void (^)(void))success failure:(void (^)(NSError *error))failure { - // DeviceId not needed nor present for Email pusher -// if (!self.mxSession.myDeviceId) -// { -// MXLogWarning(@"[MXKAccount] loadEmailPusher: device ID not found"); -// if (failure) -// { -// failure([NSError errorWithDomain:kMXKAccountErrorDomain code:0 userInfo:nil]); -// } -// return; -// } - [self.mxSession supportedMatrixVersions:^(MXMatrixVersions *matrixVersions) { - // Tchpa: TODO check for supportsRemotelyTogglingEmailNotifications -// if (!matrixVersions.supportsRemotelyTogglingPushNotifications) -// { -// MXLogDebug(@"[MXKAccount] loadEmailPusher: remotely toggling push notifications not supported"); -// -// if (success) -// { -// success(); -// } -// -// return; -// } [self.mxSession.matrixRestClient pushers:^(NSArray *pushers) { MXPusher *emailPusher; for (MXPusher *pusher in pushers) { -// if ([pusher.deviceId isEqualToString:self.mxSession.myDeviceId]) { - if ([pusher.kind isEqualToString:@"email"]) - { - emailPusher = pusher; - } -// } + if ([pusher.kind isEqualToString:@"email"]) + { + emailPusher = pusher; + } } + // On application launch, if email notification is activated on the back-end + // emailPusher is not nil here. self->currentEmailPusher = emailPusher; + if (self->currentEmailPusher == nil) + { + self->_hasPusherForEmailNotifications = NO; + [[MXKAccountManager sharedManager] saveAccounts]; + } + else + { + self->_hasPusherForEmailNotifications = YES; + [[MXKAccountManager sharedManager] saveAccounts]; + } + if (success) { success(); @@ -1531,7 +1519,7 @@ - (void)enableAPNSPusher:(BOOL)enabled success:(void (^)(void))success failure:( } // Tchap: handle Email notification -// Refresh the Email pusher state for this account on this device. +// Refresh the Email pusher state for this account. - (void)refreshEmailPusher { MXLogDebug(@"[MXKAccount][Email] refreshEmailPusher");