diff --git a/Classes/ChatConversationView.h b/Classes/ChatConversationView.h index cb600d244..b38d4b8f5 100644 --- a/Classes/ChatConversationView.h +++ b/Classes/ChatConversationView.h @@ -56,6 +56,7 @@ UIConfirmationDialog *securityDialog; UIRefreshControl *refreshControl; BOOL isOneToOne; + BOOL isEncrypted; } @property(nonatomic) LinphoneChatRoom *chatRoom; diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 3dff644d1..ab1bf2877 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -116,6 +116,7 @@ _chatRoomCbs = NULL; securityDialog = NULL; isOneToOne = TRUE; + isEncrypted = FALSE; imageQualities = [[OrderedDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithFloat:0.9], NSLocalizedString(@"Maximum", nil), [NSNumber numberWithFloat:0.5], NSLocalizedString(@"Average", nil), @@ -330,6 +331,7 @@ static UICompositeViewDescription *compositeDescription = nil; if (peerAddr) { _chatRoom = linphone_core_get_chat_room([LinphoneManager getLc], peerAddr); isOneToOne = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesOneToOne; + isEncrypted = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesEncrypted; } [self configureForRoom:true]; _backButton.hidden = _tableController.isEditing; @@ -407,10 +409,8 @@ static UICompositeViewDescription *compositeDescription = nil; [self update]; [self shareFile]; - if (![ChatConversationView isBasicChatRoom:_chatRoom]) { - [self setupPopupMenu]; - _ephemeralndicator.hidden = !linphone_chat_room_ephemeral_enabled(_chatRoom); - } + [self setupPopupMenu]; + _ephemeralndicator.hidden = !linphone_chat_room_ephemeral_enabled(_chatRoom); [self handlePendingTransferIfAny]; } @@ -422,6 +422,14 @@ static UICompositeViewDescription *compositeDescription = nil; return capabilities & LinphoneChatRoomCapabilitiesBasic; } +-(BOOL) isEncryptedChatRoom:(LinphoneChatRoom *)room { + if (!room) + return true; + LinphoneChatRoomCapabilitiesMask capabilities = linphone_chat_room_get_capabilities(room); + return capabilities & LinphoneChatRoomCapabilitiesBasic; +} + + - (void)configureMessageField { if (isOneToOne) { @@ -480,6 +488,7 @@ static UICompositeViewDescription *compositeDescription = nil; if (peerAddr) { _chatRoom = linphone_core_get_chat_room([LinphoneManager getLc], peerAddr); isOneToOne = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesOneToOne; + isEncrypted = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesEncrypted; } [self configureForRoom:self.editing]; if (_chatRoom && _markAsRead) { @@ -654,8 +663,7 @@ static UICompositeViewDescription *compositeDescription = nil; [_backToCallButton update]; _infoButton.hidden = (isOneToOne|| !_backToCallButton.hidden || _tableController.tableView.isEditing); _callButton.hidden = !_backToCallButton.hidden || !_infoButton.hidden || _tableController.tableView.isEditing; - _toggleMenuButton.hidden = [ChatConversationView isBasicChatRoom:_chatRoom] || _tableController.tableView.isEditing; - _tableController.editButton.hidden = _tableController.editButton.hidden || ![ChatConversationView isBasicChatRoom:_chatRoom]; + _toggleMenuButton.hidden = _tableController.isEditing; } - (void)updateParticipantLabel { @@ -814,16 +822,17 @@ static UICompositeViewDescription *compositeDescription = nil; LOGI(@"onDeleteClick"); NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"Do you want to delete the selected messages?", nil)]; [UIConfirmationDialog ShowWithMessage:msg - cancelMessage:nil - confirmMessage:nil - onCancelClick:^() { - [self onEditionChangeClick:nil]; - } - onConfirmationClick:^() { - [_tableController removeSelectionUsing:nil]; - [_tableController loadData]; - [self onEditionChangeClick:nil]; - }]; + cancelMessage:nil + confirmMessage:nil + onCancelClick:^() { + [self onEditionChangeClick:nil]; + } + onConfirmationClick:^() { + [_tableController removeSelectionUsing:nil]; + _tableController.editButton.hidden = true; + [_tableController loadData]; + [self onEditionChangeClick:nil]; + }]; } - (IBAction)onEditionChangeClick:(id)sender { @@ -870,7 +879,7 @@ static UICompositeViewDescription *compositeDescription = nil; } -- (IBAction)onInfoClick:(id)sender { +- (void)displayGroupInfo { NSMutableArray *contactsArray = [[NSMutableArray alloc] init]; NSMutableArray *admins = [[NSMutableArray alloc] init]; bctbx_list_t *participants = linphone_chat_room_get_participants(_chatRoom); @@ -897,6 +906,10 @@ static UICompositeViewDescription *compositeDescription = nil; [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; } +- (IBAction)onInfoClick:(id)sender { + [self displayGroupInfo]; +} + #pragma mark ChatRoomDelegate - (BOOL)startMultiFilesUpload:(LinphoneChatMessage *)rootMessage { @@ -1651,17 +1664,70 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog } // Popup menu +-(void) addOrGoToContact:(const LinphoneAddress *)contactAddress { + Contact *contact = [FastAddressBook getContactWithAddress:contactAddress]; + + if (contact) { + ContactDetailsView *view = VIEW(ContactDetailsView); + [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; + [ContactSelection setSelectionMode:ContactSelectionModeNone]; + [view setContact:contact]; + } else { + char *lAddress = linphone_address_as_string_uri_only(contactAddress); + if (lAddress != NULL) { + NSString *normSip = [NSString stringWithUTF8String:lAddress]; + normSip = [normSip hasPrefix:@"sip:"] ? [normSip substringFromIndex:4] : normSip; + normSip = [normSip hasPrefix:@"sips:"] ? [normSip substringFromIndex:5] : normSip; + [ContactSelection setAddAddress:normSip]; + [ContactSelection setSelectionMode:ContactSelectionModeEdit]; + [ContactSelection enableSipFilter:FALSE]; + [PhoneMainView.instance changeCurrentView:ContactsListView.compositeViewDescription]; + ms_free(lAddress); + } + } +} +-(BOOL) isConversationMuted { + return FALSE; // TODO +} +-(void) toggleMuteConversation { + // TODO +} --(BOOL) canAdminEphemeral:(LinphoneChatRoom *)cr { +-(void) showAddressAndIdentityPopup { + + char *localAddress = linphone_address_as_string(linphone_chat_room_get_local_address(_chatRoom)); + char *peerAddress = linphone_address_as_string(linphone_chat_room_get_peer_address(_chatRoom)); + NSString *infoMsg = [NSString stringWithFormat:@"Chat room id:\n%s\nLocal account:\n%s", peerAddress, localAddress]; + ms_free(localAddress); + ms_free(peerAddress); + + UIAlertController *popupView = + [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Chatroom debug infos", nil) + message:infoMsg + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Copy to clipboard", nil) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; + pasteboard.string = infoMsg; + }]; + + [popupView addAction:defaultAction]; + [self presentViewController:popupView animated:YES completion:nil]; + +} + +-(BOOL) canAdminEphemeral:(const LinphoneChatRoom *)cr { if (!cr) return FALSE; + if ([ChatConversationView isBasicChatRoom:_chatRoom]) return FALSE; // If ephemeral mode is DeviceManaged, then we don't need to check anything else return (linphone_chat_room_params_get_ephemeral_mode(linphone_chat_room_get_current_params(cr)) == LinphoneChatRoomEphemeralModeDeviceManaged) || ( linphone_chat_room_has_capability(cr, LinphoneChatRoomCapabilitiesEphemeral) && linphone_chat_room_params_get_ephemeral_mode(linphone_chat_room_get_current_params(cr)) == LinphoneChatRoomEphemeralModeAdminManaged && linphone_participant_is_admin(linphone_chat_room_get_me(cr))); } - - (void) setupPopupMenu { _popupMenu.dataSource = self; _popupMenu.delegate = self; @@ -1678,19 +1744,38 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self onToggleMenu:nil]; + BOOL isEncrypted = ![ChatConversationView isBasicChatRoom:_chatRoom]; + if (indexPath.row == 0) { + if (isOneToOne) { + [self addOrGoToContact:linphone_chat_room_get_peer_address(_chatRoom)]; + } else { + [self displayGroupInfo]; + } + } + + if (isEncrypted && indexPath.row == 1) { [self goToDeviceListView]; } - if (indexPath.row == 1) { + + BOOL canEphemeral = [self canAdminEphemeral:_chatRoom]; + if (canEphemeral && indexPath.row == 2) { + EphemeralSettingsView *view = VIEW(EphemeralSettingsView); + view.room = _chatRoom; + [PhoneMainView.instance popToView:view.compositeViewDescription]; + } + if ((!isEncrypted && indexPath.row == 1) || (isEncrypted && indexPath.row == 3)) { + [self toggleMuteConversation]; + } + + if ((!isEncrypted && indexPath.row == 2) || (isEncrypted && indexPath.row == 4)) { [_tableController onEditClick:nil]; [self onEditionChangeClick:nil]; } - if ([self canAdminEphemeral:_chatRoom]) { - if (indexPath.row == 2) { - EphemeralSettingsView *view = VIEW(EphemeralSettingsView); - view.room = _chatRoom; - [PhoneMainView.instance popToView:view.compositeViewDescription]; - } + + if ((isEncrypted && ((!canEphemeral && indexPath.row == 4)||(canEphemeral && indexPath.row == 5))) + || (!isEncrypted && indexPath.row == 3)) { + [self showAddressAndIdentityPopup]; } } @@ -1699,27 +1784,73 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return [self canAdminEphemeral:_chatRoom] ? 3 : 2; + int nbRows = 3; + + if ([LinphoneManager.instance lpConfigIntForKey:@"debugenable_preference"] == 1) // DEBOGUE == ALL + ++nbRows; + + if (!isEncrypted) + return nbRows; + else + ++nbRows; + + if ([self canAdminEphemeral:_chatRoom]) + ++nbRows; + + return nbRows; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [[UITableViewCell alloc] init]; if (indexPath.row == 0) { + if (isOneToOne) { + Contact *contact = [FastAddressBook getContactWithAddress:linphone_chat_room_get_peer_address(_chatRoom)]; + if (contact == nil) { + cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"contact_add_default.png"] newSize:CGSizeMake(20, 25)]; + cell.textLabel.text = NSLocalizedString(@"Add to contacts",nil); + } else { + cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"contacts_all_default.png"] newSize:CGSizeMake(20, 25)]; + cell.textLabel.text = NSLocalizedString(@"Go to contact",nil); + } + } else { + cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"chat_group_informations.png"] newSize:CGSizeMake(20, 25)]; + cell.textLabel.text = NSLocalizedString(@"Group infos",nil); + } + } + + if (isEncrypted && indexPath.row == 1) { cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"menu_security_default.png"] newSize:CGSizeMake(20, 25)]; cell.textLabel.text = NSLocalizedString(@"Conversation's devices",nil); } - if (indexPath.row == 1) { + + bool canEphemeral = [self canAdminEphemeral:_chatRoom]; + if (canEphemeral && indexPath.row == 2) { + cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"ephemeral_messages_default.png"] newSize:CGSizeMake(20, 25)]; + cell.textLabel.text = NSLocalizedString(@"Ephemeral messages",nil); + } + + if ((isEncrypted && indexPath.row == 3) || (!isEncrypted && indexPath.row == 1)) { + if ([self isConversationMuted]) { + cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"menu_notifications_off.png"] newSize:CGSizeMake(20, 25)]; + cell.textLabel.text = NSLocalizedString(@"NOT IMPLEMENTED",nil); + } else { + cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"menu_notifications_on.png"] newSize:CGSizeMake(20, 25)]; + cell.textLabel.text = NSLocalizedString(@"NOT IMPLEMENTED",nil); + } + } + + if ((isEncrypted && indexPath.row == 4) || (!isEncrypted && indexPath.row == 2)) { cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"delete_default.png"] newSize:CGSizeMake(20, 25)]; cell.textLabel.text = NSLocalizedString(@"Delete messages",nil); } - if ([self canAdminEphemeral:_chatRoom]) { - if (indexPath.row == 2) { - cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"ephemeral_messages_default.png"] newSize:CGSizeMake(20, 25)]; - cell.textLabel.text = NSLocalizedString(@"Ephemeral messages",nil); - } + if ((isEncrypted && ((!canEphemeral && indexPath.row == 4)||(canEphemeral && indexPath.row == 5))) + || (!isEncrypted && indexPath.row == 3)) { + cell.imageView.image = [LinphoneUtils resizeImage:[UIImage imageNamed:@"chat_group_informations.png"] newSize:CGSizeMake(20, 25)]; + cell.textLabel.text = NSLocalizedString(@"Show address and identity",nil); } + cell.imageView.contentMode = UIViewContentModeScaleAspectFit; return cell; } @@ -1729,9 +1860,7 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog [_popupMenu selectRowAtIndexPath:nil animated:false scrollPosition:UITableViewScrollPositionNone]; } - -// Voice redcording - +// Voice recording - (IBAction)onVrDelete:(id)sender { [self cancelVoiceRecording]; diff --git a/Resources/images/menu_notifications_off.png b/Resources/images/menu_notifications_off.png new file mode 100644 index 000000000..556e26a8b Binary files /dev/null and b/Resources/images/menu_notifications_off.png differ diff --git a/Resources/images/menu_notifications_on.png b/Resources/images/menu_notifications_on.png new file mode 100644 index 000000000..d9fa816ad Binary files /dev/null and b/Resources/images/menu_notifications_on.png differ diff --git a/Resources/images/more_menu_default.png b/Resources/images/more_menu_default.png index aa544d0ed..b4e2ff3bf 100644 Binary files a/Resources/images/more_menu_default.png and b/Resources/images/more_menu_default.png differ diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index bf4006977..ad0ea7056 100644 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -632,6 +632,8 @@ 669B140827A1821F0012220A /* scroll_to_bottom_default.png in Resources */ = {isa = PBXBuildFile; fileRef = 669B140727A1821F0012220A /* scroll_to_bottom_default.png */; }; 669B140C27A29D140012220A /* FloatingScrollDownButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 669B140B27A29D140012220A /* FloatingScrollDownButton.swift */; }; 6F3A2542B1FC7C128439D37C /* Pods_linphone.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CFCC14A580A05DEC78090273 /* Pods_linphone.framework */; }; + 66E399F72857869300E73456 /* menu_notifications_off.png in Resources */ = {isa = PBXBuildFile; fileRef = 66E399F52857869200E73456 /* menu_notifications_off.png */; }; + 66E399F82857869300E73456 /* menu_notifications_on.png in Resources */ = {isa = PBXBuildFile; fileRef = 66E399F62857869200E73456 /* menu_notifications_on.png */; }; 70E542F313E147E3002BA2C0 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 70E542F213E147E3002BA2C0 /* OpenGLES.framework */; }; 70E542F513E147EB002BA2C0 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 70E542F413E147EB002BA2C0 /* QuartzCore.framework */; }; 8C1B67061E671826001EA2FE /* AudioHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C1B67051E671826001EA2FE /* AudioHelper.m */; }; @@ -1624,6 +1626,8 @@ 666D795C283E67E300B07215 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = ""; }; 669B140727A1821F0012220A /* scroll_to_bottom_default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = scroll_to_bottom_default.png; sourceTree = ""; }; 669B140B27A29D140012220A /* FloatingScrollDownButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloatingScrollDownButton.swift; sourceTree = ""; }; + 66E399F52857869200E73456 /* menu_notifications_off.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = menu_notifications_off.png; sourceTree = ""; }; + 66E399F62857869200E73456 /* menu_notifications_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = menu_notifications_on.png; sourceTree = ""; }; 70E542F213E147E3002BA2C0 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; 70E542F413E147EB002BA2C0 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 87F00D1935382CCA03DF2F02 /* Pods-linphone.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-linphone.debug.xcconfig"; path = "Target Support Files/Pods-linphone/Pods-linphone.debug.xcconfig"; sourceTree = ""; }; @@ -2752,6 +2756,8 @@ 61586B86217A17150038AC45 /* menu_assistant@2x.png */, 61586B88217A17220038AC45 /* menu_link_account.png */, 61586B8A217A17320038AC45 /* menu_link_account@2x.png */, + 66E399F52857869200E73456 /* menu_notifications_off.png */, + 66E399F62857869200E73456 /* menu_notifications_on.png */, 61586B8C217A173F0038AC45 /* menu_options.png */, 61586B8E217A174F0038AC45 /* menu_options@2x.png */, 61586B90217A175C0038AC45 /* menu_recordings.png */, @@ -3947,6 +3953,7 @@ 633FEE1C1D3CD5590014B822 /* chat_start_body_default~ipad.png in Resources */, 633FEE011D3CD5590014B822 /* camera_switch_over@2x.png in Resources */, 633FEEA01D3CD55A0014B822 /* numpad_0_over~ipad@2x.png in Resources */, + 66E399F72857869300E73456 /* menu_notifications_off.png in Resources */, 633FEF3E1D3CD55A0014B822 /* security_pending.png in Resources */, D381881915FE3FCA00C3EDCA /* CallView.xib in Resources */, 633FEE7E1D3CD5590014B822 /* history_missed_selected.png in Resources */, @@ -3994,6 +4001,7 @@ 633FEE911D3CD55A0014B822 /* list_details_over@2x.png in Resources */, 633FEE121D3CD5590014B822 /* chat_message_not_delivered.png in Resources */, 633FEDCE1D3CD5590014B822 /* call_quality_indicator_1.png in Resources */, + 66E399F82857869300E73456 /* menu_notifications_on.png in Resources */, 8CB2B8F91F86229E0015CEE2 /* chat_secure.png in Resources */, 633FEF4E1D3CD55A0014B822 /* valid_default.png in Resources */, 570742581D5A0691004B9C84 /* ShopView.xib in Resources */,