mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-18 23:48:29 +02:00
Merge MatrixKit develop with commit hash: b85b736313bec0592bd1cabc68035d97f5331137
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
Copyright 2017 Vector Creations 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>
|
||||
|
||||
#import "MXKView.h"
|
||||
|
||||
@protocol MXKEncryptionInfoViewDelegate;
|
||||
|
||||
/**
|
||||
MXKEncryptionInfoView class may be used to display the available information on a encrypted event.
|
||||
The event sender device may be verified, unverified, blocked or unblocked from this view.
|
||||
*/
|
||||
@interface MXKEncryptionInfoView : MXKView
|
||||
|
||||
/**
|
||||
The displayed event
|
||||
*/
|
||||
@property (nonatomic, readonly) MXEvent *mxEvent;
|
||||
|
||||
/**
|
||||
The matrix session.
|
||||
*/
|
||||
@property (nonatomic, readonly) MXSession *mxSession;
|
||||
|
||||
/**
|
||||
The event device info
|
||||
*/
|
||||
@property (nonatomic, readonly) MXDeviceInfo *mxDeviceInfo;
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UITextView *textView;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *cancelButton;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *verifyButton;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *blockButton;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *confirmVerifyButton;
|
||||
|
||||
@property (nonatomic, weak) id<MXKEncryptionInfoViewDelegate> delegate;
|
||||
|
||||
/**
|
||||
Initialise an `MXKEncryptionInfoView` instance based on an encrypted event
|
||||
|
||||
@param event the encrypted event.
|
||||
@param session the related matrix session.
|
||||
@return the newly created instance.
|
||||
*/
|
||||
- (instancetype)initWithEvent:(MXEvent*)event andMatrixSession:(MXSession*)session;
|
||||
|
||||
/**
|
||||
Initialise an `MXKEncryptionInfoView` instance based only on a device information.
|
||||
|
||||
@param deviceInfo the device information.
|
||||
@param session the related matrix session.
|
||||
@return the newly created instance.
|
||||
*/
|
||||
- (instancetype)initWithDeviceInfo:(MXDeviceInfo*)deviceInfo andMatrixSession:(MXSession*)session;
|
||||
|
||||
/**
|
||||
The default text color in the text view. [UIColor blackColor] by default.
|
||||
*/
|
||||
@property (nonatomic) UIColor *defaultTextColor;
|
||||
|
||||
/**
|
||||
Action registered on 'UIControlEventTouchUpInside' event for each UIButton instance.
|
||||
*/
|
||||
- (IBAction)onButtonPressed:(id)sender;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@protocol MXKEncryptionInfoViewDelegate <NSObject>
|
||||
|
||||
/**
|
||||
Called when the user changes the verified state of a device.
|
||||
|
||||
@param encryptionInfoView the view.
|
||||
@param deviceInfo the device that has changed.
|
||||
*/
|
||||
- (void)encryptionInfoView:(MXKEncryptionInfoView*)encryptionInfoView didDeviceInfoVerifiedChange:(MXDeviceInfo*)deviceInfo;
|
||||
|
||||
@optional
|
||||
|
||||
/**
|
||||
Called when the user close the view without changing value.
|
||||
|
||||
@param encryptionInfoView the view.
|
||||
*/
|
||||
- (void)encryptionInfoViewDidClose:(MXKEncryptionInfoView*)encryptionInfoView;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,492 @@
|
||||
/*
|
||||
Copyright 2016 OpenMarket Ltd
|
||||
Copyright 2017 Vector Creations Ltd
|
||||
Copyright 2018 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 "MXKEncryptionInfoView.h"
|
||||
|
||||
#import "NSBundle+MatrixKit.h"
|
||||
|
||||
#import "MXKConstants.h"
|
||||
|
||||
#import "MXKSwiftHeader.h"
|
||||
|
||||
static NSAttributedString *verticalWhitespace = nil;
|
||||
|
||||
@interface MXKEncryptionInfoView ()
|
||||
{
|
||||
/**
|
||||
Current request in progress.
|
||||
*/
|
||||
MXHTTPOperation *mxCurrentOperation;
|
||||
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation MXKEncryptionInfoView
|
||||
|
||||
+ (UINib *)nib
|
||||
{
|
||||
// Check whether a nib file is available
|
||||
NSBundle *mainBundle = [NSBundle mxk_bundleForClass:self.class];
|
||||
|
||||
NSString *path = [mainBundle pathForResource:NSStringFromClass([self class]) ofType:@"nib"];
|
||||
if (path)
|
||||
{
|
||||
return [UINib nibWithNibName:NSStringFromClass([self class]) bundle:mainBundle];
|
||||
}
|
||||
return [UINib nibWithNibName:NSStringFromClass([MXKEncryptionInfoView class]) bundle:[NSBundle mxk_bundleForClass:[MXKEncryptionInfoView class]]];
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[super awakeFromNib];
|
||||
|
||||
// Localize string
|
||||
[_cancelButton setTitle:[MatrixKitL10n ok] forState:UIControlStateNormal];
|
||||
[_cancelButton setTitle:[MatrixKitL10n ok] forState:UIControlStateHighlighted];
|
||||
|
||||
[_confirmVerifyButton setTitle:[MatrixKitL10n roomEventEncryptionVerifyOk] forState:UIControlStateNormal];
|
||||
[_confirmVerifyButton setTitle:[MatrixKitL10n roomEventEncryptionVerifyOk] forState:UIControlStateHighlighted];
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
[super layoutSubviews];
|
||||
|
||||
// Scroll to the top the text view content
|
||||
self.textView.contentOffset = CGPointZero;
|
||||
}
|
||||
|
||||
- (void)removeFromSuperview
|
||||
{
|
||||
if (mxCurrentOperation)
|
||||
{
|
||||
[mxCurrentOperation cancel];
|
||||
mxCurrentOperation = nil;
|
||||
}
|
||||
|
||||
[super removeFromSuperview];
|
||||
}
|
||||
|
||||
#pragma mark - Override MXKView
|
||||
|
||||
-(void)customizeViewRendering
|
||||
{
|
||||
[super customizeViewRendering];
|
||||
|
||||
_defaultTextColor = [UIColor blackColor];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (instancetype)initWithEvent:(MXEvent*)event andMatrixSession:(MXSession*)session
|
||||
{
|
||||
self = [[[self class] nib] instantiateWithOwner:nil options:nil].firstObject;
|
||||
if (self)
|
||||
{
|
||||
_mxEvent = event;
|
||||
_mxSession = session;
|
||||
_mxDeviceInfo = nil;
|
||||
|
||||
[self setTranslatesAutoresizingMaskIntoConstraints: NO];
|
||||
|
||||
[self updateTextViewText];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithDeviceInfo:(MXDeviceInfo*)deviceInfo andMatrixSession:(MXSession*)session
|
||||
{
|
||||
self = [[[self class] nib] instantiateWithOwner:nil options:nil].firstObject;
|
||||
if (self)
|
||||
{
|
||||
_mxEvent = nil;
|
||||
_mxDeviceInfo = deviceInfo;
|
||||
_mxSession = session;
|
||||
|
||||
[self setTranslatesAutoresizingMaskIntoConstraints: NO];
|
||||
|
||||
[self updateTextViewText];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
_mxEvent = nil;
|
||||
_mxSession = nil;
|
||||
_mxDeviceInfo = nil;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)updateTextViewText
|
||||
{
|
||||
// Prepare the text view content
|
||||
NSMutableAttributedString *textViewAttributedString = [[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoTitle]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:17]}];
|
||||
|
||||
if (_mxEvent)
|
||||
{
|
||||
NSString *senderId = _mxEvent.sender;
|
||||
|
||||
if (_mxSession && _mxSession.crypto && !_mxDeviceInfo)
|
||||
{
|
||||
_mxDeviceInfo = [_mxSession.crypto eventDeviceInfo:_mxEvent];
|
||||
|
||||
if (!_mxDeviceInfo)
|
||||
{
|
||||
// Trigger a server request to get the device information for the event sender
|
||||
mxCurrentOperation = [_mxSession.crypto downloadKeys:@[senderId] forceDownload:NO success:^(MXUsersDevicesMap<MXDeviceInfo *> *usersDevicesInfoMap, NSDictionary<NSString *,MXCrossSigningInfo *> *crossSigningKeysMap) {
|
||||
|
||||
self->mxCurrentOperation = nil;
|
||||
|
||||
// Sanity check: check whether some device information has been retrieved.
|
||||
self->_mxDeviceInfo = [self.mxSession.crypto eventDeviceInfo:self.mxEvent];
|
||||
if (self.mxDeviceInfo)
|
||||
{
|
||||
[self updateTextViewText];
|
||||
}
|
||||
|
||||
} failure:^(NSError *error) {
|
||||
|
||||
self->mxCurrentOperation = nil;
|
||||
|
||||
MXLogDebug(@"[MXKEncryptionInfoView] Crypto failed to download device info for user: %@", self.mxEvent.sender);
|
||||
|
||||
// Notify MatrixKit user
|
||||
NSString *myUserId = self.mxSession.myUser.userId;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error userInfo:myUserId ? @{kMXKErrorUserIdKey: myUserId} : nil];
|
||||
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
// Event information
|
||||
NSMutableAttributedString *eventInformationString = [[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoEvent]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:15]}];
|
||||
[eventInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
|
||||
NSString *senderKey = _mxEvent.senderKey;
|
||||
NSString *claimedKey = _mxEvent.keysClaimed[@"ed25519"];
|
||||
NSString *algorithm = _mxEvent.wireContent[@"algorithm"];
|
||||
NSString *sessionId = _mxEvent.wireContent[@"session_id"];
|
||||
|
||||
NSString *decryptionError;
|
||||
if (_mxEvent.decryptionError)
|
||||
{
|
||||
decryptionError = [NSString stringWithFormat:@"** %@ **", _mxEvent.decryptionError.localizedDescription];
|
||||
}
|
||||
|
||||
if (!senderKey.length)
|
||||
{
|
||||
senderKey = [MatrixKitL10n roomEventEncryptionInfoEventNone];
|
||||
}
|
||||
if (!claimedKey.length)
|
||||
{
|
||||
claimedKey = [MatrixKitL10n roomEventEncryptionInfoEventNone];
|
||||
}
|
||||
if (!algorithm.length)
|
||||
{
|
||||
algorithm = [MatrixKitL10n roomEventEncryptionInfoEventUnencrypted];
|
||||
}
|
||||
if (!sessionId.length)
|
||||
{
|
||||
sessionId = [MatrixKitL10n roomEventEncryptionInfoEventNone];
|
||||
}
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoEventUserId] attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:senderId
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoEventIdentityKey]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:senderKey
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoEventFingerprintKey]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:claimedKey
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoEventAlgorithm]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:algorithm
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
|
||||
if (decryptionError.length)
|
||||
{
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoEventDecryptionError]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:decryptionError
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
}
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoEventSessionId]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:sessionId
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[textViewAttributedString appendAttributedString:eventInformationString];
|
||||
}
|
||||
|
||||
// Device information
|
||||
NSMutableAttributedString *deviceInformationString = [[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoDevice]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:15]}];
|
||||
[deviceInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
|
||||
if (_mxDeviceInfo)
|
||||
{
|
||||
NSString *name = _mxDeviceInfo.displayName;
|
||||
NSString *deviceId = _mxDeviceInfo.deviceId;
|
||||
NSMutableAttributedString *verification;
|
||||
NSString *fingerprint = _mxDeviceInfo.fingerprint;
|
||||
|
||||
// Display here the Verify and Block buttons except if the device is the current one.
|
||||
_verifyButton.hidden = _blockButton.hidden = [_mxDeviceInfo.deviceId isEqualToString:_mxSession.matrixRestClient.credentials.deviceId];
|
||||
|
||||
switch (_mxDeviceInfo.trustLevel.localVerificationStatus)
|
||||
{
|
||||
case MXDeviceUnknown:
|
||||
case MXDeviceUnverified:
|
||||
{
|
||||
verification = [[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoDeviceNotVerified]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}];
|
||||
|
||||
[_verifyButton setTitle:[MatrixKitL10n roomEventEncryptionInfoVerify] forState:UIControlStateNormal];
|
||||
[_verifyButton setTitle:[MatrixKitL10n roomEventEncryptionInfoVerify] forState:UIControlStateHighlighted];
|
||||
[_blockButton setTitle:[MatrixKitL10n roomEventEncryptionInfoBlock] forState:UIControlStateNormal];
|
||||
[_blockButton setTitle:[MatrixKitL10n roomEventEncryptionInfoBlock] forState:UIControlStateHighlighted];
|
||||
break;
|
||||
}
|
||||
case MXDeviceVerified:
|
||||
{
|
||||
verification = [[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoDeviceVerified]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}];
|
||||
|
||||
[_verifyButton setTitle:[MatrixKitL10n roomEventEncryptionInfoUnverify] forState:UIControlStateNormal];
|
||||
[_verifyButton setTitle:[MatrixKitL10n roomEventEncryptionInfoUnverify] forState:UIControlStateHighlighted];
|
||||
[_blockButton setTitle:[MatrixKitL10n roomEventEncryptionInfoBlock] forState:UIControlStateNormal];
|
||||
[_blockButton setTitle:[MatrixKitL10n roomEventEncryptionInfoBlock] forState:UIControlStateHighlighted];
|
||||
|
||||
break;
|
||||
}
|
||||
case MXDeviceBlocked:
|
||||
{
|
||||
verification = [[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoDeviceBlocked]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}];
|
||||
|
||||
[_verifyButton setTitle:[MatrixKitL10n roomEventEncryptionInfoVerify] forState:UIControlStateNormal];
|
||||
[_verifyButton setTitle:[MatrixKitL10n roomEventEncryptionInfoVerify] forState:UIControlStateHighlighted];
|
||||
[_blockButton setTitle:[MatrixKitL10n roomEventEncryptionInfoUnblock] forState:UIControlStateNormal];
|
||||
[_blockButton setTitle:[MatrixKitL10n roomEventEncryptionInfoUnblock] forState:UIControlStateHighlighted];
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoDeviceName]
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:(name.length ? name : @"")
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoDeviceId] attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:deviceId
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoDeviceVerification] attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:verification];
|
||||
[deviceInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoDeviceFingerprint] attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:fingerprint
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[MXKEncryptionInfoView verticalWhitespace]];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unknown device
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionInfoDeviceUnknown] attributes:@{NSForegroundColorAttributeName: _defaultTextColor, NSFontAttributeName: [UIFont italicSystemFontOfSize:14]}]];
|
||||
}
|
||||
|
||||
[textViewAttributedString appendAttributedString:deviceInformationString];
|
||||
|
||||
self.textView.attributedText = textViewAttributedString;
|
||||
}
|
||||
|
||||
+ (NSAttributedString *)verticalWhitespace
|
||||
{
|
||||
if (verticalWhitespace == nil)
|
||||
{
|
||||
verticalWhitespace = [[NSAttributedString alloc] initWithString:@"\n\n" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:4]}];
|
||||
}
|
||||
return verticalWhitespace;
|
||||
}
|
||||
|
||||
#pragma mark - Actions
|
||||
|
||||
- (IBAction)onButtonPressed:(id)sender
|
||||
{
|
||||
if (sender == _cancelButton)
|
||||
{
|
||||
[self removeFromSuperview];
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(encryptionInfoViewDidClose:)])
|
||||
{
|
||||
[_delegate encryptionInfoViewDidClose:self];
|
||||
}
|
||||
}
|
||||
// Note: Verify and Block buttons are hidden when the deviceInfo is not available
|
||||
else if (sender == _confirmVerifyButton && _mxDeviceInfo)
|
||||
{
|
||||
[_mxSession.crypto setDeviceVerification:MXDeviceVerified forDevice:_mxDeviceInfo.deviceId ofUser:_mxDeviceInfo.userId success:^{
|
||||
|
||||
// Refresh data
|
||||
_mxDeviceInfo = [self.mxSession.crypto eventDeviceInfo:self.mxEvent];
|
||||
if (self->_delegate)
|
||||
{
|
||||
[self->_delegate encryptionInfoView:self didDeviceInfoVerifiedChange:self.mxDeviceInfo];
|
||||
}
|
||||
[self removeFromSuperview];
|
||||
|
||||
} failure:^(NSError *error) {
|
||||
[self removeFromSuperview];
|
||||
}];
|
||||
}
|
||||
else if (_mxDeviceInfo)
|
||||
{
|
||||
MXDeviceVerification verificationStatus;
|
||||
|
||||
if (sender == _verifyButton)
|
||||
{
|
||||
verificationStatus = ((_mxDeviceInfo.trustLevel.localVerificationStatus == MXDeviceVerified) ? MXDeviceUnverified : MXDeviceVerified);
|
||||
}
|
||||
else if (sender == _blockButton)
|
||||
{
|
||||
verificationStatus = ((_mxDeviceInfo.trustLevel.localVerificationStatus == MXDeviceBlocked) ? MXDeviceUnverified : MXDeviceBlocked);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unexpected case
|
||||
MXLogDebug(@"[MXKEncryptionInfoView] Invalid button pressed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (verificationStatus == MXDeviceVerified)
|
||||
{
|
||||
// Prompt user
|
||||
NSMutableAttributedString *textViewAttributedString = [[NSMutableAttributedString alloc]
|
||||
initWithString:[MatrixKitL10n roomEventEncryptionVerifyTitle] attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:17]}];
|
||||
|
||||
NSString *message = [MatrixKitL10n roomEventEncryptionVerifyMessage:_mxDeviceInfo.displayName :_mxDeviceInfo.deviceId :_mxDeviceInfo.fingerprint];
|
||||
|
||||
[textViewAttributedString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:message
|
||||
attributes:@{NSForegroundColorAttributeName: _defaultTextColor,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
|
||||
self.textView.attributedText = textViewAttributedString;
|
||||
|
||||
[_cancelButton setTitle:[MatrixKitL10n cancel] forState:UIControlStateNormal];
|
||||
[_cancelButton setTitle:[MatrixKitL10n cancel] forState:UIControlStateHighlighted];
|
||||
_verifyButton.hidden = _blockButton.hidden = YES;
|
||||
_confirmVerifyButton.hidden = NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
[_mxSession.crypto setDeviceVerification:verificationStatus forDevice:_mxDeviceInfo.deviceId ofUser:_mxDeviceInfo.userId success:^{
|
||||
|
||||
// Refresh data
|
||||
_mxDeviceInfo = [self.mxSession.crypto eventDeviceInfo:self.mxEvent];
|
||||
|
||||
if (self->_delegate)
|
||||
{
|
||||
[self->_delegate encryptionInfoView:self didDeviceInfoVerifiedChange:self.mxDeviceInfo];
|
||||
}
|
||||
|
||||
[self removeFromSuperview];
|
||||
|
||||
} failure:^(NSError *error) {
|
||||
[self removeFromSuperview];
|
||||
}];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,90 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16C67" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
|
||||
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
||||
<view contentMode="scaleToFill" id="8VI-1E-fge" customClass="MXKEncryptionInfoView">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<textView autoresizesSubviews="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" bounces="NO" editable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="3Vk-Jx-L6Y">
|
||||
<rect key="frame" x="10" y="10" width="580" height="540"/>
|
||||
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
|
||||
<string key="text">Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Nam liber te conscient to factor tum poen legum odioque civiuda.</string>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
|
||||
</textView>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ump-1C-SzI">
|
||||
<rect key="frame" x="60" y="560" width="30" height="30"/>
|
||||
<state key="normal" title="OK">
|
||||
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="onButtonPressed:" destination="8VI-1E-fge" eventType="touchUpInside" id="t42-2S-MsY"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qkC-t0-Qd0">
|
||||
<rect key="frame" x="355" y="560" width="40" height="30"/>
|
||||
<state key="normal" title="Verify">
|
||||
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="onButtonPressed:" destination="8VI-1E-fge" eventType="touchUpInside" id="ljK-ul-fY2"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="IdO-jn-iTV">
|
||||
<rect key="frame" x="507" y="560" width="38" height="30"/>
|
||||
<state key="normal" title="Block">
|
||||
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="onButtonPressed:" destination="8VI-1E-fge" eventType="touchUpInside" id="j21-e2-e3C"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="L4h-aG-8UN">
|
||||
<rect key="frame" x="506" y="560" width="40" height="30"/>
|
||||
<state key="normal" title="Verify">
|
||||
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</state>
|
||||
<connections>
|
||||
<action selector="onButtonPressed:" destination="8VI-1E-fge" eventType="touchUpInside" id="nKr-w7-ECp"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<constraints>
|
||||
<constraint firstItem="L4h-aG-8UN" firstAttribute="top" secondItem="3Vk-Jx-L6Y" secondAttribute="bottom" constant="10" id="0tX-be-JRZ"/>
|
||||
<constraint firstAttribute="centerX" secondItem="qkC-t0-Qd0" secondAttribute="centerX" multiplier="0.8" id="7iU-9D-miY"/>
|
||||
<constraint firstAttribute="bottom" secondItem="qkC-t0-Qd0" secondAttribute="bottom" constant="10" id="DyR-rX-nt0"/>
|
||||
<constraint firstAttribute="bottom" secondItem="Ump-1C-SzI" secondAttribute="bottom" constant="10" id="Nfo-nh-gvW"/>
|
||||
<constraint firstItem="3Vk-Jx-L6Y" firstAttribute="top" secondItem="8VI-1E-fge" secondAttribute="top" constant="10" id="Oi3-Zq-HKf"/>
|
||||
<constraint firstAttribute="bottom" secondItem="L4h-aG-8UN" secondAttribute="bottom" constant="10" id="Owt-zM-W2X"/>
|
||||
<constraint firstItem="3Vk-Jx-L6Y" firstAttribute="leading" secondItem="8VI-1E-fge" secondAttribute="leading" constant="10" id="Tqb-eF-AIh"/>
|
||||
<constraint firstAttribute="centerX" secondItem="Ump-1C-SzI" secondAttribute="centerX" multiplier="4" id="YMC-ob-tqT"/>
|
||||
<constraint firstAttribute="bottom" secondItem="IdO-jn-iTV" secondAttribute="bottom" constant="10" id="YcV-iN-9WU"/>
|
||||
<constraint firstAttribute="trailing" secondItem="3Vk-Jx-L6Y" secondAttribute="trailing" constant="10" id="ZbI-rp-TR9"/>
|
||||
<constraint firstAttribute="centerX" secondItem="L4h-aG-8UN" secondAttribute="centerX" multiplier="0.57" id="g1v-Mg-fQ6"/>
|
||||
<constraint firstAttribute="centerX" secondItem="IdO-jn-iTV" secondAttribute="centerX" multiplier="0.57" id="gAm-ph-zPW"/>
|
||||
</constraints>
|
||||
<nil key="simulatedStatusBarMetrics"/>
|
||||
<nil key="simulatedTopBarMetrics"/>
|
||||
<nil key="simulatedBottomBarMetrics"/>
|
||||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<connections>
|
||||
<outlet property="blockButton" destination="IdO-jn-iTV" id="HI0-ZU-esJ"/>
|
||||
<outlet property="cancelButton" destination="Ump-1C-SzI" id="U8M-nT-JiK"/>
|
||||
<outlet property="confirmVerifyButton" destination="L4h-aG-8UN" id="GX6-dB-JG6"/>
|
||||
<outlet property="textView" destination="3Vk-Jx-L6Y" id="uOw-Bq-neN"/>
|
||||
<outlet property="verifyButton" destination="qkC-t0-Qd0" id="6LD-04-WgO"/>
|
||||
</connections>
|
||||
</view>
|
||||
</objects>
|
||||
</document>
|
||||
Reference in New Issue
Block a user