From 38c389bf64a495c262cf1dc930175225ee38fbe8 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Wed, 2 Jan 2019 14:45:45 +0100 Subject: [PATCH] new ContactDetailView : enable the creation of an encrypted chatroom if it has the ability of lime --- .../Base.lproj/UIContactDetailsCell.xib | 84 +++++++++++++------ Classes/LinphoneUI/UIContactDetailsCell.h | 3 + Classes/LinphoneUI/UIContactDetailsCell.m | 28 +++++-- Classes/PhoneMainView.m | 2 +- Resources/linphonerc-factory | 4 +- 5 files changed, 87 insertions(+), 34 deletions(-) diff --git a/Classes/LinphoneUI/Base.lproj/UIContactDetailsCell.xib b/Classes/LinphoneUI/Base.lproj/UIContactDetailsCell.xib index 62db03089..d50e7c765 100644 --- a/Classes/LinphoneUI/Base.lproj/UIContactDetailsCell.xib +++ b/Classes/LinphoneUI/Base.lproj/UIContactDetailsCell.xib @@ -18,8 +18,10 @@ + + @@ -59,32 +61,6 @@ - - @@ -127,5 +158,6 @@ + diff --git a/Classes/LinphoneUI/UIContactDetailsCell.h b/Classes/LinphoneUI/UIContactDetailsCell.h index 5d340efcf..ec5da8d20 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.h +++ b/Classes/LinphoneUI/UIContactDetailsCell.h @@ -38,6 +38,8 @@ @property (weak, nonatomic) IBOutlet UIImageView *linphoneImage; @property (weak, nonatomic) UIView *waitView; @property (strong, nonatomic) IBOutlet UIButton *inviteButton; +@property (weak, nonatomic) IBOutlet UIView *encryptedChatView; +@property (weak, nonatomic) IBOutlet UIView *optionsView; - (id)initWithIdentifier:(NSString *)identifier; - (void)setAddress:(NSString *)address; @@ -46,6 +48,7 @@ - (IBAction)onCallClick:(id)sender; - (IBAction)onChatClick:(id)sender; +- (IBAction)onEncrptedChatClick:(id)sender; - (IBAction)onDeleteClick:(id)sender; - (IBAction)onSMSInviteClick:(id)sender; @end diff --git a/Classes/LinphoneUI/UIContactDetailsCell.m b/Classes/LinphoneUI/UIContactDetailsCell.m index 3fbbe92ab..b632deb0f 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.m +++ b/Classes/LinphoneUI/UIContactDetailsCell.m @@ -61,15 +61,16 @@ _linphoneImage.hidden = TRUE; if (contact) { + const LinphonePresenceModel *model = contact.friend ? linphone_friend_get_presence_model_for_uri_or_tel(contact.friend, _addressLabel.text.UTF8String) : NULL; + self.linphoneImage.hidden = - !((contact.friend && - linphone_presence_model_get_basic_status(linphone_friend_get_presence_model_for_uri_or_tel( - contact.friend, _addressLabel.text.UTF8String)) == LinphonePresenceBasicStatusOpen) || + !((model && linphone_presence_model_get_basic_status(model) == LinphonePresenceBasicStatusOpen) || (!linphone_proxy_config_is_phone_number(linphone_core_get_default_proxy_config(LC), _addressLabel.text.UTF8String) && [FastAddressBook isSipURIValid:_addressLabel.text])); ContactDetailsView *contactDetailsView = VIEW(ContactDetailsView); self.inviteButton.hidden = !ENABLE_SMS_INVITE || [[contactDetailsView.contact sipAddresses] count] > 0 || !self.linphoneImage.hidden; + [self shouldHideEncryptedChatView:model && linphone_presence_model_has_capability(model, LinphoneFriendCapabilityLimeX3dh)]; } if (addr) { @@ -77,6 +78,18 @@ } } +- (void)shouldHideEncryptedChatView:(BOOL)hasLime { + _encryptedChatView.hidden = !hasLime; + CGRect newFrame = _optionsView.frame; + if (!hasLime) { + newFrame.origin.x = _addressLabel.frame.origin.x + _callButton.frame.size.width * 2/3; + + } else { + newFrame.origin.x = _addressLabel.frame.origin.x; + } + _optionsView.frame = newFrame; +} + - (void)shouldHideLinphoneImageOfAddress { if (!_addressLabel.text) { return; @@ -137,11 +150,16 @@ - (IBAction)onChatClick:(id)event { LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:_addressLabel.text]; - // TODO one button for chatroom encrypted,another button for chatroom unencrypted - [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView isEncrypted:TRUE]; + [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView isEncrypted:FALSE]; linphone_address_destroy(addr); } +- (IBAction)onEncrptedChatClick:(id)sender { + LinphoneAddress *addr = [LinphoneUtils normalizeSipOrPhoneAddress:_addressLabel.text]; + [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView isEncrypted:TRUE]; + linphone_address_destroy(addr); +} + - (IBAction)onDeleteClick:(id)sender { UITableView *tableView = VIEW(ContactDetailsView).tableController.tableView; NSIndexPath *indexPath = [tableView indexPathForCell:self]; diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 71626c396..c751a4dbf 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -866,7 +866,7 @@ static RootViewManager *rootViewManagerInstance = nil; } const LinphoneAddress *local = linphone_proxy_config_get_contact(linphone_core_get_default_proxy_config(LC)); - LinphoneChatRoom *room = linphone_core_find_one_to_one_chat_room(LC, local, remoteAddress); + LinphoneChatRoom *room = linphone_core_find_one_to_one_chat_room_2(LC, local, remoteAddress, isEncrypted); if (!room) { bctbx_list_t *addresses = bctbx_list_new((void*)remoteAddress); [self createChatRoomWithSubject:LINPHONE_DUMMY_SUBJECT addresses:addresses andWaitView:waitView isEncrypted:isEncrypted]; diff --git a/Resources/linphonerc-factory b/Resources/linphonerc-factory index d50e389b2..c04b3b86e 100644 --- a/Resources/linphonerc-factory +++ b/Resources/linphonerc-factory @@ -36,7 +36,7 @@ sip_random_port=0 #whether SIP passwords must be encrypted in configuration storage file store_ha1_passwd=0 deliver_imdn=1 -linphone_specs=groupchat +linphone_specs=groupchat,lime #to avoid app to not detect broken sockets when in long running task. tcp_tls_keepalive=30000 @@ -60,7 +60,7 @@ display_filter_auto_rotate=0 [lime] lime_v2=1 -x3dh_server_url=http://54.37.202.229:8082/flexisip-account-manager/x3dh-25519.php +x3dh_server_url=http://54.36.232.93:8082/flexisip-account-manager/x3dh-25519.php lime_update_threshold=86400 max_nb_device_per_participant=255 allow_message_in_unsafe_chatroom=1