mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-02 14:16:59 +02:00
EncryptionInfoView: Trigger a server request to get information on unknown devices
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
#import "EncryptionInfoView.h"
|
||||
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "VectorDesignValues.h"
|
||||
|
||||
static NSAttributedString *verticalWhitespace = nil;
|
||||
@@ -37,6 +39,11 @@ static NSAttributedString *verticalWhitespace = nil;
|
||||
*/
|
||||
MXDeviceInfo *deviceInfo;
|
||||
|
||||
/**
|
||||
Current request in progress.
|
||||
*/
|
||||
MXHTTPOperation *mxCurrentOperation;
|
||||
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -54,6 +61,17 @@ static NSAttributedString *verticalWhitespace = nil;
|
||||
[_confirmVerifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_verify_ok", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
}
|
||||
|
||||
- (void)removeFromSuperview
|
||||
{
|
||||
if (mxCurrentOperation)
|
||||
{
|
||||
[mxCurrentOperation cancel];
|
||||
mxCurrentOperation = nil;
|
||||
}
|
||||
|
||||
[super removeFromSuperview];
|
||||
}
|
||||
|
||||
- (instancetype)initWithEvent:(MXEvent*)event andMatrixSession:(MXSession*)session
|
||||
{
|
||||
NSArray *nibViews = [[NSBundle bundleForClass:[EncryptionInfoView class]] loadNibNamed:NSStringFromClass([EncryptionInfoView class])
|
||||
@@ -67,242 +85,7 @@ static NSAttributedString *verticalWhitespace = nil;
|
||||
|
||||
[self setTranslatesAutoresizingMaskIntoConstraints: NO];
|
||||
|
||||
if (mxEvent)
|
||||
{
|
||||
MXRoom *mxRoom = [mxSession roomWithRoomId:mxEvent.roomId];
|
||||
|
||||
if (mxRoom)
|
||||
{
|
||||
deviceInfo = [mxRoom eventDeviceInfo:mxEvent];
|
||||
}
|
||||
|
||||
// Prepare text view content
|
||||
NSMutableAttributedString *textViewAttributedString = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_title", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:17]}];
|
||||
// Event information
|
||||
NSMutableAttributedString *eventInformationString = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:15]}];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
NSString *senderId = event.sender;
|
||||
NSString *senderKey = event.senderKey;
|
||||
NSString *claimedKey = event.keysClaimed[@"ed25519"];
|
||||
NSString *algorithm = event.wireContent[@"algorithm"];
|
||||
NSString *sessionId = event.wireContent[@"session_id"];
|
||||
|
||||
NSString *decryptionError;
|
||||
if (event.decryptionError)
|
||||
{
|
||||
decryptionError = [NSString stringWithFormat:@"** %@ **", event.decryptionError.localizedDescription];
|
||||
}
|
||||
|
||||
if (!senderKey.length)
|
||||
{
|
||||
senderKey = NSLocalizedStringFromTable(@"room_event_encryption_info_event_none", @"Vector", nil);
|
||||
}
|
||||
if (!claimedKey.length)
|
||||
{
|
||||
claimedKey = NSLocalizedStringFromTable(@"room_event_encryption_info_event_none", @"Vector", nil);
|
||||
}
|
||||
if (!algorithm.length)
|
||||
{
|
||||
algorithm = NSLocalizedStringFromTable(@"room_event_encryption_info_event_unencrypted", @"Vector", nil);
|
||||
}
|
||||
if (!sessionId.length)
|
||||
{
|
||||
sessionId = NSLocalizedStringFromTable(@"room_event_encryption_info_event_none", @"Vector", nil);
|
||||
}
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_user_id", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:senderId
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_identity_key", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:senderKey
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_fingerprint_key", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:claimedKey
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_algorithm", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:algorithm
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
if (decryptionError.length)
|
||||
{
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_decryption_error", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:decryptionError
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
}
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_session_id", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:sessionId
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[textViewAttributedString appendAttributedString:eventInformationString];
|
||||
|
||||
|
||||
|
||||
// Device information
|
||||
NSMutableAttributedString *deviceInformationString = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:15]}];
|
||||
[deviceInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
if (deviceInfo)
|
||||
{
|
||||
NSString *name = deviceInfo.displayName;
|
||||
NSString *deviceId = deviceInfo.deviceId;
|
||||
NSMutableAttributedString *verification;
|
||||
NSString *fingerprint = deviceInfo.fingerprint;
|
||||
|
||||
// Display here the Verify and Block buttons except if the device is the current one.
|
||||
_verifyButton.hidden = _blockButton.hidden = [deviceInfo.deviceId isEqualToString:mxSession.matrixRestClient.credentials.deviceId];
|
||||
|
||||
switch (deviceInfo.verified)
|
||||
{
|
||||
case MXDeviceUnverified:
|
||||
{
|
||||
verification = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_not_verified", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}];
|
||||
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_verify", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_verify", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_block", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_block", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
break;
|
||||
}
|
||||
case MXDeviceVerified:
|
||||
{
|
||||
verification = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_verified", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}];
|
||||
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_unverify", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_unverify", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_block", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_block", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
|
||||
break;
|
||||
}
|
||||
case MXDeviceBlocked:
|
||||
{
|
||||
verification = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_blocked", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}];
|
||||
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_verify", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_verify", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_unblock", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_unblock", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_name", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:(name.length ? name : @"")
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_id", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:deviceId
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_verification", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:verification];
|
||||
[deviceInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_fingerprint", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:fingerprint
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unknown device
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_unknown", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont italicSystemFontOfSize:14]}]];
|
||||
}
|
||||
|
||||
|
||||
[textViewAttributedString appendAttributedString:deviceInformationString];
|
||||
|
||||
self.textView.attributedText = textViewAttributedString;
|
||||
}
|
||||
else
|
||||
{
|
||||
_textView.text = nil;
|
||||
}
|
||||
[self updateTextViewText];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -314,6 +97,268 @@ static NSAttributedString *verticalWhitespace = nil;
|
||||
mxSession = nil;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)updateTextViewText
|
||||
{
|
||||
if (mxEvent)
|
||||
{
|
||||
MXRoom *mxRoom = [mxSession roomWithRoomId:mxEvent.roomId];
|
||||
|
||||
if (mxRoom)
|
||||
{
|
||||
deviceInfo = [mxRoom eventDeviceInfo:mxEvent];
|
||||
}
|
||||
|
||||
// Prepare text view content
|
||||
NSMutableAttributedString *textViewAttributedString = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_title", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:17]}];
|
||||
// Event information
|
||||
NSMutableAttributedString *eventInformationString = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:15]}];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
NSString *senderId = mxEvent.sender;
|
||||
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 = NSLocalizedStringFromTable(@"room_event_encryption_info_event_none", @"Vector", nil);
|
||||
}
|
||||
if (!claimedKey.length)
|
||||
{
|
||||
claimedKey = NSLocalizedStringFromTable(@"room_event_encryption_info_event_none", @"Vector", nil);
|
||||
}
|
||||
if (!algorithm.length)
|
||||
{
|
||||
algorithm = NSLocalizedStringFromTable(@"room_event_encryption_info_event_unencrypted", @"Vector", nil);
|
||||
}
|
||||
if (!sessionId.length)
|
||||
{
|
||||
sessionId = NSLocalizedStringFromTable(@"room_event_encryption_info_event_none", @"Vector", nil);
|
||||
}
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_user_id", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:senderId
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_identity_key", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:senderKey
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_fingerprint_key", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:claimedKey
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_algorithm", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:algorithm
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
if (decryptionError.length)
|
||||
{
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_decryption_error", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:decryptionError
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
}
|
||||
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_event_session_id", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:sessionId
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[eventInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[textViewAttributedString appendAttributedString:eventInformationString];
|
||||
|
||||
|
||||
|
||||
// Device information
|
||||
NSMutableAttributedString *deviceInformationString = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:15]}];
|
||||
[deviceInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
if (deviceInfo)
|
||||
{
|
||||
NSString *name = deviceInfo.displayName;
|
||||
NSString *deviceId = deviceInfo.deviceId;
|
||||
NSMutableAttributedString *verification;
|
||||
NSString *fingerprint = deviceInfo.fingerprint;
|
||||
|
||||
// Display here the Verify and Block buttons except if the device is the current one.
|
||||
_verifyButton.hidden = _blockButton.hidden = [deviceInfo.deviceId isEqualToString:mxSession.matrixRestClient.credentials.deviceId];
|
||||
|
||||
switch (deviceInfo.verified)
|
||||
{
|
||||
case MXDeviceUnverified:
|
||||
{
|
||||
verification = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_not_verified", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}];
|
||||
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_verify", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_verify", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_block", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_block", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
break;
|
||||
}
|
||||
case MXDeviceVerified:
|
||||
{
|
||||
verification = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_verified", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}];
|
||||
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_unverify", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_unverify", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_block", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_block", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
|
||||
break;
|
||||
}
|
||||
case MXDeviceBlocked:
|
||||
{
|
||||
verification = [[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_blocked", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}];
|
||||
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_verify", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_verifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_verify", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_unblock", @"Vector", nil) forState:UIControlStateNormal];
|
||||
[_blockButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_info_unblock", @"Vector", nil) forState:UIControlStateHighlighted];
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_name", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:(name.length ? name : @"")
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_id", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:deviceId
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_verification", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:verification];
|
||||
[deviceInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_fingerprint", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont boldSystemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:fingerprint
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont systemFontOfSize:14]}]];
|
||||
[deviceInformationString appendAttributedString:[EncryptionInfoView verticalWhitespace]];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unknown device
|
||||
[deviceInformationString appendAttributedString:[[NSMutableAttributedString alloc]
|
||||
initWithString:NSLocalizedStringFromTable(@"room_event_encryption_info_device_unknown", @"Vector", nil)
|
||||
attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack,
|
||||
NSFontAttributeName: [UIFont italicSystemFontOfSize:14]}]];
|
||||
|
||||
// Trigger a server request to get the device information for the event sender
|
||||
mxCurrentOperation = [mxSession.crypto downloadKeys:@[senderId] forceDownload:YES success:^(MXUsersDevicesMap<MXDeviceInfo *> *usersDevicesInfoMap) {
|
||||
|
||||
mxCurrentOperation = nil;
|
||||
|
||||
// Sanity check: check whether some device information has been retrieved.
|
||||
if (usersDevicesInfoMap.map.count)
|
||||
{
|
||||
[self updateTextViewText];
|
||||
}
|
||||
|
||||
} failure:^(NSError *error) {
|
||||
|
||||
mxCurrentOperation = nil;
|
||||
|
||||
NSLog(@"[EncryptionInfoView] Crypto failed to download device info for user: %@", mxEvent.sender);
|
||||
|
||||
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
[textViewAttributedString appendAttributedString:deviceInformationString];
|
||||
|
||||
self.textView.attributedText = textViewAttributedString;
|
||||
}
|
||||
else
|
||||
{
|
||||
_textView.text = nil;
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSAttributedString *)verticalWhitespace
|
||||
{
|
||||
if (verticalWhitespace == nil)
|
||||
|
||||
Reference in New Issue
Block a user