IdentityVerifiedViewController.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2012-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import <QuartzCore/QuartzCore.h>
  21. #import "IdentityVerifiedViewController.h"
  22. #import "Contact.h"
  23. #import "CryptoUtils.h"
  24. #import "AvatarMaker.h"
  25. #import "BundleUtil.h"
  26. #import "FeatureMask.h"
  27. #import "ServerConnector.h"
  28. #import "Threema-Swift.h"
  29. #import "UIDefines.h"
  30. @interface IdentityVerifiedViewController ()
  31. @end
  32. @implementation IdentityVerifiedViewController
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. self.contactImage.contentMode = UIViewContentModeScaleAspectFill;
  36. self.contactImage.layer.cornerRadius = self.contactImage.frame.size.width/2;
  37. self.contactImage.layer.masksToBounds = YES;
  38. _threemaTypeIcon.image = [Utils threemaTypeIcon];
  39. [self setupColors];
  40. }
  41. - (void)setupColors {
  42. [_nameLabel setTextColor:[Colors fontNormal]];
  43. _nameLabel.shadowColor = nil;
  44. if (@available(iOS 11.0, *)) {
  45. _contactImage.accessibilityIgnoresInvertColors = true;
  46. _threemaTypeIcon.accessibilityIgnoresInvertColors = true;
  47. }
  48. }
  49. - (void)viewWillAppear:(BOOL)animated {
  50. [super viewWillAppear:animated];
  51. [self updateView];
  52. }
  53. - (void)viewWillLayoutSubviews {
  54. [super viewWillLayoutSubviews];
  55. UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleTitle3];
  56. CGFloat size = fontDescriptor.pointSize;
  57. _nameLabel.font = [UIFont boldSystemFontOfSize:size];
  58. }
  59. - (BOOL)shouldAutorotate {
  60. return YES;
  61. }
  62. -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
  63. if (SYSTEM_IS_IPAD) {
  64. return UIInterfaceOrientationMaskAll;
  65. }
  66. return UIInterfaceOrientationMaskAllButUpsideDown;
  67. }
  68. - (void)updateView {
  69. self.sendMessageLabel.text = [BundleUtil localizedStringForKey:@"send_message"];
  70. self.threemaCallLabel.text = [BundleUtil localizedStringForKey:@"call_voip_not_supported_title"];
  71. self.title = self.contact.displayName;
  72. self.nameLabel.text = self.contact.displayName;
  73. self.contactImage.image = [[AvatarMaker sharedAvatarMaker] avatarForContact:self.contact size:self.contactImage.frame.size.width masked:NO];
  74. _threemaTypeIcon.hidden = [Utils hideThreemaTypeIconForContact:self.contact];
  75. self.identityLabel.text = self.contact.identity;
  76. self.keyFingerprintCell.fingerprintValueLabel.text = [CryptoUtils fingerprintForPublicKey:self.contact.publicKey];
  77. self.verificationLevelCell.contact = self.contact;
  78. if (self.contact.isWorkContact == true) {
  79. _verificationLevelImage.image = StyleKit.verificationBig4;
  80. } else {
  81. _verificationLevelImage.image = StyleKit.verificationBig2;
  82. }
  83. if (self.contact.isGatewayId || !is64Bit) {
  84. self.threemaCallCell.hidden = YES;
  85. }
  86. }
  87. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  88. if (indexPath.section == 1) {
  89. [Colors updateTableViewCellBackground:cell];
  90. [Colors setTextColor:[Colors main] inView:cell.contentView];
  91. } else {
  92. [Colors updateTableViewCell:cell];
  93. }
  94. }
  95. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  96. UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:indexPath];
  97. if (selectedCell == self.sendMessageCell) {
  98. [self dismissViewControllerAnimated:YES completion:^{
  99. NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys: self.contact, kKeyContact, [NSNumber numberWithBool:YES], kKeyForceCompose, nil];
  100. [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationShowConversation object:nil userInfo:info];
  101. }];
  102. }
  103. else if (selectedCell == self.threemaCallCell) {
  104. [self dismissViewControllerAnimated:YES completion:^{
  105. NSInteger state = [[VoIPCallStateManager shared] currentCallState];
  106. if (state == CallStateIdle) {
  107. [FeatureMask checkFeatureMask:FEATURE_MASK_VOIP forContacts:[NSSet setWithObjects:self.contact, nil] onCompletion:^(NSArray *unsupportedContacts) {
  108. if (unsupportedContacts.count == 0) {
  109. [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
  110. if ([ServerConnector sharedServerConnector].connectionState == ConnectionStateLoggedIn) {
  111. VoIPCallUserAction *action = [[VoIPCallUserAction alloc] initWithAction:ActionCall contact:self.contact callId:nil completion:nil];
  112. [[VoIPCallStateManager shared] processUserAction:action];
  113. } else {
  114. // Alert no internet connection
  115. NSString *title = NSLocalizedString(@"cannot_connect_title", nil);
  116. NSString *message = NSLocalizedString(@"cannot_connect_message", nil);
  117. [UIAlertTemplate showAlertWithOwner:self title:title message:message actionOk:^(UIAlertAction * _Nonnull okAction) {
  118. [self.extensionContext completeRequestReturningItems:@[] completionHandler:^(BOOL expired) {
  119. }];
  120. }];
  121. }
  122. } else {
  123. [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
  124. [UIAlertTemplate showAlertWithOwner:self title:NSLocalizedString(@"call_voip_not_supported_title", nil) message:NSLocalizedString(@"call_voip_not_supported_text", nil) actionOk:nil];
  125. }
  126. }];
  127. } else {
  128. [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
  129. }
  130. }];
  131. }
  132. }
  133. - (IBAction)done:(id)sender {
  134. [self dismissViewControllerAnimated:YES completion:nil];
  135. }
  136. @end