Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2fbd129
Add first refresh token implementation pass. Account credential persi…
langleyd Dec 9, 2021
b09cf74
Fix refresh token coding and persistence.
langleyd Dec 13, 2021
362635a
Split MXKAccount from Data so just data can be loaded from disk witho…
langleyd Jan 6, 2022
4effc7e
Merge branch 'develop' of https://github.com/vector-im/element-ios in…
langleyd Jan 6, 2022
56475bb
Remove duplicated logout code and fix spinner.
langleyd Jan 10, 2022
38fae3c
Temporarily point to refresh sdk branch to build alpha
langleyd Jan 11, 2022
06a8d0c
Add analytics for Unauthenticated errors
langleyd Jan 13, 2022
05b817f
Merge branch 'develop' of https://github.com/vector-im/element-ios in…
langleyd Jan 14, 2022
dbe3c6f
Update Podfile.lock
langleyd Jan 14, 2022
5850d55
Update lockfile to get latest SDK.
langleyd Jan 14, 2022
5006a20
Merge branch 'develop' of https://github.com/vector-im/element-ios in…
langleyd Jan 24, 2022
07b9b08
Remove NSLog and fix Analytics documentation.
langleyd Jan 24, 2022
cb70d6d
Update pod lockfile to include fix in SDK.
langleyd Jan 24, 2022
e785179
Update Podfile.lock
langleyd Jan 24, 2022
2f00672
Merge branch 'develop' of https://github.com/vector-im/element-ios in…
langleyd Jan 24, 2022
c2928ba
Fix missing bubbles cell types (from #5419)
langleyd Jan 24, 2022
be445ac
Revert bad merge formatting from "Merge branch 'develop' of https://g…
langleyd Jan 24, 2022
2fff8d9
Fix bad formatting from merge moar.
langleyd Jan 24, 2022
456e269
Add nullability checks and remove comment
langleyd Jan 28, 2022
d8c3992
Disable refresh tokens and revert pod and lockfile
langleyd Jan 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Riot/Modules/Analytics/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import AnalyticsEvents

// Catch and log crashes
MXLogger.logCrashes(true)
MXLogger.setBuildVersion(AppDelegate.theDelegate().build)
MXLogger.setBuildVersion(AppInfo.current.buildInfo.readableBuildVersion)
}

/// Use the analytics settings from the supplied session to configure analytics.
Expand Down Expand Up @@ -200,6 +200,16 @@ extension Analytics {
}
}

/// Track when a user becomes unauthenticated without pressing the `sign out` button.
/// - Parameters:
/// - reason: The error that occurred.
/// - count: The number of times that error occurred.
func trackAuthUnauthenticatedError(softLogout: Bool, refreshTokenAuth: Bool, errorCode: String, errorReason: String) {
let errorCode = AnalyticsEvent.UnauthenticatedError.ErrorCode(rawValue: errorCode) ?? .M_UNKNOWN
let event = AnalyticsEvent.UnauthenticatedError(errorCode: errorCode, errorReason: errorReason, refreshTokenAuth: refreshTokenAuth, softLogout: softLogout)
client.capture(event)
}

/// Track whether the user accepted or declined the terms to an identity server.
/// **Note** This method isn't currently implemented.
/// - Parameter accepted: Whether the terms were accepted.
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/MatrixKit/Models/Account/MXKAccount.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,5 +362,5 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
/**
Handle unauthenticated errors from the server triggering hard/soft logouts as appropriate.
*/
- (void)handleUnauthenticated:(MXError *)error andCompletion:(void (^)(void))completion;
- (void)handleUnauthenticatedWithError:(MXError *)error isSoftLogout:(BOOL)isSoftLogout isRefreshTokenAuth:(BOOL)isRefreshTokenAuth andCompletion:(void (^)(void))completion;
@end
15 changes: 9 additions & 6 deletions Riot/Modules/MatrixKit/Models/Account/MXKAccount.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#import "MXKSwiftHeader.h"

#import "GeneratedInterface-Swift.h"

