mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 15:09:31 +02:00
Split MXKAccount from Data so just data can be loaded from disk without side effects. Also change force reload of accounts to stop double load on init.
This commit is contained in:
@@ -340,7 +340,7 @@ static const CGFloat kAuthInputContainerViewMinHeightConstraintConstant = 150.0;
|
|||||||
didCheckFalseAuthScreenDisplay = YES;
|
didCheckFalseAuthScreenDisplay = YES;
|
||||||
|
|
||||||
MXLogDebug(@"[AuthenticationVC] viewDidAppear: Checking false logout");
|
MXLogDebug(@"[AuthenticationVC] viewDidAppear: Checking false logout");
|
||||||
[[MXKAccountManager sharedManager] forceReloadAccounts];
|
[MXKAccountManager sharedManagerWithReload: YES];
|
||||||
if ([MXKAccountManager sharedManager].activeAccounts.count)
|
if ([MXKAccountManager sharedManager].activeAccounts.count)
|
||||||
{
|
{
|
||||||
// For now, we do not have better solution than forcing the user to restart the app
|
// For now, we do not have better solution than forcing the user to restart the app
|
||||||
|
|||||||
@@ -1451,6 +1451,8 @@
|
|||||||
|
|
||||||
MXRestClient *mxRestClient = [[MXRestClient alloc] initWithCredentials:credentials andOnUnrecognizedCertificateBlock:^BOOL(NSData *certificate) {
|
MXRestClient *mxRestClient = [[MXRestClient alloc] initWithCredentials:credentials andOnUnrecognizedCertificateBlock:^BOOL(NSData *certificate) {
|
||||||
return NO;
|
return NO;
|
||||||
|
} andPersistentTokenDataHandler:^(void (^handler)(NSArray<MXCredentials *> *credentials, void (^completion)(BOOL didUpdateCredentials))) {
|
||||||
|
[[MXKAccountManager sharedManager] readAndWriteCredentials:handler];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
MXWeakify(self);
|
MXWeakify(self);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#import <MatrixSDK/MatrixSDK.h>
|
#import <MatrixSDK/MatrixSDK.h>
|
||||||
|
#import "MXKAccountData.h"
|
||||||
|
|
||||||
@class MXKAccount;
|
@class MXKAccount;
|
||||||
|
|
||||||
@@ -56,29 +57,7 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
|
|||||||
`MXKAccount` object contains the credentials of a logged matrix user. It is used to handle matrix
|
`MXKAccount` object contains the credentials of a logged matrix user. It is used to handle matrix
|
||||||
session and presence for this user.
|
session and presence for this user.
|
||||||
*/
|
*/
|
||||||
@interface MXKAccount : NSObject <NSCoding>
|
@interface MXKAccount : MXKAccountData
|
||||||
|
|
||||||
/**
|
|
||||||
The account's credentials: homeserver, access token, user id.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, readonly) MXCredentials *mxCredentials;
|
|
||||||
|
|
||||||
/**
|
|
||||||
The identity server URL.
|
|
||||||
*/
|
|
||||||
@property (nonatomic) NSString *identityServerURL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
The antivirus server URL, if any (nil by default).
|
|
||||||
Set a non-null url to configure the antivirus scanner use.
|
|
||||||
*/
|
|
||||||
@property (nonatomic) NSString *antivirusServerURL;
|
|
||||||
|
|
||||||
/**
|
|
||||||
The Push Gateway URL used to send event notifications to (nil by default).
|
|
||||||
This URL should be over HTTPS and never over HTTP.
|
|
||||||
*/
|
|
||||||
@property (nonatomic) NSString *pushGatewayURL;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The matrix REST client used to make matrix API requests.
|
The matrix REST client used to make matrix API requests.
|
||||||
@@ -107,12 +86,6 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly) NSString *fullDisplayName;
|
@property (nonatomic, readonly) NSString *fullDisplayName;
|
||||||
|
|
||||||
/**
|
|
||||||
The 3PIDs linked to this account.
|
|
||||||
[self load3PIDs] must be called to update the property.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, readonly) NSArray<MXThirdPartyIdentifier *> *threePIDs;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The email addresses linked to this account.
|
The email addresses linked to this account.
|
||||||
This is a subset of self.threePIDs.
|
This is a subset of self.threePIDs.
|
||||||
@@ -125,12 +98,6 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly) NSArray<NSString *> *linkedPhoneNumbers;
|
@property (nonatomic, readonly) NSArray<NSString *> *linkedPhoneNumbers;
|
||||||
|
|
||||||
/**
|
|
||||||
The account user's device.
|
|
||||||
[self loadDeviceInformation] must be called to update the property.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, readonly) MXDevice *device;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The account user's presence (`MXPresenceUnknown` by default, available if matrix session `mxSession` is opened).
|
The account user's presence (`MXPresenceUnknown` by default, available if matrix session `mxSession` is opened).
|
||||||
The notification `kMXKAccountUserInfoDidChangeNotification` is posted in case of change of this property.
|
The notification `kMXKAccountUserInfoDidChangeNotification` is posted in case of change of this property.
|
||||||
@@ -148,11 +115,6 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly) BOOL pushNotificationServiceIsActive;
|
@property (nonatomic, readonly) BOOL pushNotificationServiceIsActive;
|
||||||
|
|
||||||
/**
|
|
||||||
Transient information storage.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, strong, readonly) NSMutableDictionary<NSString *, id<NSCoding>> *others;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Enable Push notification based on Apple Push Notification Service (APNS).
|
Enable Push notification based on Apple Push Notification Service (APNS).
|
||||||
|
|
||||||
@@ -166,11 +128,6 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
|
|||||||
success:(void (^)(void))success
|
success:(void (^)(void))success
|
||||||
failure:(void (^)(NSError *))failure;
|
failure:(void (^)(NSError *))failure;
|
||||||
|
|
||||||
/**
|
|
||||||
Flag to indicate that an APNS pusher has been set on the homeserver for this device.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, readonly) BOOL hasPusherForPushNotifications;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The Push notification activity (based on PushKit) for this account.
|
The Push notification activity (based on PushKit) for this account.
|
||||||
YES when Push is turned on (locally available and enabled homeserver side).
|
YES when Push is turned on (locally available and enabled homeserver side).
|
||||||
@@ -190,26 +147,6 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
|
|||||||
success:(void (^)(void))success
|
success:(void (^)(void))success
|
||||||
failure:(void (^)(NSError *))failure;
|
failure:(void (^)(NSError *))failure;
|
||||||
|
|
||||||
/**
|
|
||||||
Flag to indicate that a PushKit pusher has been set on the homeserver for this device.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, readonly) BOOL hasPusherForPushKitNotifications;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
Enable In-App notifications based on Remote notifications rules.
|
|
||||||
NO by default.
|
|
||||||
*/
|
|
||||||
@property (nonatomic) BOOL enableInAppNotifications;
|
|
||||||
|
|
||||||
/**
|
|
||||||
Disable the account without logging out (NO by default).
|
|
||||||
|
|
||||||
A matrix session is automatically opened for the account when this property is toggled from YES to NO.
|
|
||||||
The session is closed when this property is set to YES.
|
|
||||||
*/
|
|
||||||
@property (nonatomic,getter=isDisabled) BOOL disabled;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Manage the online presence event.
|
Manage the online presence event.
|
||||||
|
|
||||||
@@ -217,11 +154,6 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
|
|||||||
*/
|
*/
|
||||||
@property (nonatomic) BOOL hideUserPresence;
|
@property (nonatomic) BOOL hideUserPresence;
|
||||||
|
|
||||||
/**
|
|
||||||
Flag indicating if the end user has been warned about encryption and its limitations.
|
|
||||||
*/
|
|
||||||
@property (nonatomic,getter=isWarnedAboutEncryption) BOOL warnedAboutEncryption;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Register the MXKAccountOnCertificateChange block that will be used to handle certificate change during account use.
|
Register the MXKAccountOnCertificateChange block that will be used to handle certificate change during account use.
|
||||||
This block is nil by default, any new certificate is ignored/untrusted (this will abort the connection to the server).
|
This block is nil by default, any new certificate is ignored/untrusted (this will abort the connection to the server).
|
||||||
@@ -284,11 +216,6 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
|
|||||||
|
|
||||||
#pragma mark - Soft logout
|
#pragma mark - Soft logout
|
||||||
|
|
||||||
/**
|
|
||||||
Flag to indicate if the account has been logged out by the homeserver admin.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, readonly) BOOL isSoftLogout;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Soft logout the account.
|
Soft logout the account.
|
||||||
|
|
||||||
|
|||||||
@@ -92,13 +92,10 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
@property (nonatomic, strong) id<MXBackgroundTask> backgroundTask;
|
@property (nonatomic, strong) id<MXBackgroundTask> backgroundTask;
|
||||||
@property (nonatomic, strong) id<MXBackgroundTask> backgroundSyncBgTask;
|
@property (nonatomic, strong) id<MXBackgroundTask> backgroundSyncBgTask;
|
||||||
|
|
||||||
@property (nonatomic, strong) NSMutableDictionary<NSString *, id<NSCoding>> *others;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MXKAccount
|
@implementation MXKAccount
|
||||||
@synthesize mxCredentials, mxSession, mxRestClient;
|
@synthesize mxSession, mxRestClient;
|
||||||
@synthesize threePIDs;
|
|
||||||
@synthesize userPresence;
|
@synthesize userPresence;
|
||||||
@synthesize userTintColor;
|
@synthesize userTintColor;
|
||||||
@synthesize hideUserPresence;
|
@synthesize hideUserPresence;
|
||||||
@@ -144,7 +141,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
notifyOpenSessionFailure = YES;
|
notifyOpenSessionFailure = YES;
|
||||||
|
|
||||||
// Report credentials and alloc REST client.
|
// Report credentials and alloc REST client.
|
||||||
mxCredentials = credentials;
|
_mxCredentials = credentials;
|
||||||
[self prepareRESTClient];
|
[self prepareRESTClient];
|
||||||
|
|
||||||
userPresence = MXPresenceUnknown;
|
userPresence = MXPresenceUnknown;
|
||||||
@@ -171,67 +168,19 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
|
|
||||||
- (id)initWithCoder:(NSCoder *)coder
|
- (id)initWithCoder:(NSCoder *)coder
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super initWithCoder:coder];
|
||||||
|
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
notifyOpenSessionFailure = YES;
|
notifyOpenSessionFailure = YES;
|
||||||
|
|
||||||
NSString *homeServerURL = [coder decodeObjectForKey:@"homeserverurl"];
|
|
||||||
NSString *userId = [coder decodeObjectForKey:@"userid"];
|
|
||||||
NSString *accessToken = [coder decodeObjectForKey:@"accesstoken"];
|
|
||||||
_identityServerURL = [coder decodeObjectForKey:@"identityserverurl"];
|
|
||||||
NSString *identityServerAccessToken = [coder decodeObjectForKey:@"identityserveraccesstoken"];
|
|
||||||
|
|
||||||
mxCredentials = [[MXCredentials alloc] initWithHomeServer:homeServerURL
|
|
||||||
userId:userId
|
|
||||||
accessToken:accessToken];
|
|
||||||
|
|
||||||
mxCredentials.accessTokenExpiresAt = [coder decodeInt64ForKey:@"accessTokenExpiresAt"];
|
|
||||||
mxCredentials.refreshToken = [coder decodeObjectForKey:@"refreshToken"];
|
|
||||||
mxCredentials.identityServer = _identityServerURL;
|
|
||||||
mxCredentials.identityServerAccessToken = identityServerAccessToken;
|
|
||||||
mxCredentials.deviceId = [coder decodeObjectForKey:@"deviceId"];
|
|
||||||
mxCredentials.allowedCertificate = [coder decodeObjectForKey:@"allowedCertificate"];
|
|
||||||
|
|
||||||
[self prepareRESTClient];
|
[self prepareRESTClient];
|
||||||
|
|
||||||
[self registerAccountDataDidChangeIdentityServerNotification];
|
[self registerAccountDataDidChangeIdentityServerNotification];
|
||||||
[self registerIdentityServiceDidChangeAccessTokenNotification];
|
[self registerIdentityServiceDidChangeAccessTokenNotification];
|
||||||
|
|
||||||
if ([coder decodeObjectForKey:@"threePIDs"])
|
|
||||||
{
|
|
||||||
threePIDs = [coder decodeObjectForKey:@"threePIDs"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([coder decodeObjectForKey:@"device"])
|
|
||||||
{
|
|
||||||
_device = [coder decodeObjectForKey:@"device"];
|
|
||||||
}
|
|
||||||
|
|
||||||
userPresence = MXPresenceUnknown;
|
userPresence = MXPresenceUnknown;
|
||||||
|
|
||||||
if ([coder decodeObjectForKey:@"antivirusserverurl"])
|
|
||||||
{
|
|
||||||
_antivirusServerURL = [coder decodeObjectForKey:@"antivirusserverurl"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([coder decodeObjectForKey:@"pushgatewayurl"])
|
|
||||||
{
|
|
||||||
_pushGatewayURL = [coder decodeObjectForKey:@"pushgatewayurl"];
|
|
||||||
}
|
|
||||||
|
|
||||||
_hasPusherForPushNotifications = [coder decodeBoolForKey:@"_enablePushNotifications"];
|
|
||||||
_hasPusherForPushKitNotifications = [coder decodeBoolForKey:@"enablePushKitNotifications"];
|
|
||||||
_enableInAppNotifications = [coder decodeBoolForKey:@"enableInAppNotifications"];
|
|
||||||
|
|
||||||
_disabled = [coder decodeBoolForKey:@"disabled"];
|
|
||||||
_isSoftLogout = [coder decodeBoolForKey:@"isSoftLogout"];
|
|
||||||
|
|
||||||
_warnedAboutEncryption = [coder decodeBoolForKey:@"warnedAboutEncryption"];
|
|
||||||
|
|
||||||
_others = [coder decodeObjectForKey:@"others"];
|
|
||||||
|
|
||||||
// Refresh device information
|
// Refresh device information
|
||||||
[self loadDeviceInformation:nil failure:nil];
|
[self loadDeviceInformation:nil failure:nil];
|
||||||
}
|
}
|
||||||
@@ -239,66 +188,6 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)encodeWithCoder:(NSCoder *)coder
|
|
||||||
{
|
|
||||||
[coder encodeObject:mxCredentials.homeServer forKey:@"homeserverurl"];
|
|
||||||
[coder encodeObject:mxCredentials.userId forKey:@"userid"];
|
|
||||||
[coder encodeObject:mxCredentials.accessToken forKey:@"accesstoken"];
|
|
||||||
if (mxCredentials.accessTokenExpiresAt) {
|
|
||||||
[coder encodeInt64:mxCredentials.accessTokenExpiresAt forKey:@"accessTokenExpiresAt"];
|
|
||||||
}
|
|
||||||
if (mxCredentials.refreshToken) {
|
|
||||||
[coder encodeObject:mxCredentials.refreshToken forKey:@"refreshToken"];
|
|
||||||
}
|
|
||||||
[coder encodeObject:mxCredentials.identityServerAccessToken forKey:@"identityserveraccesstoken"];
|
|
||||||
|
|
||||||
if (mxCredentials.deviceId)
|
|
||||||
{
|
|
||||||
[coder encodeObject:mxCredentials.deviceId forKey:@"deviceId"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mxCredentials.allowedCertificate)
|
|
||||||
{
|
|
||||||
[coder encodeObject:mxCredentials.allowedCertificate forKey:@"allowedCertificate"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.threePIDs)
|
|
||||||
{
|
|
||||||
[coder encodeObject:threePIDs forKey:@"threePIDs"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.device)
|
|
||||||
{
|
|
||||||
[coder encodeObject:_device forKey:@"device"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.identityServerURL)
|
|
||||||
{
|
|
||||||
[coder encodeObject:_identityServerURL forKey:@"identityserverurl"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.antivirusServerURL)
|
|
||||||
{
|
|
||||||
[coder encodeObject:_antivirusServerURL forKey:@"antivirusserverurl"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.pushGatewayURL)
|
|
||||||
{
|
|
||||||
[coder encodeObject:_pushGatewayURL forKey:@"pushgatewayurl"];
|
|
||||||
}
|
|
||||||
|
|
||||||
[coder encodeBool:_hasPusherForPushNotifications forKey:@"_enablePushNotifications"];
|
|
||||||
[coder encodeBool:_hasPusherForPushKitNotifications forKey:@"enablePushKitNotifications"];
|
|
||||||
[coder encodeBool:_enableInAppNotifications forKey:@"enableInAppNotifications"];
|
|
||||||
|
|
||||||
[coder encodeBool:_disabled forKey:@"disabled"];
|
|
||||||
[coder encodeBool:_isSoftLogout forKey:@"isSoftLogout"];
|
|
||||||
|
|
||||||
[coder encodeBool:_warnedAboutEncryption forKey:@"warnedAboutEncryption"];
|
|
||||||
|
|
||||||
[coder encodeObject:_others forKey:@"others"];
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Properties
|
#pragma mark - Properties
|
||||||
|
|
||||||
- (void)setIdentityServerURL:(NSString *)identityServerURL
|
- (void)setIdentityServerURL:(NSString *)identityServerURL
|
||||||
@@ -306,10 +195,10 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
if (identityServerURL.length)
|
if (identityServerURL.length)
|
||||||
{
|
{
|
||||||
_identityServerURL = identityServerURL;
|
_identityServerURL = identityServerURL;
|
||||||
mxCredentials.identityServer = identityServerURL;
|
self.mxCredentials.identityServer = identityServerURL;
|
||||||
|
|
||||||
// Update services used in MXSession
|
// Update services used in MXSession
|
||||||
[mxSession setIdentityServer:mxCredentials.identityServer andAccessToken:mxCredentials.identityServerAccessToken];
|
[mxSession setIdentityServer:self.mxCredentials.identityServer andAccessToken:self.mxCredentials.identityServerAccessToken];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -363,24 +252,24 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
{
|
{
|
||||||
if (self.userDisplayName.length)
|
if (self.userDisplayName.length)
|
||||||
{
|
{
|
||||||
return [NSString stringWithFormat:@"%@ (%@)", self.userDisplayName, mxCredentials.userId];
|
return [NSString stringWithFormat:@"%@ (%@)", self.userDisplayName, self.mxCredentials.userId];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return mxCredentials.userId;
|
return self.mxCredentials.userId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray<MXThirdPartyIdentifier *> *)threePIDs
|
//- (NSArray<MXThirdPartyIdentifier *> *)threePIDs
|
||||||
{
|
//{
|
||||||
return threePIDs;
|
// return _threePIDs;
|
||||||
}
|
//}
|
||||||
|
|
||||||
- (NSArray<NSString *> *)linkedEmails
|
- (NSArray<NSString *> *)linkedEmails
|
||||||
{
|
{
|
||||||
NSMutableArray<NSString *> *linkedEmails = [NSMutableArray array];
|
NSMutableArray<NSString *> *linkedEmails = [NSMutableArray array];
|
||||||
|
|
||||||
for (MXThirdPartyIdentifier *threePID in threePIDs)
|
for (MXThirdPartyIdentifier *threePID in self.threePIDs)
|
||||||
{
|
{
|
||||||
if ([threePID.medium isEqualToString:kMX3PIDMediumEmail])
|
if ([threePID.medium isEqualToString:kMX3PIDMediumEmail])
|
||||||
{
|
{
|
||||||
@@ -395,7 +284,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
{
|
{
|
||||||
NSMutableArray<NSString *> *linkedPhoneNumbers = [NSMutableArray array];
|
NSMutableArray<NSString *> *linkedPhoneNumbers = [NSMutableArray array];
|
||||||
|
|
||||||
for (MXThirdPartyIdentifier *threePID in threePIDs)
|
for (MXThirdPartyIdentifier *threePID in self.threePIDs)
|
||||||
{
|
{
|
||||||
if ([threePID.medium isEqualToString:kMX3PIDMediumMSISDN])
|
if ([threePID.medium isEqualToString:kMX3PIDMediumMSISDN])
|
||||||
{
|
{
|
||||||
@@ -410,7 +299,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
{
|
{
|
||||||
if (!userTintColor)
|
if (!userTintColor)
|
||||||
{
|
{
|
||||||
userTintColor = [MXKTools colorWithRGBValue:[mxCredentials.userId hash]];
|
userTintColor = [MXKTools colorWithRGBValue:[self.mxCredentials.userId hash]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return userTintColor;
|
return userTintColor;
|
||||||
@@ -418,7 +307,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
|
|
||||||
- (BOOL)pushNotificationServiceIsActive
|
- (BOOL)pushNotificationServiceIsActive
|
||||||
{
|
{
|
||||||
BOOL pushNotificationServiceIsActive = ([[MXKAccountManager sharedManager] isAPNSAvailable] && _hasPusherForPushNotifications && mxSession);
|
BOOL pushNotificationServiceIsActive = ([[MXKAccountManager sharedManager] isAPNSAvailable] && self.hasPusherForPushNotifications && mxSession);
|
||||||
MXLogDebug(@"[MXKAccount][Push] pushNotificationServiceIsActive: %@", @(pushNotificationServiceIsActive));
|
MXLogDebug(@"[MXKAccount][Push] pushNotificationServiceIsActive: %@", @(pushNotificationServiceIsActive));
|
||||||
|
|
||||||
return pushNotificationServiceIsActive;
|
return pushNotificationServiceIsActive;
|
||||||
@@ -469,7 +358,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (_hasPusherForPushNotifications)
|
else if (self.hasPusherForPushNotifications)
|
||||||
{
|
{
|
||||||
MXLogDebug(@"[MXKAccount][Push] enablePushNotifications: Disable APNS for %@ account", self.mxCredentials.userId);
|
MXLogDebug(@"[MXKAccount][Push] enablePushNotifications: Disable APNS for %@ account", self.mxCredentials.userId);
|
||||||
|
|
||||||
@@ -495,7 +384,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
|
|
||||||
- (BOOL)isPushKitNotificationActive
|
- (BOOL)isPushKitNotificationActive
|
||||||
{
|
{
|
||||||
BOOL isPushKitNotificationActive = ([[MXKAccountManager sharedManager] isPushAvailable] && _hasPusherForPushKitNotifications && mxSession);
|
BOOL isPushKitNotificationActive = ([[MXKAccountManager sharedManager] isPushAvailable] && self.hasPusherForPushKitNotifications && mxSession);
|
||||||
MXLogDebug(@"[MXKAccount][Push] isPushKitNotificationActive: %@", @(isPushKitNotificationActive));
|
MXLogDebug(@"[MXKAccount][Push] isPushKitNotificationActive: %@", @(isPushKitNotificationActive));
|
||||||
|
|
||||||
return isPushKitNotificationActive;
|
return isPushKitNotificationActive;
|
||||||
@@ -543,7 +432,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
failure (error);
|
failure (error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (_hasPusherForPushKitNotifications)
|
else if (self.hasPusherForPushKitNotifications)
|
||||||
{
|
{
|
||||||
MXLogDebug(@"[MXKAccount][Push] enablePushKitNotifications: Disable Push for %@ account", self.mxCredentials.userId);
|
MXLogDebug(@"[MXKAccount][Push] enablePushKitNotifications: Disable Push for %@ account", self.mxCredentials.userId);
|
||||||
|
|
||||||
@@ -641,7 +530,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
success();
|
success();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:self->mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:self.mxCredentials.userId];
|
||||||
}
|
}
|
||||||
failure:failure];
|
failure:failure];
|
||||||
}
|
}
|
||||||
@@ -661,7 +550,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
success();
|
success();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:self->mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:self.mxCredentials.userId];
|
||||||
}
|
}
|
||||||
failure:failure];
|
failure:failure];
|
||||||
}
|
}
|
||||||
@@ -694,9 +583,9 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
|
|
||||||
- (void)load3PIDs:(void (^)(void))success failure:(void (^)(NSError *))failure
|
- (void)load3PIDs:(void (^)(void))success failure:(void (^)(NSError *))failure
|
||||||
{
|
{
|
||||||
|
|
||||||
[mxRestClient threePIDs:^(NSArray<MXThirdPartyIdentifier *> *threePIDs2) {
|
[mxRestClient threePIDs:^(NSArray<MXThirdPartyIdentifier *> *threePIDs2) {
|
||||||
|
self->_threePIDs = threePIDs2;
|
||||||
self->threePIDs = threePIDs2;
|
|
||||||
|
|
||||||
// Archive updated field
|
// Archive updated field
|
||||||
[[MXKAccountManager sharedManager] saveAccounts];
|
[[MXKAccountManager sharedManager] saveAccounts];
|
||||||
@@ -716,9 +605,9 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
|
|
||||||
- (void)loadDeviceInformation:(void (^)(void))success failure:(void (^)(NSError *error))failure
|
- (void)loadDeviceInformation:(void (^)(void))success failure:(void (^)(NSError *error))failure
|
||||||
{
|
{
|
||||||
if (mxCredentials.deviceId)
|
if (self.mxCredentials.deviceId)
|
||||||
{
|
{
|
||||||
[mxRestClient deviceByDeviceId:mxCredentials.deviceId success:^(MXDevice *device) {
|
[mxRestClient deviceByDeviceId:self.mxCredentials.deviceId success:^(MXDevice *device) {
|
||||||
|
|
||||||
self->_device = device;
|
self->_device = device;
|
||||||
|
|
||||||
@@ -759,21 +648,21 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
[mxSession.myUser setPresence:userPresence
|
[mxSession.myUser setPresence:userPresence
|
||||||
andStatusMessage:statusMessage
|
andStatusMessage:statusMessage
|
||||||
success:^{
|
success:^{
|
||||||
MXLogDebug(@"[MXKAccount] %@: set user presence (%lu) succeeded", self->mxCredentials.userId, (unsigned long)self->userPresence);
|
MXLogDebug(@"[MXKAccount] %@: set user presence (%lu) succeeded", self.mxCredentials.userId, (unsigned long)self->userPresence);
|
||||||
if (completion)
|
if (completion)
|
||||||
{
|
{
|
||||||
completion();
|
completion();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:self->mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:self.mxCredentials.userId];
|
||||||
}
|
}
|
||||||
failure:^(NSError *error) {
|
failure:^(NSError *error) {
|
||||||
MXLogDebug(@"[MXKAccount] %@: set user presence (%lu) failed", self->mxCredentials.userId, (unsigned long)self->userPresence);
|
MXLogDebug(@"[MXKAccount] %@: set user presence (%lu) failed", self.mxCredentials.userId, (unsigned long)self->userPresence);
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
else if (hideUserPresence)
|
else if (hideUserPresence)
|
||||||
{
|
{
|
||||||
MXLogDebug(@"[MXKAccount] %@: set user presence is disabled.", mxCredentials.userId);
|
MXLogDebug(@"[MXKAccount] %@: set user presence is disabled.", self.mxCredentials.userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -791,7 +680,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
-(void)openSessionWithStore:(id<MXStore>)store
|
-(void)openSessionWithStore:(id<MXStore>)store
|
||||||
{
|
{
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if (!mxCredentials || !mxRestClient)
|
if (!self.mxCredentials || !mxRestClient)
|
||||||
{
|
{
|
||||||
MXLogDebug(@"[MXKAccount] Matrix session cannot be created without credentials");
|
MXLogDebug(@"[MXKAccount] Matrix session cannot be created without credentials");
|
||||||
return;
|
return;
|
||||||
@@ -1056,9 +945,9 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
- (void)hydrateWithCredentials:(MXCredentials*)credentials
|
- (void)hydrateWithCredentials:(MXCredentials*)credentials
|
||||||
{
|
{
|
||||||
// Sanity check
|
// Sanity check
|
||||||
if ([mxCredentials.userId isEqualToString:credentials.userId])
|
if ([self.mxCredentials.userId isEqualToString:credentials.userId])
|
||||||
{
|
{
|
||||||
mxCredentials = credentials;
|
_mxCredentials = credentials;
|
||||||
_isSoftLogout = NO;
|
_isSoftLogout = NO;
|
||||||
[[MXKAccountManager sharedManager] saveAccounts];
|
[[MXKAccountManager sharedManager] saveAccounts];
|
||||||
|
|
||||||
@@ -1066,11 +955,13 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MXLogDebug(@"[MXKAccount] hydrateWithCredentials: Error: users ids mismatch: %@ vs %@", credentials.userId, mxCredentials.userId);
|
MXLogDebug(@"[MXKAccount] hydrateWithCredentials: Error: users ids mismatch: %@ vs %@", credentials.userId, self.mxCredentials.userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- (void)deletePusher
|
- (void)deletePusher
|
||||||
{
|
{
|
||||||
if (self.pushNotificationServiceIsActive)
|
if (self.pushNotificationServiceIsActive)
|
||||||
@@ -1267,7 +1158,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
success();
|
success();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountAPNSActivityDidChangeNotification object:self->mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountAPNSActivityDidChangeNotification object:self.mxCredentials.userId];
|
||||||
|
|
||||||
} failure:^(NSError *error) {
|
} failure:^(NSError *error) {
|
||||||
|
|
||||||
@@ -1286,7 +1177,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
success();
|
success();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountAPNSActivityDidChangeNotification object:self->mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountAPNSActivityDidChangeNotification object:self.mxCredentials.userId];
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1303,7 +1194,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
failure(error);
|
failure(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountAPNSActivityDidChangeNotification object:self->mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountAPNSActivityDidChangeNotification object:self.mxCredentials.userId];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1330,7 +1221,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
MXLogDebug(@"[MXKAccount][Push] refreshPushKitPusher: Error: %@", error);
|
MXLogDebug(@"[MXKAccount][Push] refreshPushKitPusher: Error: %@", error);
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
else if (_hasPusherForPushKitNotifications)
|
else if (self.hasPusherForPushKitNotifications)
|
||||||
{
|
{
|
||||||
if ([MXKAccountManager sharedManager].pushDeviceToken)
|
if ([MXKAccountManager sharedManager].pushDeviceToken)
|
||||||
{
|
{
|
||||||
@@ -1344,7 +1235,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
MXLogDebug(@"[MXKAccount][Push] refreshPushKitPusher: PushKit pusher for %@ account is already disabled. Reset _hasPusherForPushKitNotifications", self.mxCredentials.userId);
|
MXLogDebug(@"[MXKAccount][Push] refreshPushKitPusher: PushKit pusher for %@ account is already disabled. Reset _hasPusherForPushKitNotifications", self.mxCredentials.userId);
|
||||||
_hasPusherForPushKitNotifications = NO;
|
self->_hasPusherForPushKitNotifications = NO;
|
||||||
[[MXKAccountManager sharedManager] saveAccounts];
|
[[MXKAccountManager sharedManager] saveAccounts];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1406,7 +1297,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
success();
|
success();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountPushKitActivityDidChangeNotification object:self->mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountPushKitActivityDidChangeNotification object:self.mxCredentials.userId];
|
||||||
|
|
||||||
} failure:^(NSError *error) {
|
} failure:^(NSError *error) {
|
||||||
|
|
||||||
@@ -1425,7 +1316,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
success();
|
success();
|
||||||
}
|
}
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountPushKitActivityDidChangeNotification object:self->mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountPushKitActivityDidChangeNotification object:self.mxCredentials.userId];
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1442,7 +1333,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
failure(error);
|
failure(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountPushKitActivityDidChangeNotification object:self->mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountPushKitActivityDidChangeNotification object:self.mxCredentials.userId];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1451,7 +1342,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
MXLogDebug(@"[MXKAccount][Push] enablePusher: %@", @(enabled));
|
MXLogDebug(@"[MXKAccount][Push] enablePusher: %@", @(enabled));
|
||||||
|
|
||||||
// Refuse to try & turn push on if we're not logged in, it's nonsensical.
|
// Refuse to try & turn push on if we're not logged in, it's nonsensical.
|
||||||
if (!mxCredentials)
|
if (!self.mxCredentials)
|
||||||
{
|
{
|
||||||
MXLogDebug(@"[MXKAccount][Push] enablePusher: Not setting push token because we're not logged in");
|
MXLogDebug(@"[MXKAccount][Push] enablePusher: Not setting push token because we're not logged in");
|
||||||
return;
|
return;
|
||||||
@@ -1618,7 +1509,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
[self.mxSession startWithSyncFilter:syncFilter onServerSyncDone:^{
|
[self.mxSession startWithSyncFilter:syncFilter onServerSyncDone:^{
|
||||||
MXStrongifyAndReturnIfNil(self);
|
MXStrongifyAndReturnIfNil(self);
|
||||||
|
|
||||||
MXLogDebug(@"[MXKAccount] %@: The session is ready. Matrix SDK session has been started in %0.fms.", self->mxCredentials.userId, [[NSDate date] timeIntervalSinceDate:self->openSessionStartDate] * 1000);
|
MXLogDebug(@"[MXKAccount] %@: The session is ready. Matrix SDK session has been started in %0.fms.", self.mxCredentials.userId, [[NSDate date] timeIntervalSinceDate:self->openSessionStartDate] * 1000);
|
||||||
|
|
||||||
[self setUserPresence:MXPresenceOnline andStatusMessage:nil completion:nil];
|
[self setUserPresence:MXPresenceOnline andStatusMessage:nil completion:nil];
|
||||||
|
|
||||||
@@ -1753,11 +1644,11 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Here displayname or other information have been updated, post update notification.
|
// Here displayname or other information have been updated, post update notification.
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:self->mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:self.mxCredentials.userId];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// User information are just up-to-date (`mxSession` is running), post update notification.
|
// User information are just up-to-date (`mxSession` is running), post update notification.
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:self.mxCredentials.userId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mxSession.state == MXSessionStateStoreDataReady || mxSession.state == MXSessionStateSyncInProgress)
|
else if (mxSession.state == MXSessionStateStoreDataReady || mxSession.state == MXSessionStateSyncInProgress)
|
||||||
@@ -1772,7 +1663,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
{
|
{
|
||||||
// Here the initial server sync is in progress. The session is not running yet, but some user's information are available (from local storage).
|
// Here the initial server sync is in progress. The session is not running yet, but some user's information are available (from local storage).
|
||||||
// We post update notification to let observer take into account this user's information even if they may not be up-to-date.
|
// We post update notification to let observer take into account this user's information even if they may not be up-to-date.
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:mxCredentials.userId];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountUserInfoDidChangeNotification object:self.mxCredentials.userId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (mxSession.state == MXSessionStatePaused)
|
else if (mxSession.state == MXSessionStatePaused)
|
||||||
@@ -1782,7 +1673,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
else if (mxSession.state == MXSessionStateUnauthenticated)
|
else if (mxSession.state == MXSessionStateUnauthenticated)
|
||||||
{
|
{
|
||||||
// Logout this account
|
// Logout this account
|
||||||
[[MXKAccountManager sharedManager] removeAccount:self completion:nil];
|
[[MXKAccountManager sharedManager] removeAccount:self sendLogoutRequest:NO completion:nil];
|
||||||
}
|
}
|
||||||
else if (mxSession.state == MXSessionStateSoftLogout)
|
else if (mxSession.state == MXSessionStateSoftLogout)
|
||||||
{
|
{
|
||||||
@@ -1793,19 +1684,19 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
|
|
||||||
- (void)prepareRESTClient
|
- (void)prepareRESTClient
|
||||||
{
|
{
|
||||||
if (!mxCredentials)
|
if (!self.mxCredentials)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mxRestClient = [[MXRestClient alloc] initWithCredentials:mxCredentials andOnUnrecognizedCertificateBlock:^BOOL(NSData *certificate) {
|
mxRestClient = [[MXRestClient alloc] initWithCredentials:self.mxCredentials andOnUnrecognizedCertificateBlock:^BOOL(NSData *certificate) {
|
||||||
|
|
||||||
if (_onCertificateChangeBlock)
|
if (_onCertificateChangeBlock)
|
||||||
{
|
{
|
||||||
if (_onCertificateChangeBlock (self, certificate))
|
if (_onCertificateChangeBlock (self, certificate))
|
||||||
{
|
{
|
||||||
// Update the certificate in credentials
|
// Update the certificate in credentials
|
||||||
self->mxCredentials.allowedCertificate = certificate;
|
self.mxCredentials.allowedCertificate = certificate;
|
||||||
|
|
||||||
// Archive updated field
|
// Archive updated field
|
||||||
[[MXKAccountManager sharedManager] saveAccounts];
|
[[MXKAccountManager sharedManager] saveAccounts];
|
||||||
@@ -1813,13 +1704,15 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
self->mxCredentials.ignoredCertificate = certificate;
|
self.mxCredentials.ignoredCertificate = certificate;
|
||||||
|
|
||||||
// Archive updated field
|
// Archive updated field
|
||||||
[[MXKAccountManager sharedManager] saveAccounts];
|
[[MXKAccountManager sharedManager] saveAccounts];
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
|
} andPersistentTokenDataHandler:^(void (^handler)(NSArray<MXCredentials *> *credentials, void (^completion)(BOOL didUpdateCredentials))) {
|
||||||
|
[MXKAccountManager.sharedManager readAndWriteCredentials:handler];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1875,7 +1768,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
#pragma mark - Crypto
|
#pragma mark - Crypto
|
||||||
- (void)resetDeviceId
|
- (void)resetDeviceId
|
||||||
{
|
{
|
||||||
mxCredentials.deviceId = nil;
|
self.mxCredentials.deviceId = nil;
|
||||||
|
|
||||||
// Archive updated field
|
// Archive updated field
|
||||||
[[MXKAccountManager sharedManager] saveAccounts];
|
[[MXKAccountManager sharedManager] saveAccounts];
|
||||||
@@ -2191,11 +2084,11 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
MXSession *mxSession = notification.object;
|
MXSession *mxSession = notification.object;
|
||||||
if (mxSession == self.mxSession)
|
if (mxSession == self.mxSession)
|
||||||
{
|
{
|
||||||
if (![mxCredentials.identityServer isEqualToString:self.mxSession.accountDataIdentityServer])
|
if (![self.mxCredentials.identityServer isEqualToString:self.mxSession.accountDataIdentityServer])
|
||||||
{
|
{
|
||||||
_identityServerURL = self.mxSession.accountDataIdentityServer;
|
_identityServerURL = self.mxSession.accountDataIdentityServer;
|
||||||
mxCredentials.identityServer = _identityServerURL;
|
self.mxCredentials.identityServer = _identityServerURL;
|
||||||
mxCredentials.identityServerAccessToken = nil;
|
self.mxCredentials.identityServerAccessToken = nil;
|
||||||
|
|
||||||
// Archive updated field
|
// Archive updated field
|
||||||
[[MXKAccountManager sharedManager] saveAccounts];
|
[[MXKAccountManager sharedManager] saveAccounts];
|
||||||
@@ -2208,7 +2101,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
|
|
||||||
- (void)identityService:(MXIdentityService *)identityService didUpdateAccessToken:(NSString *)accessToken
|
- (void)identityService:(MXIdentityService *)identityService didUpdateAccessToken:(NSString *)accessToken
|
||||||
{
|
{
|
||||||
mxCredentials.identityServerAccessToken = accessToken;
|
self.mxCredentials.identityServerAccessToken = accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)registerIdentityServiceDidChangeAccessTokenNotification
|
- (void)registerIdentityServiceDidChangeAccessTokenNotification
|
||||||
@@ -2224,9 +2117,9 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
|||||||
NSString *identityServer = userInfo[MXIdentityServiceNotificationIdentityServerKey];
|
NSString *identityServer = userInfo[MXIdentityServiceNotificationIdentityServerKey];
|
||||||
NSString *accessToken = userInfo[MXIdentityServiceNotificationAccessTokenKey];
|
NSString *accessToken = userInfo[MXIdentityServiceNotificationAccessTokenKey];
|
||||||
|
|
||||||
if (userId && identityServer && accessToken && [mxCredentials.identityServer isEqualToString:identityServer])
|
if (userId && identityServer && accessToken && [self.mxCredentials.identityServer isEqualToString:identityServer])
|
||||||
{
|
{
|
||||||
mxCredentials.identityServerAccessToken = accessToken;
|
self.mxCredentials.identityServerAccessToken = accessToken;
|
||||||
|
|
||||||
// Archive updated field
|
// Archive updated field
|
||||||
[[MXKAccountManager sharedManager] saveAccounts];
|
[[MXKAccountManager sharedManager] saveAccounts];
|
||||||
|
|||||||
141
Riot/Modules/MatrixKit/Models/Account/MXKAccountData.h
Normal file
141
Riot/Modules/MatrixKit/Models/Account/MXKAccountData.h
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2021 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
#import <MatrixSDK/MatrixSDK.h>
|
||||||
|
|
||||||
|
@class MXKAccountData;
|
||||||
|
|
||||||
|
@interface MXKAccountData : NSObject <NSCoding> {
|
||||||
|
|
||||||
|
@protected MXCredentials *_mxCredentials;
|
||||||
|
@protected NSString *_identityServerURL;
|
||||||
|
@protected NSString *_antivirusServerURL;
|
||||||
|
@protected NSString *_pushGatewayURL;
|
||||||
|
@protected MXDevice *_device;
|
||||||
|
@protected BOOL _disabled;
|
||||||
|
@protected BOOL _enableInAppNotifications;
|
||||||
|
@protected BOOL _warnedAboutEncryption;
|
||||||
|
@protected NSMutableDictionary<NSString *, id<NSCoding>> *_others;
|
||||||
|
@protected NSArray<MXThirdPartyIdentifier *> *_threePIDs;
|
||||||
|
@protected BOOL _isSoftLogout;
|
||||||
|
@protected BOOL _hasPusherForPushNotifications;
|
||||||
|
@protected BOOL _hasPusherForPushKitNotifications;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
The account's credentials: homeserver, access token, user id.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) MXCredentials *mxCredentials;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The identity server URL.
|
||||||
|
*/
|
||||||
|
@property (nonatomic) NSString *identityServerURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The antivirus server URL, if any (nil by default).
|
||||||
|
Set a non-null url to configure the antivirus scanner use.
|
||||||
|
*/
|
||||||
|
@property (nonatomic) NSString *antivirusServerURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The Push Gateway URL used to send event notifications to (nil by default).
|
||||||
|
This URL should be over HTTPS and never over HTTP.
|
||||||
|
*/
|
||||||
|
@property (nonatomic) NSString *pushGatewayURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The 3PIDs linked to this account.
|
||||||
|
[self load3PIDs] must be called to update the property.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) NSArray<MXThirdPartyIdentifier *> *threePIDs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The email addresses linked to this account.
|
||||||
|
This is a subset of self.threePIDs.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) NSArray<NSString *> *linkedEmails;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The phone numbers linked to this account.
|
||||||
|
This is a subset of self.threePIDs.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) NSArray<NSString *> *linkedPhoneNumbers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The account user's device.
|
||||||
|
[self loadDeviceInformation] must be called to update the property.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) MXDevice *device;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The account user's tint color: a unique color fixed by the user id. This tint color may be used to highlight
|
||||||
|
rooms which belong to this account's user.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) UIColor *userTintColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The Apple Push Notification Service activity for this account. YES when APNS is turned on (locally available and synced with server).
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) BOOL pushNotificationServiceIsActive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Transient information storage.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, strong, readonly) NSMutableDictionary<NSString *, id<NSCoding>> *others;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Flag to indicate that an APNS pusher has been set on the homeserver for this device.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) BOOL hasPusherForPushNotifications;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The Push notification activity (based on PushKit) for this account.
|
||||||
|
YES when Push is turned on (locally available and enabled homeserver side).
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) BOOL isPushKitNotificationActive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Flag to indicate that a PushKit pusher has been set on the homeserver for this device.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) BOOL hasPusherForPushKitNotifications;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Enable In-App notifications based on Remote notifications rules.
|
||||||
|
NO by default.
|
||||||
|
*/
|
||||||
|
@property (nonatomic) BOOL enableInAppNotifications;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Disable the account without logging out (NO by default).
|
||||||
|
|
||||||
|
A matrix session is automatically opened for the account when this property is toggled from YES to NO.
|
||||||
|
The session is closed when this property is set to YES.
|
||||||
|
*/
|
||||||
|
@property (nonatomic,getter=isDisabled) BOOL disabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Flag indicating if the end user has been warned about encryption and its limitations.
|
||||||
|
*/
|
||||||
|
@property (nonatomic,getter=isWarnedAboutEncryption) BOOL warnedAboutEncryption;
|
||||||
|
|
||||||
|
#pragma mark - Soft logout
|
||||||
|
|
||||||
|
/**
|
||||||
|
Flag to indicate if the account has been logged out by the homeserver admin.
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly) BOOL isSoftLogout;
|
||||||
|
@end
|
||||||
150
Riot/Modules/MatrixKit/Models/Account/MXKAccountData.m
Normal file
150
Riot/Modules/MatrixKit/Models/Account/MXKAccountData.m
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
//
|
||||||
|
// Copyright 2021 New Vector Ltd
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "MXKAccountData.h"
|
||||||
|
|
||||||
|
@interface MXKAccountData ()
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MXKAccountData
|
||||||
|
|
||||||
|
@synthesize mxCredentials = _mxCredentials;
|
||||||
|
|
||||||
|
#pragma mark - NSCoding
|
||||||
|
|
||||||
|
- (id)initWithCoder:(NSCoder *)coder
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
|
if (self)
|
||||||
|
{
|
||||||
|
|
||||||
|
NSString *homeServerURL = [coder decodeObjectForKey:@"homeserverurl"];
|
||||||
|
NSString *userId = [coder decodeObjectForKey:@"userid"];
|
||||||
|
NSString *accessToken = [coder decodeObjectForKey:@"accesstoken"];
|
||||||
|
_identityServerURL = [coder decodeObjectForKey:@"identityserverurl"];
|
||||||
|
NSString *identityServerAccessToken = [coder decodeObjectForKey:@"identityserveraccesstoken"];
|
||||||
|
|
||||||
|
_mxCredentials = [[MXCredentials alloc] initWithHomeServer:homeServerURL
|
||||||
|
userId:userId
|
||||||
|
accessToken:accessToken];
|
||||||
|
|
||||||
|
_mxCredentials.accessTokenExpiresAt = [coder decodeInt64ForKey:@"accessTokenExpiresAt"];
|
||||||
|
_mxCredentials.refreshToken = [coder decodeObjectForKey:@"refreshToken"];
|
||||||
|
_mxCredentials.identityServer = _identityServerURL;
|
||||||
|
_mxCredentials.identityServerAccessToken = identityServerAccessToken;
|
||||||
|
_mxCredentials.deviceId = [coder decodeObjectForKey:@"deviceId"];
|
||||||
|
_mxCredentials.allowedCertificate = [coder decodeObjectForKey:@"allowedCertificate"];
|
||||||
|
|
||||||
|
if ([coder decodeObjectForKey:@"threePIDs"])
|
||||||
|
{
|
||||||
|
_threePIDs = [coder decodeObjectForKey:@"threePIDs"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([coder decodeObjectForKey:@"device"])
|
||||||
|
{
|
||||||
|
_device = [coder decodeObjectForKey:@"device"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([coder decodeObjectForKey:@"antivirusserverurl"])
|
||||||
|
{
|
||||||
|
_antivirusServerURL = [coder decodeObjectForKey:@"antivirusserverurl"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([coder decodeObjectForKey:@"pushgatewayurl"])
|
||||||
|
{
|
||||||
|
_pushGatewayURL = [coder decodeObjectForKey:@"pushgatewayurl"];
|
||||||
|
}
|
||||||
|
|
||||||
|
_hasPusherForPushNotifications = [coder decodeBoolForKey:@"_enablePushNotifications"];
|
||||||
|
_hasPusherForPushKitNotifications = [coder decodeBoolForKey:@"enablePushKitNotifications"];
|
||||||
|
_enableInAppNotifications = [coder decodeBoolForKey:@"enableInAppNotifications"];
|
||||||
|
|
||||||
|
_disabled = [coder decodeBoolForKey:@"disabled"];
|
||||||
|
_isSoftLogout = [coder decodeBoolForKey:@"isSoftLogout"];
|
||||||
|
|
||||||
|
_warnedAboutEncryption = [coder decodeBoolForKey:@"warnedAboutEncryption"];
|
||||||
|
|
||||||
|
_others = [coder decodeObjectForKey:@"others"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)encodeWithCoder:(NSCoder *)coder
|
||||||
|
{
|
||||||
|
[coder encodeObject:_mxCredentials.homeServer forKey:@"homeserverurl"];
|
||||||
|
[coder encodeObject:_mxCredentials.userId forKey:@"userid"];
|
||||||
|
[coder encodeObject:_mxCredentials.accessToken forKey:@"accesstoken"];
|
||||||
|
if (self.mxCredentials.accessTokenExpiresAt) {
|
||||||
|
[coder encodeInt64:_mxCredentials.accessTokenExpiresAt forKey:@"accessTokenExpiresAt"];
|
||||||
|
}
|
||||||
|
if (self.mxCredentials.refreshToken) {
|
||||||
|
[coder encodeObject:_mxCredentials.refreshToken forKey:@"refreshToken"];
|
||||||
|
}
|
||||||
|
[coder encodeObject:_mxCredentials.identityServerAccessToken forKey:@"identityserveraccesstoken"];
|
||||||
|
|
||||||
|
if (self.mxCredentials.deviceId)
|
||||||
|
{
|
||||||
|
[coder encodeObject:_mxCredentials.deviceId forKey:@"deviceId"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.mxCredentials.allowedCertificate)
|
||||||
|
{
|
||||||
|
[coder encodeObject:_mxCredentials.allowedCertificate forKey:@"allowedCertificate"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.threePIDs)
|
||||||
|
{
|
||||||
|
[coder encodeObject:_threePIDs forKey:@"threePIDs"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.device)
|
||||||
|
{
|
||||||
|
[coder encodeObject:_device forKey:@"device"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.identityServerURL)
|
||||||
|
{
|
||||||
|
[coder encodeObject:_identityServerURL forKey:@"identityserverurl"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.antivirusServerURL)
|
||||||
|
{
|
||||||
|
[coder encodeObject:_antivirusServerURL forKey:@"antivirusserverurl"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self.pushGatewayURL)
|
||||||
|
{
|
||||||
|
[coder encodeObject:_pushGatewayURL forKey:@"pushgatewayurl"];
|
||||||
|
}
|
||||||
|
|
||||||
|
[coder encodeBool:_hasPusherForPushNotifications forKey:@"_enablePushNotifications"];
|
||||||
|
[coder encodeBool:_hasPusherForPushKitNotifications forKey:@"enablePushKitNotifications"];
|
||||||
|
[coder encodeBool:_enableInAppNotifications forKey:@"enableInAppNotifications"];
|
||||||
|
|
||||||
|
[coder encodeBool:_disabled forKey:@"disabled"];
|
||||||
|
[coder encodeBool:_isSoftLogout forKey:@"isSoftLogout"];
|
||||||
|
|
||||||
|
[coder encodeBool:_warnedAboutEncryption forKey:@"warnedAboutEncryption"];
|
||||||
|
|
||||||
|
[coder encodeObject:_others forKey:@"others"];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -110,6 +110,8 @@ extern NSString *const MXKAccountManagerDataType;
|
|||||||
*/
|
*/
|
||||||
+ (MXKAccountManager *)sharedManager;
|
+ (MXKAccountManager *)sharedManager;
|
||||||
|
|
||||||
|
+ (MXKAccountManager *)sharedManagerWithReload:(BOOL)reload;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Check for each enabled account if a matrix session is already opened.
|
Check for each enabled account if a matrix session is already opened.
|
||||||
Open a matrix session for each enabled account which doesn't have a session.
|
Open a matrix session for each enabled account which doesn't have a session.
|
||||||
@@ -208,11 +210,6 @@ extern NSString *const MXKAccountManagerDataType;
|
|||||||
*/
|
*/
|
||||||
- (MXKAccount *)accountKnowingUserWithUserId:(NSString *)userId;
|
- (MXKAccount *)accountKnowingUserWithUserId:(NSString *)userId;
|
||||||
|
|
||||||
/**
|
- (void)readAndWriteCredentials:(void (^)(NSArray<MXCredentials*> * _Nullable readData, void (^completion)(BOOL didUpdateCredentials)))readAnWriteHandler;
|
||||||
Force the account manager to reload existing accounts from the local storage.
|
|
||||||
The account manager is supposed to handle itself the list of the accounts.
|
|
||||||
Call this method only when an account has been changed from an other application from the same group.
|
|
||||||
*/
|
|
||||||
- (void)forceReloadAccounts;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
#import "MXKAppSettings.h"
|
#import "MXKAppSettings.h"
|
||||||
|
|
||||||
#import "MXKTools.h"
|
#import "MXKTools.h"
|
||||||
|
#import "MXKAccountData.h"
|
||||||
|
#import "MXRefreshTokenData.h"
|
||||||
|
|
||||||
static NSString *const kMXKAccountsKeyOld = @"accounts";
|
static NSString *const kMXKAccountsKeyOld = @"accounts";
|
||||||
static NSString *const kMXKAccountsKey = @"accountsV2";
|
static NSString *const kMXKAccountsKey = @"accountsV2";
|
||||||
@@ -43,13 +45,23 @@ NSString *const MXKAccountManagerDataType = @"org.matrix.kit.MXKAccountManagerDa
|
|||||||
@implementation MXKAccountManager
|
@implementation MXKAccountManager
|
||||||
|
|
||||||
+ (MXKAccountManager *)sharedManager
|
+ (MXKAccountManager *)sharedManager
|
||||||
|
{
|
||||||
|
return [MXKAccountManager sharedManagerWithReload:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (MXKAccountManager *)sharedManagerWithReload:(BOOL)reload
|
||||||
{
|
{
|
||||||
static MXKAccountManager *sharedAccountManager = nil;
|
static MXKAccountManager *sharedAccountManager = nil;
|
||||||
static dispatch_once_t onceToken;
|
static dispatch_once_t onceToken;
|
||||||
|
__block BOOL didLoad = false;
|
||||||
dispatch_once(&onceToken, ^{
|
dispatch_once(&onceToken, ^{
|
||||||
|
didLoad = true;
|
||||||
sharedAccountManager = [[super allocWithZone:NULL] init];
|
sharedAccountManager = [[super allocWithZone:NULL] init];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (reload && !didLoad) {
|
||||||
|
[sharedAccountManager loadAccounts];
|
||||||
|
}
|
||||||
return sharedAccountManager;
|
return sharedAccountManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,8 +78,6 @@ NSString *const MXKAccountManagerDataType = @"org.matrix.kit.MXKAccountManagerDa
|
|||||||
|
|
||||||
// Load existing accounts from local storage
|
// Load existing accounts from local storage
|
||||||
[self loadAccounts];
|
[self loadAccounts];
|
||||||
|
|
||||||
[self registerRestClientDidRefreshTokensNotification];
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@@ -601,7 +611,6 @@ NSString *const MXKAccountManagerDataType = @"org.matrix.kit.MXKAccountManagerDa
|
|||||||
- (void)loadAccounts
|
- (void)loadAccounts
|
||||||
{
|
{
|
||||||
MXLogDebug(@"[MXKAccountManager] loadAccounts");
|
MXLogDebug(@"[MXKAccountManager] loadAccounts");
|
||||||
|
|
||||||
NSString *accountFile = [self accountFile];
|
NSString *accountFile = [self accountFile];
|
||||||
if ([[NSFileManager defaultManager] fileExistsAtPath:accountFile])
|
if ([[NSFileManager defaultManager] fileExistsAtPath:accountFile])
|
||||||
{
|
{
|
||||||
@@ -667,12 +676,6 @@ NSString *const MXKAccountManagerDataType = @"org.matrix.kit.MXKAccountManagerDa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)forceReloadAccounts
|
|
||||||
{
|
|
||||||
MXLogDebug(@"[MXKAccountManager] Force reload existing accounts from local storage");
|
|
||||||
[self loadAccounts];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSData*)encryptData:(NSData*)data
|
- (NSData*)encryptData:(NSData*)data
|
||||||
{
|
{
|
||||||
// Exceptions are not caught as the key is always needed if the KeyProviderDelegate
|
// Exceptions are not caught as the key is always needed if the KeyProviderDelegate
|
||||||
@@ -725,17 +728,69 @@ NSString *const MXKAccountManagerDataType = @"org.matrix.kit.MXKAccountManagerDa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Homeserver Access/Refresh Token updates
|
- (void)readAndWriteCredentials:(void (^)(NSArray<MXCredentials*> * _Nullable readData, void (^completion)(BOOL didUpdateCredentials)))readAnWriteHandler
|
||||||
|
|
||||||
- (void)registerRestClientDidRefreshTokensNotification
|
|
||||||
{
|
{
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleRestClientDidRefreshTokensNotification:) name:MXRestClientDidRefreshTokensNotification object:nil];
|
NSError *error;
|
||||||
|
NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
|
||||||
|
__block BOOL coordinatorSuccess = NO;
|
||||||
|
NSLog(@"[MXKAccountManager] readAndWriteCredentials: purposeIdentifier = %@", fileCoordinator.purposeIdentifier);
|
||||||
|
NSDate *coordinateStartTime = [NSDate date];
|
||||||
|
[fileCoordinator coordinateReadingItemAtURL:[self accountFileUrl]
|
||||||
|
options:0
|
||||||
|
writingItemAtURL:[self accountFileUrl]
|
||||||
|
options:NSFileCoordinatorWritingForMerging
|
||||||
|
error:&error
|
||||||
|
byAccessor:^(NSURL * _Nonnull newReadingURL, NSURL * _Nonnull newWritingURL) {
|
||||||
|
|
||||||
|
NSDate *accessorStartTime = [NSDate date];
|
||||||
|
NSTimeInterval acquireInterval = [accessorStartTime timeIntervalSinceDate:coordinateStartTime];
|
||||||
|
NSLog(@"[MXKAccountManager] readAndWriteCredentials: acquireInterval = %f", acquireInterval);
|
||||||
|
NSError *error = nil;
|
||||||
|
NSData* data = [NSData dataWithContentsOfURL:newReadingURL options:(NSDataReadingMappedAlways | NSDataReadingUncached) error:&error];
|
||||||
|
|
||||||
|
// Decrypt data if encryption method is provided
|
||||||
|
NSData *unciphered = [self decryptData:data];
|
||||||
|
NSKeyedUnarchiver *decoder = [[NSKeyedUnarchiver alloc] initForReadingFromData:unciphered error:&error];
|
||||||
|
decoder.requiresSecureCoding = false;
|
||||||
|
[decoder setClass:[MXKAccountData class] forClassName:@"MXKAccount"];
|
||||||
|
NSMutableArray<MXKAccountData*>* mxAccountsData = [decoder decodeObjectForKey:@"mxAccounts"];
|
||||||
|
NSMutableArray<MXCredentials*>* mxAccountCredentials = [NSMutableArray arrayWithCapacity:mxAccounts.count];
|
||||||
|
for(MXKAccountData *account in mxAccountsData){
|
||||||
|
[mxAccountCredentials addObject:account.mxCredentials];
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch_group_t dispatchGroup = dispatch_group_create();
|
||||||
|
dispatch_group_enter(dispatchGroup);
|
||||||
|
|
||||||
|
__block BOOL didUpdate = NO;
|
||||||
|
readAnWriteHandler(mxAccountCredentials, ^(BOOL didUpdateCredentials) {
|
||||||
|
didUpdate = didUpdateCredentials;
|
||||||
|
dispatch_group_leave(dispatchGroup);
|
||||||
|
});
|
||||||
|
|
||||||
|
dispatch_group_wait(dispatchGroup, DISPATCH_TIME_FOREVER);
|
||||||
|
|
||||||
|
if (didUpdate) {
|
||||||
|
NSLog(@"[MXKAccountManager] readAndWriteCredentials: did update saving credential data");
|
||||||
|
NSKeyedArchiver *encoder = [[NSKeyedArchiver alloc] initRequiringSecureCoding: NO];
|
||||||
|
[encoder setClassName:@"MXKAccount" forClass:[MXKAccountData class]];
|
||||||
|
[encoder encodeObject:mxAccountsData forKey:@"mxAccounts"];
|
||||||
|
NSData *writeData = [self encryptData:[encoder encodedData]];
|
||||||
|
coordinatorSuccess = [writeData writeToURL:newWritingURL atomically:YES];
|
||||||
|
} else {
|
||||||
|
NSLog(@"[MXKAccountManager] readAndWriteCredentials: did not update not saving credential data");
|
||||||
|
coordinatorSuccess = YES;
|
||||||
|
}
|
||||||
|
NSDate *accessorEndTime = [NSDate date];
|
||||||
|
NSTimeInterval lockedTime = [accessorEndTime timeIntervalSinceDate:accessorStartTime];
|
||||||
|
NSLog(@"[MXKAccountManager] readAndWriteCredentials: lockedTime = %f", lockedTime);
|
||||||
|
}];
|
||||||
|
NSLog(@"[MXKAccountManager] readAndWriteCredentials:exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)handleRestClientDidRefreshTokensNotification:(NSNotification*)notification
|
- (NSURL *)accountFileUrl
|
||||||
{
|
{
|
||||||
[self saveAccounts];
|
return [NSURL fileURLWithPath: [self accountFile]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -56,7 +56,9 @@ class NotificationService: UNNotificationServiceExtension {
|
|||||||
guard let userAccount = userAccount else {
|
guard let userAccount = userAccount else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
let restClient = MXRestClient(credentials: userAccount.mxCredentials, unrecognizedCertificateHandler: nil)
|
let restClient = MXRestClient(credentials: userAccount.mxCredentials, unrecognizedCertificateHandler: nil) { persistTokenDataHandler in
|
||||||
|
MXKAccountManager.shared().readAndWriteCredentials(persistTokenDataHandler)
|
||||||
|
}
|
||||||
restClient.refreshTokensFailedHandler = { mxError in
|
restClient.refreshTokensFailedHandler = { mxError in
|
||||||
MXLog.debug("[NotificationService] mxRestClient: The rest client is no longer authenticated.")
|
MXLog.debug("[NotificationService] mxRestClient: The rest client is no longer authenticated.")
|
||||||
if let mxError = mxError,
|
if let mxError = mxError,
|
||||||
@@ -180,14 +182,16 @@ class NotificationService: UNNotificationServiceExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func setup(withRoomId roomId: String, eventId: String, completion: @escaping () -> Void) {
|
private func setup(withRoomId roomId: String, eventId: String, completion: @escaping () -> Void) {
|
||||||
MXKAccountManager.shared()?.forceReloadAccounts()
|
MXKAccountManager.sharedManager(withReload: true)
|
||||||
self.userAccount = MXKAccountManager.shared()?.activeAccounts.first
|
self.userAccount = MXKAccountManager.shared()?.activeAccounts.first
|
||||||
if let userAccount = userAccount {
|
if let userAccount = userAccount {
|
||||||
Self.backgroundServiceInitQueue.sync {
|
Self.backgroundServiceInitQueue.sync {
|
||||||
if NotificationService.backgroundSyncService?.credentials != userAccount.mxCredentials {
|
if NotificationService.backgroundSyncService?.credentials != userAccount.mxCredentials {
|
||||||
MXLog.debug("[NotificationService] setup: MXBackgroundSyncService init: BEFORE")
|
MXLog.debug("[NotificationService] setup: MXBackgroundSyncService init: BEFORE")
|
||||||
self.logMemory()
|
self.logMemory()
|
||||||
NotificationService.backgroundSyncService = MXBackgroundSyncService(withCredentials: userAccount.mxCredentials)
|
NotificationService.backgroundSyncService = MXBackgroundSyncService(withCredentials: userAccount.mxCredentials, persistTokenDataHandler: { persistTokenDataHandler in
|
||||||
|
MXKAccountManager.shared().readAndWriteCredentials(persistTokenDataHandler)
|
||||||
|
})
|
||||||
MXLog.debug("[NotificationService] setup: MXBackgroundSyncService init: AFTER")
|
MXLog.debug("[NotificationService] setup: MXBackgroundSyncService init: AFTER")
|
||||||
self.logMemory()
|
self.logMemory()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,9 @@
|
|||||||
NSMutableArray *cellData = [NSMutableArray array];
|
NSMutableArray *cellData = [NSMutableArray array];
|
||||||
|
|
||||||
// Add a fake matrix session to each room summary to provide it a REST client (used to handle correctly the room avatar).
|
// Add a fake matrix session to each room summary to provide it a REST client (used to handle correctly the room avatar).
|
||||||
MXSession *session = [[MXSession alloc] initWithMatrixRestClient:[[MXRestClient alloc] initWithCredentials:self.credentials andOnUnrecognizedCertificateBlock:nil]];
|
MXSession *session = [[MXSession alloc] initWithMatrixRestClient:[[MXRestClient alloc] initWithCredentials:self.credentials andOnUnrecognizedCertificateBlock:nil andPersistentTokenDataHandler:^(void (^handler)(NSArray<MXCredentials *> *credentials, void (^completion)(BOOL didUpdateCredentials))) {
|
||||||
|
[[MXKAccountManager sharedManager] readAndWriteCredentials:handler];
|
||||||
|
}]];
|
||||||
|
|
||||||
for (MXRoomSummary *roomSummary in roomsSummaries)
|
for (MXRoomSummary *roomSummary in roomsSummaries)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -78,7 +78,9 @@
|
|||||||
|
|
||||||
- (void)shareViewController:(ShareViewController *)shareViewController didRequestShareForRoomIdentifiers:(NSSet<NSString *> *)roomIdentifiers
|
- (void)shareViewController:(ShareViewController *)shareViewController didRequestShareForRoomIdentifiers:(NSSet<NSString *> *)roomIdentifiers
|
||||||
{
|
{
|
||||||
MXSession *session = [[MXSession alloc] initWithMatrixRestClient:[[MXRestClient alloc] initWithCredentials:self.userAccount.mxCredentials andOnUnrecognizedCertificateBlock:nil]];
|
MXSession *session = [[MXSession alloc] initWithMatrixRestClient:[[MXRestClient alloc] initWithCredentials:self.userAccount.mxCredentials andOnUnrecognizedCertificateBlock:nil andPersistentTokenDataHandler:^(void (^handler)(NSArray<MXCredentials *> *credentials, void (^completion)(BOOL didUpdateCredentials))) {
|
||||||
|
[[MXKAccountManager sharedManager] readAndWriteCredentials:handler];
|
||||||
|
}]];
|
||||||
[MXFileStore setPreloadOptions:0];
|
[MXFileStore setPreloadOptions:0];
|
||||||
|
|
||||||
MXWeakify(session);
|
MXWeakify(session);
|
||||||
@@ -147,7 +149,7 @@
|
|||||||
- (void)checkUserAccount
|
- (void)checkUserAccount
|
||||||
{
|
{
|
||||||
// Force account manager to reload account from the local storage.
|
// Force account manager to reload account from the local storage.
|
||||||
[[MXKAccountManager sharedManager] forceReloadAccounts];
|
[MXKAccountManager sharedManagerWithReload:YES];
|
||||||
|
|
||||||
if (self.userAccount)
|
if (self.userAccount)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user