mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-24 10:32:46 +02:00
Merge branch 'develop' of github.com:vector-im/element-ios into langleyd/wysiwyg_integration
This commit is contained in:
@@ -306,6 +306,15 @@ typedef BOOL (^MXKAccountOnCertificateChange)(MXKAccount *mxAccount, NSData *cer
|
||||
*/
|
||||
- (void)load3PIDs:(void (^)(void))success failure:(void (^)(NSError *error))failure;
|
||||
|
||||
/**
|
||||
Loads the pusher instance linked to this account.
|
||||
This method must be called to refresh self.pushNotificationServiceIsActive
|
||||
|
||||
@param success A block object called when the operation succeeds.
|
||||
@param failure A block object called when the operation fails.
|
||||
*/
|
||||
- (void)loadCurrentPusher:(nullable void (^)(void))success failure:(nullable void (^)(NSError *error))failure;
|
||||
|
||||
/**
|
||||
Load the current device information for this account.
|
||||
This method must be called to refresh self.device.
|
||||
|
||||
@@ -86,6 +86,8 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
|
||||
// Observe NSCurrentLocaleDidChangeNotification to refresh MXRoomSummaries on time formatting change.
|
||||
id NSCurrentLocaleDidChangeNotificationObserver;
|
||||
|
||||
MXPusher *currentPusher;
|
||||
}
|
||||
|
||||
/// Will be true if the session is not in a pauseable state or we requested for the session to pause but not finished yet. Will be reverted to false again after `resume` called.
|
||||
@@ -149,6 +151,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
|
||||
// Refresh device information
|
||||
[self loadDeviceInformation:nil failure:nil];
|
||||
[self loadCurrentPusher:nil failure:nil];
|
||||
|
||||
[self registerAccountDataDidChangeIdentityServerNotification];
|
||||
[self registerIdentityServiceDidChangeAccessTokenNotification];
|
||||
@@ -184,6 +187,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
|
||||
// Refresh device information
|
||||
[self loadDeviceInformation:nil failure:nil];
|
||||
[self loadCurrentPusher:nil failure:nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -303,6 +307,12 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
|
||||
- (BOOL)pushNotificationServiceIsActive
|
||||
{
|
||||
if (currentPusher && currentPusher.enabled)
|
||||
{
|
||||
MXLogDebug(@"[MXKAccount][Push] pushNotificationServiceIsActive: currentPusher.enabled %@", currentPusher.enabled);
|
||||
return currentPusher.enabled.boolValue;
|
||||
}
|
||||
|
||||
BOOL pushNotificationServiceIsActive = ([[MXKAccountManager sharedManager] isAPNSAvailable] && self.hasPusherForPushNotifications && mxSession);
|
||||
MXLogDebug(@"[MXKAccount][Push] pushNotificationServiceIsActive: %@", @(pushNotificationServiceIsActive));
|
||||
|
||||
@@ -317,7 +327,44 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
|
||||
if (enable)
|
||||
{
|
||||
if ([[MXKAccountManager sharedManager] isAPNSAvailable])
|
||||
if (currentPusher && currentPusher.enabled && !currentPusher.enabled.boolValue)
|
||||
{
|
||||
[self.mxSession.matrixRestClient setPusherWithPushkey:currentPusher.pushkey
|
||||
kind:currentPusher.kind
|
||||
appId:currentPusher.appId
|
||||
appDisplayName:currentPusher.appDisplayName
|
||||
deviceDisplayName:currentPusher.deviceDisplayName
|
||||
profileTag:currentPusher.profileTag
|
||||
lang:currentPusher.lang
|
||||
data:currentPusher.data.JSONDictionary
|
||||
append:NO
|
||||
enabled:enable
|
||||
success:^{
|
||||
|
||||
MXLogDebug(@"[MXKAccount][Push] enablePushNotifications: remotely enabled Push: Success");
|
||||
[self loadCurrentPusher:^{
|
||||
if (success)
|
||||
{
|
||||
success();
|
||||
}
|
||||
} failure:^(NSError *error) {
|
||||
|
||||
MXLogWarning(@"[MXKAccount][Push] enablePushNotifications: load current pusher failed with error: %@", error);
|
||||
if (failure)
|
||||
{
|
||||
failure(error);
|
||||
}
|
||||
}];
|
||||
} failure:^(NSError *error) {
|
||||
|
||||
MXLogWarning(@"[MXKAccount][Push] enablePushNotifications: remotely enable push failed with error: %@", error);
|
||||
if (failure)
|
||||
{
|
||||
failure(error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
else if ([[MXKAccountManager sharedManager] isAPNSAvailable])
|
||||
{
|
||||
MXLogDebug(@"[MXKAccount][Push] enablePushNotifications: Enable Push for %@ account", self.mxCredentials.userId);
|
||||
|
||||
@@ -354,7 +401,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (self.hasPusherForPushNotifications)
|
||||
else if (self.hasPusherForPushNotifications || currentPusher)
|
||||
{
|
||||
MXLogDebug(@"[MXKAccount][Push] enablePushNotifications: Disable APNS for %@ account", self.mxCredentials.userId);
|
||||
|
||||
@@ -626,6 +673,65 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)loadCurrentPusher:(void (^)(void))success failure:(void (^)(NSError *error))failure
|
||||
{
|
||||
if (!self.mxSession.myDeviceId)
|
||||
{
|
||||
MXLogWarning(@"[MXKAccount] loadPusher: device ID not found");
|
||||
if (failure)
|
||||
{
|
||||
failure([NSError errorWithDomain:kMXKAccountErrorDomain code:0 userInfo:nil]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
[self.mxSession supportedMatrixVersions:^(MXMatrixVersions *matrixVersions) {
|
||||
if (!matrixVersions.supportsRemotelyTogglingPushNotifications)
|
||||
{
|
||||
MXLogDebug(@"[MXKAccount] loadPusher: remotely toggling push notifications not supported");
|
||||
|
||||
if (success)
|
||||
{
|
||||
success();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
[self.mxSession.matrixRestClient pushers:^(NSArray<MXPusher *> *pushers) {
|
||||
MXPusher *ownPusher;
|
||||
for (MXPusher *pusher in pushers)
|
||||
{
|
||||
if ([pusher.deviceId isEqualToString:self.mxSession.myDeviceId])
|
||||
{
|
||||
ownPusher = pusher;
|
||||
}
|
||||
}
|
||||
|
||||
self->currentPusher = ownPusher;
|
||||
|
||||
if (success)
|
||||
{
|
||||
success();
|
||||
}
|
||||
} failure:^(NSError *error) {
|
||||
MXLogWarning(@"[MXKAccount] loadPusher: get pushers failed due to error %@", error);
|
||||
|
||||
if (failure)
|
||||
{
|
||||
failure(error);
|
||||
}
|
||||
}];
|
||||
} failure:^(NSError *error) {
|
||||
MXLogWarning(@"[MXKAccount] loadPusher: supportedMatrixVersions failed due to error %@", error);
|
||||
|
||||
if (failure)
|
||||
{
|
||||
failure(error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)loadDeviceInformation:(void (^)(void))success failure:(void (^)(NSError *error))failure
|
||||
{
|
||||
if (self.mxCredentials.deviceId)
|
||||
@@ -773,7 +879,9 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
[MXKContactManager.sharedManager validateSyncLocalContactsStateForSession:self.mxSession];
|
||||
|
||||
// Refresh pusher state
|
||||
[self refreshAPNSPusher];
|
||||
[self loadCurrentPusher:^{
|
||||
[self refreshAPNSPusher];
|
||||
} failure:nil];
|
||||
[self refreshPushKitPusher];
|
||||
|
||||
// Launch server sync
|
||||
@@ -1106,6 +1214,12 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
- (void)refreshAPNSPusher
|
||||
{
|
||||
MXLogDebug(@"[MXKAccount][Push] refreshAPNSPusher");
|
||||
|
||||
if (currentPusher)
|
||||
{
|
||||
MXLogDebug(@"[MXKAccount][Push] refreshAPNSPusher aborted as a pusher has been found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check the conditions required to run the pusher
|
||||
if (self.pushNotificationServiceIsActive)
|
||||
@@ -1165,12 +1279,35 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
self->_hasPusherForPushNotifications = enabled;
|
||||
[[MXKAccountManager sharedManager] saveAccounts];
|
||||
|
||||
if (success)
|
||||
if (enabled)
|
||||
{
|
||||
success();
|
||||
[self loadCurrentPusher:^{
|
||||
if (success)
|
||||
{
|
||||
success();
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountAPNSActivityDidChangeNotification object:self.mxCredentials.userId];
|
||||
} failure:^(NSError *error) {
|
||||
if (success)
|
||||
{
|
||||
success();
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountAPNSActivityDidChangeNotification object:self.mxCredentials.userId];
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
self->currentPusher = nil;
|
||||
|
||||
if (success)
|
||||
{
|
||||
success();
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountAPNSActivityDidChangeNotification object:self.mxCredentials.userId];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKAccountAPNSActivityDidChangeNotification object:self.mxCredentials.userId];
|
||||
|
||||
} failure:^(NSError *error) {
|
||||
|
||||
@@ -1415,7 +1552,7 @@ static NSArray<NSNumber*> *initialSyncSilentErrorsHTTPStatusCodes;
|
||||
|
||||
MXRestClient *restCli = self.mxRestClient;
|
||||
|
||||
[restCli setPusherWithPushkey:b64Token kind:kind appId:appId appDisplayName:appDisplayName deviceDisplayName:[[UIDevice currentDevice] name] profileTag:profileTag lang:deviceLang data:pushData append:append success:success failure:failure];
|
||||
[restCli setPusherWithPushkey:b64Token kind:kind appId:appId appDisplayName:appDisplayName deviceDisplayName:[[UIDevice currentDevice] name] profileTag:profileTag lang:deviceLang data:pushData append:append enabled:enabled success:success failure:failure];
|
||||
}
|
||||
|
||||
#pragma mark - InApp notifications
|
||||
|
||||
@@ -920,7 +920,7 @@
|
||||
{
|
||||
for (MXKRoomBubbleComponent *component in bubbleComponents)
|
||||
{
|
||||
if (component.showEncryptionBadge)
|
||||
if (component.encryptionDecoration != EventEncryptionDecorationNone)
|
||||
{
|
||||
containsBubbleComponentWithEncryptionBadge = YES;
|
||||
break;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#import "MXKEventFormatter.h"
|
||||
#import "MXKURLPreviewDataProtocol.h"
|
||||
#import "EventEncryptionDecoration.h"
|
||||
|
||||
@protocol MXThreadProtocol;
|
||||
|
||||
@@ -101,9 +102,9 @@ typedef enum : NSUInteger {
|
||||
@property (nonatomic) MXEventScan *eventScan;
|
||||
|
||||
/**
|
||||
Indicate if an encryption badge should be shown.
|
||||
Type of encryption decoration (if any) for this event
|
||||
*/
|
||||
@property (nonatomic, readonly) BOOL showEncryptionBadge;
|
||||
@property (nonatomic, readonly) EventEncryptionDecoration encryptionDecoration;
|
||||
|
||||
/**
|
||||
Thread for the bubble component. Should only exist for thread root events.
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
_showEncryptionBadge = [self shouldShowWarningBadgeForEvent:event roomState:(MXRoomState*)roomState session:session];
|
||||
_encryptionDecoration = [self encryptionDecorationForEvent:event roomState:(MXRoomState*)roomState session:session];
|
||||
|
||||
[self updateLinkWithRoomState:roomState];
|
||||
|
||||
@@ -116,7 +116,7 @@
|
||||
andLatestRoomState:latestRoomState
|
||||
error:&error];
|
||||
|
||||
_showEncryptionBadge = [self shouldShowWarningBadgeForEvent:event roomState:roomState session:session];
|
||||
_encryptionDecoration = [self encryptionDecorationForEvent:event roomState:roomState session:session];
|
||||
|
||||
[self updateLinkWithRoomState:roomState];
|
||||
}
|
||||
@@ -167,24 +167,24 @@
|
||||
self.link = url;
|
||||
}
|
||||
|
||||
- (BOOL)shouldShowWarningBadgeForEvent:(MXEvent*)event roomState:(MXRoomState*)roomState session:(MXSession*)session
|
||||
- (EventEncryptionDecoration)encryptionDecorationForEvent:(MXEvent*)event roomState:(MXRoomState*)roomState session:(MXSession*)session
|
||||
{
|
||||
// Warning badges are unnecessary in unencrypted rooms
|
||||
if (!roomState.isEncrypted)
|
||||
{
|
||||
return NO;
|
||||
return EventEncryptionDecorationNone;
|
||||
}
|
||||
|
||||
// Not all events are encrypted (e.g. state/reactions/redactions) and we only have encrypted cell subclasses for messages and attachments.
|
||||
if (event.eventType != MXEventTypeRoomMessage && !event.isMediaAttachment)
|
||||
{
|
||||
return NO;
|
||||
return EventEncryptionDecorationNone;
|
||||
}
|
||||
|
||||
// Always show a warning badge if there was a decryption error.
|
||||
if (event.decryptionError)
|
||||
{
|
||||
return YES;
|
||||
return EventEncryptionDecorationDecryptionError;
|
||||
}
|
||||
|
||||
// Unencrypted message events should show a warning unless they're pending local echoes
|
||||
@@ -193,10 +193,10 @@
|
||||
if (event.isLocalEvent
|
||||
|| event.contentHasBeenEdited) // Local echo for an edit is clear but uses a true event id, the one of the edited event
|
||||
{
|
||||
return NO;
|
||||
return EventEncryptionDecorationNone;
|
||||
}
|
||||
|
||||
return YES;
|
||||
return EventEncryptionDecorationNotEncrypted;
|
||||
}
|
||||
|
||||
// The encryption is in a good state.
|
||||
@@ -208,12 +208,17 @@
|
||||
|
||||
if (userTrustLevel.isVerified && !deviceInfo.trustLevel.isVerified)
|
||||
{
|
||||
return YES;
|
||||
return EventEncryptionDecorationUntrustedDevice;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.isUntrusted)
|
||||
{
|
||||
return EventEncryptionDecorationUnsafeKey;
|
||||
}
|
||||
|
||||
// Everything was fine
|
||||
return NO;
|
||||
return EventEncryptionDecorationNone;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -166,10 +166,11 @@ private extension CMarkNode {
|
||||
private extension String {
|
||||
/// Returns array of URLs detected inside the String.
|
||||
var containedUrls: [NSTextCheckingResult] {
|
||||
guard let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) else {
|
||||
guard let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue),
|
||||
let percentEncoded = self.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) else {
|
||||
return []
|
||||
}
|
||||
|
||||
return detector.matches(in: self, options: [], range: NSRange(location: 0, length: self.utf16.count))
|
||||
return detector.matches(in: percentEncoded, options: [], range: NSRange(location: 0, length: percentEncoded.utf16.count))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ static NSAttributedString *verticalWhitespace = nil;
|
||||
NSString *claimedKey = _mxEvent.keysClaimed[@"ed25519"];
|
||||
NSString *algorithm = _mxEvent.wireContent[@"algorithm"];
|
||||
NSString *sessionId = _mxEvent.wireContent[@"session_id"];
|
||||
NSString *untrusted = _mxEvent.isUntrusted ? [VectorL10n userVerificationSessionsListSessionUntrusted] : [VectorL10n userVerificationSessionsListSessionTrusted];
|
||||
NSString *untrusted = _mxEvent.isUntrusted ? [VectorL10n roomEventEncryptionInfoKeyAuthenticityNotGuaranteed] : [VectorL10n userVerificationSessionsListSessionTrusted];
|
||||
|
||||
NSString *decryptionError;
|
||||
if (_mxEvent.decryptionError)
|
||||
|
||||
Reference in New Issue
Block a user