NSString *const kMXKAccountUserInfoDidChangeNotification = @"kMXKAccountUserInfoDidChangeNotification";
NSString *const kMXKAccountAPNSActivityDidChangeNotification = @"kMXKAccountAPNSActivityDidChangeNotification";
NSString *const kMXKAccountPushKitActivityDidChangeNotification = @"kMXKAccountPushKitActivityDidChangeNotification";
Expand Down Expand Up @@ -1700,17 +1702,18 @@ - (void)prepareRESTClient

} andPersistentTokenDataHandler:^(void (^handler)(NSArray<MXCredentials *> *credentials, void (^completion)(BOOL didUpdateCredentials))) {
[MXKAccountManager.sharedManager readAndWriteCredentials:handler];
} andUnauthenticatedHandler:^(MXError *error, void (^completion)(void)) {
} andUnauthenticatedHandler:^(MXError *error, BOOL isSoftLogout, BOOL isRefreshTokenAuth, void (^completion)(void)) {
MXStrongifyAndReturnIfNil(self);
[self handleUnauthenticated:error andCompletion:completion];
[self handleUnauthenticatedWithError:error isSoftLogout:isSoftLogout isRefreshTokenAuth:isRefreshTokenAuth andCompletion:completion];
}];
}


- (void)handleUnauthenticated:(MXError *)error andCompletion:(void (^)(void))completion
- (void)handleUnauthenticatedWithError:(MXError *)error isSoftLogout:(BOOL)isSoftLogout isRefreshTokenAuth:(BOOL)isRefreshTokenAuth andCompletion:(void (^)(void))completion
{
if (error.httpResponse.statusCode == 401
&& [error.userInfo[kMXErrorSoftLogoutKey] isEqual:@(YES)])

[Analytics.shared trackAuthUnauthenticatedErrorWithSoftLogout:isSoftLogout refreshTokenAuth:isRefreshTokenAuth errorCode:error.errcode errorReason:error.error];
MXLogDebug(@"[MXKAccountManager] handleUnauthenticated: trackAuthUnauthenticatedErrorWithSoftLogout sent");
if (isSoftLogout)
{
MXLogDebug(@"[MXKAccountManager] handleUnauthenticated: soft logout.");
[[MXKAccountManager sharedManager] softLogout:self];
Expand Down
17 changes: 13 additions & 4 deletions RiotNSE/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class NotificationService: UNNotificationServiceExtension {
}
let restClient = MXRestClient(credentials: userAccount.mxCredentials, unrecognizedCertificateHandler: nil, persistentTokenDataHandler: { persistTokenDataHandler in
MXKAccountManager.shared().readAndWriteCredentials(persistTokenDataHandler)
}, unauthenticatedHandler: { error, completion in
userAccount.handleUnauthenticated(error, andCompletion: completion)
}, unauthenticatedHandler: { error, softLogout, refreshTokenAuth, completion in
userAccount.handleUnauthenticatedWithError(error, isSoftLogout: softLogout, isRefreshTokenAuth: refreshTokenAuth, andCompletion: completion)
})
return restClient
}()
Expand Down Expand Up @@ -97,6 +97,8 @@ class NotificationService: UNNotificationServiceExtension {
// log memory at the beginning of the process
logMemory()

setupAnalytics()

UNUserNotificationCenter.current().removeUnwantedNotifications()

// check if this is a Matrix notification
Expand Down Expand Up @@ -170,6 +172,13 @@ class NotificationService: UNNotificationServiceExtension {
}
}

private func setupAnalytics(){
// Configure our analytics. It will start if the option is enabled
let analytics = Analytics.shared
MXSDKOptions.sharedInstance().analyticsDelegate = analytics
analytics.startIfEnabled()
}

private func setup(withRoomId roomId: String, eventId: String, completion: @escaping () -> Void) {
MXKAccountManager.sharedManager(withReload: true)
self.userAccount = MXKAccountManager.shared()?.activeAccounts.first
Expand All @@ -180,8 +189,8 @@ class NotificationService: UNNotificationServiceExtension {
self.logMemory()
NotificationService.backgroundSyncService = MXBackgroundSyncService(withCredentials: userAccount.mxCredentials, persistTokenDataHandler: { persistTokenDataHandler in
MXKAccountManager.shared().readAndWriteCredentials(persistTokenDataHandler)
}, unauthenticatedHandler: { error, completion in
userAccount.handleUnauthenticated(error, andCompletion: completion)
}, unauthenticatedHandler: { error, softLogout, refreshTokenAuth, completion in
userAccount.handleUnauthenticatedWithError(error, isSoftLogout: softLogout, isRefreshTokenAuth: refreshTokenAuth, andCompletion: completion)
})
MXLog.debug("[NotificationService] setup: MXBackgroundSyncService init: AFTER")
self.logMemory()
Expand Down
2 changes: 2 additions & 0 deletions RiotNSE/SupportingFiles/RiotNSE-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@

#import "MatrixKit-Bridging-Header.h"

#import "BuildInfo.h"

#endif /* RiotNSE_Bridging_Header_h */
2 changes: 2 additions & 0 deletions RiotNSE/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ targets:
- path: ../Riot/Managers/Widgets/WidgetConstants.m
- path: ../Riot/PropertyWrappers/UserDefaultsBackedPropertyWrapper.swift
- path: ../Riot/Modules/MatrixKit
- path: ../Riot/Modules/Analytics
- path: ../Riot/Managers/AppInfo/
excludes:
- "**/*.md" # excludes all files with the .md extension
- path: ../Riot/Generated/MatrixKitStrings.swift
4 changes: 2 additions & 2 deletions RiotShareExtension/Shared/ShareManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ - (void)shareViewController:(ShareViewController *)shareViewController didReques
MXWeakify(self);
MXRestClient *restClient = [[MXRestClient alloc] initWithCredentials:self.userAccount.mxCredentials andOnUnrecognizedCertificateBlock:nil andPersistentTokenDataHandler:^(void (^handler)(NSArray<MXCredentials *> *credentials, void (^completion)(BOOL didUpdateCredentials))) {
[[MXKAccountManager sharedManager] readAndWriteCredentials:handler];
} andUnauthenticatedHandler:^(MXError *error, void (^completion)(void)) {
} andUnauthenticatedHandler:^(MXError *error, BOOL isSoftLogout, BOOL isRefreshTokenAuth, void (^completion)(void)) {
MXStrongifyAndReturnIfNil(self);
[self.userAccount handleUnauthenticated:error andCompletion:completion];
[self.userAccount handleUnauthenticatedWithError:error isSoftLogout:isSoftLogout isRefreshTokenAuth:isRefreshTokenAuth andCompletion:completion];
}];
MXSession *session = [[MXSession alloc] initWithMatrixRestClient:restClient];
[MXFileStore setPreloadOptions:0];
Expand Down
4 changes: 4 additions & 0 deletions RiotShareExtension/Sources/ShareExtensionRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ - (void)viewDidLoad

[MXLog configure:configuration];

// Configure our analytics. It will start if the option is enabled
Analytics *analytics = Analytics.shared;
[MXSDKOptions sharedInstance].analyticsDelegate = analytics;
[analytics startIfEnabled];

[ThemeService.shared setThemeId:RiotSettings.shared.userInterfaceTheme];

Expand Down
1 change: 1 addition & 0 deletions RiotShareExtension/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ targets:
- path: ../Riot/Assets/SharedImages.xcassets
buildPhase: resources
- path: ../Riot/Modules/MatrixKit
- path: ../Riot/Modules/Analytics
excludes:
- "**/*.md" # excludes all files with the .md extension
- path: ../Riot/Generated/MatrixKitStrings.swift
5 changes: 5 additions & 0 deletions SiriIntents/IntentHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ - (instancetype)init
}

[MXLog configure:configuration];

// Configure our analytics. It will start if the option is enabled
Analytics *analytics = Analytics.shared;
[MXSDKOptions sharedInstance].analyticsDelegate = analytics;
[analytics startIfEnabled];
}
return self;
}
Expand Down
1 change: 1 addition & 0 deletions SiriIntents/SupportingFiles/SiriIntents-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
//

#import "MatrixKit-Bridging-Header.h"
#import "BuildInfo.h"
4 changes: 4 additions & 0 deletions SiriIntents/target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ targets:
- path: ../Riot/Managers/Locale/LocaleProviderType.swift
- path: ../Riot/Managers/Locale/LocaleProvider.swift
- path: ../Riot/Modules/MatrixKit
- path: ../Riot/Modules/Analytics
- path: ../Riot/Managers/AppInfo/
- path: ../Riot/Managers/Locale/LocaleProviderType.swift
- path: ../Riot/Generated/Strings.swift
excludes:
- "**/*.md" # excludes all files with the .md extension
- path: ../Riot/Generated/MatrixKitStrings.swift