Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Privacy: Store Identity Server in Account Data (MSC2230)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuroe committed Sep 5, 2019
1 parent c631a8d commit a2313d3
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion MatrixKit/Models/Account/MXKAccount.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ - (instancetype)initWithCredentials:(MXCredentials*)credentials

// Refresh device information
[self loadDeviceInformation:nil failure:nil];


[self registerAccountDataDidChangeIdentityServerNotification];
[self registerIdentityServiceDidChangeAccessTokenNotification];
}
return self;
Expand Down Expand Up @@ -171,6 +172,7 @@ - (id)initWithCoder:(NSCoder *)coder

[self prepareRESTClient];

[self registerAccountDataDidChangeIdentityServerNotification];
[self registerIdentityServiceDidChangeAccessTokenNotification];

if ([coder decodeObjectForKey:@"threePIDs"])
Expand Down Expand Up @@ -1975,6 +1977,34 @@ - (void)checkSyncFilterCompatibility:(MXFilterJSONModel*)syncFilter completion:(
}
}


#pragma mark - Identity Server updates

- (void)registerAccountDataDidChangeIdentityServerNotification
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAccountDataDidChangeIdentityServerNotification:) name:kMXSessionAccountDataDidChangeIdentityServerNotification object:nil];
}

- (void)handleAccountDataDidChangeIdentityServerNotification:(NSNotification*)notification
{
MXSession *mxSession = notification.object;
if (mxSession == self.mxSession)
{
if (![mxCredentials.identityServer isEqualToString:self.mxSession.accountDataIdentityServer])
{
_identityServerURL = self.mxSession.accountDataIdentityServer;
mxCredentials.identityServer = _identityServerURL;
mxCredentials.identityServerAccessToken = nil;

// Archive updated field
[[MXKAccountManager sharedManager] saveAccounts];
}
}
}


#pragma mark - Identity Server Access Token updates

- (void)identityService:(MXIdentityService *)identityService didUpdateAccessToken:(NSString *)accessToken
{
mxCredentials.identityServerAccessToken = accessToken;
Expand All @@ -1996,6 +2026,9 @@ - (void)handleIdentityServiceDidChangeAccessTokenNotification:(NSNotification*)n
if (userId && identityServer && accessToken && [mxCredentials.identityServer isEqualToString:identityServer])
{
mxCredentials.identityServerAccessToken = accessToken;

// Archive updated field
[[MXKAccountManager sharedManager] saveAccounts];
}
}

Expand Down

0 comments on commit a2313d3

Please sign in to comment.