Skip to content

Commit

Permalink
Synchronize local state with back-end state at loading
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasBuquet committed Oct 10, 2023
1 parent 1349b8a commit 1309b40
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions Riot/Modules/MatrixKit/Models/Account/MXKAccount.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<MXPusher *> *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();
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 1309b40

Please sign in to comment.