From 2beaf5db15393dbbe3aa53e32427878918a191be Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Tue, 4 Dec 2018 12:50:21 +0100 Subject: [PATCH] create a chatroom with new configuration if it is an encryptrd chatroom --- Classes/CallView.m | 3 ++- Classes/ChatConversationCreateTableView.h | 1 + Classes/ChatConversationCreateTableView.m | 2 +- Classes/ChatConversationCreateView.h | 1 + Classes/ChatConversationCreateView.m | 17 +++++++++++------ Classes/ChatConversationInfoView.h | 1 + Classes/ChatConversationInfoView.m | 2 +- Classes/HistoryDetailsView.m | 3 ++- Classes/LinphoneUI/UIContactDetailsCell.m | 3 ++- Classes/PhoneMainView.h | 4 ++-- Classes/PhoneMainView.m | 9 +++++---- 11 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Classes/CallView.m b/Classes/CallView.m index ec17e91bd..2d49be1b7 100644 --- a/Classes/CallView.m +++ b/Classes/CallView.m @@ -753,7 +753,8 @@ static void hideSpinner(LinphoneCall *call, void *user_data) { - (IBAction)onChatClick:(id)sender { const LinphoneCall *currentCall = linphone_core_get_current_call(LC); const LinphoneAddress *addr = currentCall ? linphone_call_get_remote_address(currentCall) : NULL; - [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView]; + // TODO encrpted or unencrpted + [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView isEncrypted:TRUE]; } - (IBAction)onRecordClick:(id)sender { diff --git a/Classes/ChatConversationCreateTableView.h b/Classes/ChatConversationCreateTableView.h index a7dcdb6ad..cc6cc0349 100644 --- a/Classes/ChatConversationCreateTableView.h +++ b/Classes/ChatConversationCreateTableView.h @@ -21,6 +21,7 @@ @property(nonatomic) Boolean isForEditing; @property(nonatomic) Boolean isGroupChat; +@property(nonatomic) Boolean isEncrypted; - (void) loadData; @end diff --git a/Classes/ChatConversationCreateTableView.m b/Classes/ChatConversationCreateTableView.m index ffae06e0b..63b0958cc 100644 --- a/Classes/ChatConversationCreateTableView.m +++ b/Classes/ChatConversationCreateTableView.m @@ -149,7 +149,7 @@ bctbx_list_t *addresses = NULL; LinphoneAddress *addr = linphone_address_new(cell.addressLabel.text.UTF8String); addresses = bctbx_list_append(addresses, addr); - [PhoneMainView.instance createChatRoomWithSubject:NULL addresses:addresses andWaitView:NULL]; + [PhoneMainView.instance createChatRoomWithSubject:NULL addresses:addresses andWaitView:NULL isEncrypted:_isEncrypted]; linphone_address_unref(addr); return; } diff --git a/Classes/ChatConversationCreateView.h b/Classes/ChatConversationCreateView.h index 7db983db9..d5f6029a6 100644 --- a/Classes/ChatConversationCreateView.h +++ b/Classes/ChatConversationCreateView.h @@ -32,6 +32,7 @@ @property(nonatomic) Boolean isForEditing; @property(nonatomic) Boolean isGroupChat; +@property(nonatomic) Boolean isEncrypted; - (IBAction)onBackClick:(id)sender; - (IBAction)onNextClick:(id)sender; diff --git a/Classes/ChatConversationCreateView.m b/Classes/ChatConversationCreateView.m index 0e66ba73e..09c500132 100644 --- a/Classes/ChatConversationCreateView.m +++ b/Classes/ChatConversationCreateView.m @@ -50,6 +50,7 @@ static UICompositeViewDescription *compositeDescription = nil; _tableController.collectionView = _collectionView; _tableController.controllerNextButton = _nextButton; _isForEditing = FALSE; + _isEncrypted = TRUE; } - (void)viewWillAppear:(BOOL)animated { @@ -86,6 +87,7 @@ static UICompositeViewDescription *compositeDescription = nil; [_collectionView reloadData]; _tableController.isForEditing = _isForEditing; _tableController.isGroupChat = _isGroupChat; + _tableController.isEncrypted = _isEncrypted; [self changeView:ContactsLinphone]; } @@ -94,7 +96,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)createChatRoom { NSString *addr = _tableController.contactsGroup[0]; LinphoneAddress *remoteAddress = linphone_address_new(addr.UTF8String); - [PhoneMainView.instance getOrCreateOneToOneChatRoom:remoteAddress waitView:_waitView]; + [PhoneMainView.instance getOrCreateOneToOneChatRoom:remoteAddress waitView:_waitView isEncrypted:_isEncrypted]; linphone_address_unref(remoteAddress); } @@ -117,20 +119,23 @@ static UICompositeViewDescription *compositeDescription = nil; ChatConversationInfoView *view = VIEW(ChatConversationInfoView); view.contacts = _tableController.contactsGroup; view.create = !_isForEditing; + view.encrypted = _isEncrypted; [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; } - (IBAction)onChiffreClick:(id)sender { CGRect frame = _chiffreButton.frame; + _isEncrypted = !_isEncrypted; + _tableController.isEncrypted = _isEncrypted; // TODO show encrypted contacts - if (frame.origin.x > 10) { + if (_isEncrypted) { // encrypted - frame.origin.x = 2; - [_chiffreImage setImage:[UIImage imageNamed:@"security_toogle_background_grey.png"]]; - } else { - // no encrypted frame.origin.x = 20; [_chiffreImage setImage:[UIImage imageNamed:@"security_toogle_background_green.png"]]; + } else { + // no encrypted + frame.origin.x = 2; + [_chiffreImage setImage:[UIImage imageNamed:@"security_toogle_background_grey.png"]]; } _chiffreButton.frame = frame; } diff --git a/Classes/ChatConversationInfoView.h b/Classes/ChatConversationInfoView.h index cf7951acd..962157c0e 100644 --- a/Classes/ChatConversationInfoView.h +++ b/Classes/ChatConversationInfoView.h @@ -14,6 +14,7 @@ @property(nonatomic) BOOL create; @property(nonatomic) BOOL imAdmin; +@property(nonatomic) BOOL encrypted; @property(nonatomic, strong) NSMutableArray *contacts; @property(nonatomic, strong) NSMutableArray *admins; @property(nonatomic, strong) NSMutableArray *oldContacts; diff --git a/Classes/ChatConversationInfoView.m b/Classes/ChatConversationInfoView.m index eab13591f..db390de42 100644 --- a/Classes/ChatConversationInfoView.m +++ b/Classes/ChatConversationInfoView.m @@ -142,7 +142,7 @@ static UICompositeViewDescription *compositeDescription = nil; } addresses = bctbx_list_append(addresses, (void *)linphoneAddress); } - [PhoneMainView.instance createChatRoomWithSubject:_nameLabel.text.UTF8String addresses:addresses andWaitView:_waitView]; + [PhoneMainView.instance createChatRoomWithSubject:_nameLabel.text.UTF8String addresses:addresses andWaitView:_waitView isEncrypted:_encrypted]; bctbx_list_free_with_data(addresses, (void (*)(void *))linphone_address_unref); } diff --git a/Classes/HistoryDetailsView.m b/Classes/HistoryDetailsView.m index cf99cf01c..c0cffe96f 100644 --- a/Classes/HistoryDetailsView.m +++ b/Classes/HistoryDetailsView.m @@ -195,7 +195,8 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onChatClick:(id)event { const LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog); - [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView]; + // TODO one button for chatroom encrypted,another button for chatroom unencrypted + [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView isEncrypted:TRUE]; } @end diff --git a/Classes/LinphoneUI/UIContactDetailsCell.m b/Classes/LinphoneUI/UIContactDetailsCell.m index b5c3fe56b..3fbbe92ab 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.m +++ b/Classes/LinphoneUI/UIContactDetailsCell.m @@ -137,7 +137,8 @@ - (IBAction)onChatClick:(id)event { LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:_addressLabel.text]; - [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView]; + // TODO one button for chatroom encrypted,another button for chatroom unencrypted + [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView isEncrypted:TRUE]; linphone_address_destroy(addr); } diff --git a/Classes/PhoneMainView.h b/Classes/PhoneMainView.h index 9b54fdd67..be634db4e 100644 --- a/Classes/PhoneMainView.h +++ b/Classes/PhoneMainView.h @@ -112,8 +112,8 @@ - (BOOL)removeInhibitedEvent:(id)event; - (void)updateApplicationBadgeNumber; -- (void)getOrCreateOneToOneChatRoom:(const LinphoneAddress *)remoteAddress waitView:(UIView *)waitView; -- (void)createChatRoomWithSubject:(const char *)subject addresses:(bctbx_list_t *)addresses andWaitView:(UIView *)waitView; +- (void)getOrCreateOneToOneChatRoom:(const LinphoneAddress *)remoteAddress waitView:(UIView *)waitView isEncrypted:(BOOL)isEncrypted; +- (void)createChatRoomWithSubject:(const char *)subject addresses:(bctbx_list_t *)addresses andWaitView:(UIView *)waitView isEncrypted:(BOOL)isEncrypted; - (void)goToChatRoom:(LinphoneChatRoom *)cr; + (PhoneMainView*) instance; diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index ff7e27ac0..71626c396 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -859,7 +859,7 @@ static RootViewManager *rootViewManagerInstance = nil; #pragma mark - Chat room Functions -- (void)getOrCreateOneToOneChatRoom:(const LinphoneAddress *)remoteAddress waitView:(UIView *)waitView { +- (void)getOrCreateOneToOneChatRoom:(const LinphoneAddress *)remoteAddress waitView:(UIView *)waitView isEncrypted:(BOOL)isEncrypted{ if (!remoteAddress) { [self changeCurrentView:ChatsListView.compositeViewDescription]; return; @@ -869,7 +869,7 @@ static RootViewManager *rootViewManagerInstance = nil; LinphoneChatRoom *room = linphone_core_find_one_to_one_chat_room(LC, local, remoteAddress); if (!room) { bctbx_list_t *addresses = bctbx_list_new((void*)remoteAddress); - [self createChatRoomWithSubject:LINPHONE_DUMMY_SUBJECT addresses:addresses andWaitView:waitView]; + [self createChatRoomWithSubject:LINPHONE_DUMMY_SUBJECT addresses:addresses andWaitView:waitView isEncrypted:isEncrypted]; bctbx_list_free(addresses); return; } @@ -877,7 +877,7 @@ static RootViewManager *rootViewManagerInstance = nil; [self goToChatRoom:room]; } -- (void)createChatRoomWithSubject:(const char *)subject addresses:(bctbx_list_t *)addresses andWaitView:(UIView *)waitView { +- (void)createChatRoomWithSubject:(const char *)subject addresses:(bctbx_list_t *)addresses andWaitView:(UIView *)waitView isEncrypted:(BOOL)isEncrypted{ if (!linphone_proxy_config_get_conference_factory_uri(linphone_core_get_default_proxy_config(LC)) || ([[LinphoneManager instance] lpConfigBoolForKey:@"prefer_basic_chat_room" inSection:@"misc"] && bctbx_list_size(addresses) == 1)) { // If there's no factory uri, create a basic chat room @@ -902,7 +902,8 @@ static RootViewManager *rootViewManagerInstance = nil; _waitView = waitView; _waitView.hidden = NO; - LinphoneChatRoom *room = linphone_core_create_client_group_chat_room(LC, subject ?: LINPHONE_DUMMY_SUBJECT, bctbx_list_size(addresses) == 1); + // always use group chatroom + LinphoneChatRoom *room = linphone_core_create_client_group_chat_room_2(LC, subject ?: LINPHONE_DUMMY_SUBJECT, false, isEncrypted); if (!room) { _waitView.hidden = YES; return;