diff --git a/Classes/ChatConversationView.h b/Classes/ChatConversationView.h index 921b41a9b..6d6cd4834 100644 --- a/Classes/ChatConversationView.h +++ b/Classes/ChatConversationView.h @@ -28,6 +28,7 @@ #import "UIBackToCallButton.h" #import "Utils/HPGrowingTextView/HPGrowingTextView.h" #import "UIImageViewDeletable.h" +#import "UIConfirmationDialog.h" #include "linphone/linphonecore.h" @@ -37,6 +38,7 @@ OrderedDictionary *imageQualities; BOOL scrollOnGrowingEnabled; BOOL composingVisible; + UIConfirmationDialog *securityDialog; } @property(nonatomic) LinphoneChatRoom *chatRoom; diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 3c9a245b7..e5bfa4f42 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -37,6 +37,7 @@ static NSString* groupName = @"group.belledonne-communications.linphone"; scrollOnGrowingEnabled = TRUE; _chatRoom = NULL; _chatRoomCbs = NULL; + securityDialog = NULL; imageQualities = [[OrderedDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithFloat:0.9], NSLocalizedString(@"Maximum", nil), [NSNumber numberWithFloat:0.5], NSLocalizedString(@"Average", nil), @@ -572,10 +573,40 @@ static UICompositeViewDescription *compositeDescription = nil; } - (IBAction)onEncryptedDevicesClick:(id)sender { - DevicesListView *view = VIEW(DevicesListView); - view.room = _chatRoom; + BOOL isOneToOne = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesOneToOne; + NSString *message = NSLocalizedString(@"Instant messages are end-to-end encrypted in secured conversations. It is possible to upgrade the security level of a conversation by authenticating participants. To do so, call the contact and follow the authentification process.",nil); - [PhoneMainView.instance popToView:view.compositeViewDescription]; + if (isOneToOne) { + bctbx_list_t *participants = linphone_chat_room_get_participants(_chatRoom); + + LinphoneParticipant *firstParticipant = participants ? (LinphoneParticipant *)participants->data : NULL; + const LinphoneAddress *addr = firstParticipant ? linphone_participant_get_address(firstParticipant) : linphone_chat_room_get_peer_address(_chatRoom); + if (bctbx_list_size(linphone_participant_get_devices(firstParticipant)) == 1) { + if (securityDialog && securityDialog.notAskAgain) { + [LinphoneManager.instance doCall:addr]; + } else { + securityDialog = [UIConfirmationDialog ShowWithMessage:message cancelMessage:NSLocalizedString(@"CANCELL", nil) confirmMessage:NSLocalizedString(@"CALL", nil) onCancelClick:^() { + } onConfirmationClick:^() { + [LinphoneManager.instance doCall:addr]; + }]; + securityDialog.authView.hidden = FALSE; + } + return; + } + } + + if (securityDialog && securityDialog.notAskAgain) { + [self goToDeviceListView]; + } else { + securityDialog = [UIConfirmationDialog ShowWithMessage:message cancelMessage:NSLocalizedString(@"CANCELL", nil) confirmMessage:NSLocalizedString(@"OK", nil) onCancelClick:^() { + } onConfirmationClick:^() { + DevicesListView *view = VIEW(DevicesListView); + view.room = _chatRoom; + + [PhoneMainView.instance popToView:view.compositeViewDescription]; + }]; + securityDialog.authView.hidden = FALSE; + } } - (IBAction)onCallClick:(id)sender { @@ -937,6 +968,12 @@ void on_chat_room_conference_left(LinphoneChatRoom *cr, const LinphoneEventLog * [view.tableController scrollToBottom:true]; } +- (void)goToDeviceListView { + DevicesListView *view = VIEW(DevicesListView); + view.room = _chatRoom; + [PhoneMainView.instance popToView:view.compositeViewDescription]; +} + - (void)openFile:(NSString *) filePath { // Open the controller. diff --git a/Classes/DevicesListView.m b/Classes/DevicesListView.m index 0b5b274b2..a08552251 100644 --- a/Classes/DevicesListView.m +++ b/Classes/DevicesListView.m @@ -95,8 +95,7 @@ static UICompositeViewDescription *compositeDescription = nil; { if (!_isOneToOne) { DevicesMenuEntry *entry = [_devicesMenuEntries objectAtIndex:indexPath.row]; - return (entry->numberOfDevices + 1) * 56.0; - + return entry->numberOfDevices > 1 ? (entry->numberOfDevices + 1) * 56.0 : 56.0; } return 56.0; } @@ -129,8 +128,7 @@ static UICompositeViewDescription *compositeDescription = nil; [ContactDisplay setDisplayNameLabel:cell.addressLabel forAddress:linphone_participant_get_address(entry->participant)]; cell.devices = linphone_participant_get_devices(entry->participant); - UIImage *image = (entry->numberOfDevices != 0) ? [UIImage imageNamed:@"chevron_list_open"] : [UIImage imageNamed:@"chevron_list_close"]; - [cell.dropMenuButton setImage:image forState:UIControlStateNormal]; + [cell update:(entry->numberOfDevices != 0)]; return cell; } diff --git a/Classes/LinphoneUI/Base.lproj/UIConfirmationDialog.xib b/Classes/LinphoneUI/Base.lproj/UIConfirmationDialog.xib index 309f0201f..156520643 100644 --- a/Classes/LinphoneUI/Base.lproj/UIConfirmationDialog.xib +++ b/Classes/LinphoneUI/Base.lproj/UIConfirmationDialog.xib @@ -11,6 +11,8 @@ + + @@ -36,7 +38,7 @@ + + + + + + + + diff --git a/Classes/LinphoneUI/UIDevicesDetails.h b/Classes/LinphoneUI/UIDevicesDetails.h index fef26874e..5d45c268b 100644 --- a/Classes/LinphoneUI/UIDevicesDetails.h +++ b/Classes/LinphoneUI/UIDevicesDetails.h @@ -13,8 +13,11 @@ @property (weak, nonatomic) IBOutlet UILabel *addressLabel; @property (weak, nonatomic) IBOutlet UIRoundedImageView *avatarImage; @property (weak, nonatomic) IBOutlet UIImageView *securityImage; +@property (weak, nonatomic) IBOutlet UIButton *securityButton; @property (weak, nonatomic) IBOutlet UITableView *devicesTable; @property bctbx_list_t *devices; +- (IBAction)onSecurityCallClick:(id)sender; - (id)initWithIdentifier:(NSString *)identifier; +- (void)update:(BOOL)listOpen; @end diff --git a/Classes/LinphoneUI/UIDevicesDetails.m b/Classes/LinphoneUI/UIDevicesDetails.m index 1b529ab22..84964d56d 100644 --- a/Classes/LinphoneUI/UIDevicesDetails.m +++ b/Classes/LinphoneUI/UIDevicesDetails.m @@ -26,6 +26,24 @@ return self; } +- (void)update:(BOOL)listOpen { + if (bctbx_list_size(_devices) == 1) { + _securityButton.hidden = FALSE; + _dropMenuButton.hidden = TRUE; + } else { + UIImage *image = listOpen ? [UIImage imageNamed:@"chevron_list_open"] : [UIImage imageNamed:@"chevron_list_close"]; + [_dropMenuButton setImage:image forState:UIControlStateNormal]; + } +} + +- (IBAction)onSecurityCallClick:(id)sender { + LinphoneParticipantDevice *device = (LinphoneParticipantDevice *)bctbx_list_nth_data(_devices, 0); + const LinphoneAddress *addr = linphone_participant_device_get_address(device); + if (addr) + [LinphoneManager.instance doCall:addr]; + else + LOGE(@"CallKit : No call address"); +} #pragma mark - TableView diff --git a/Classes/LinphoneUI/UIDevicesDetails.xib b/Classes/LinphoneUI/UIDevicesDetails.xib index 49cd71cf4..165f8a872 100644 --- a/Classes/LinphoneUI/UIDevicesDetails.xib +++ b/Classes/LinphoneUI/UIDevicesDetails.xib @@ -16,6 +16,7 @@ + @@ -49,6 +50,14 @@ +