diff --git a/Classes/ChatConversationCreateView.m b/Classes/ChatConversationCreateView.m index 2d4a583f2..dd01365a5 100644 --- a/Classes/ChatConversationCreateView.m +++ b/Classes/ChatConversationCreateView.m @@ -82,19 +82,9 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)createChatRoom { NSString *addr = _tableController.contactsGroup[0]; - const LinphoneAddress *local = linphone_proxy_config_get_contact(linphone_core_get_default_proxy_config(LC)); - LinphoneAddress *linphoneAddress = linphone_address_new(addr.UTF8String); - LinphoneChatRoom *room = linphone_core_find_one_to_one_chat_room(LC, local, linphoneAddress); - if (!room) { - bctbx_list_t *addresses = bctbx_list_new((void*)linphoneAddress); - [PhoneMainView.instance createChatRoomWithSubject:LINPHONE_DUMMY_SUBJECT addresses:addresses andWaitView:_waitView]; - bctbx_list_free_with_data(addresses, (void (*)(void *))linphone_address_unref); - return; - } - ChatConversationView *view = VIEW(ChatConversationView); - [view setChatRoom:room]; - [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; - linphone_address_destroy(linphoneAddress); + LinphoneAddress *remoteAddress = linphone_address_new(addr.UTF8String); + [PhoneMainView.instance getOrCreateOneToOneChatRoom:remoteAddress waitView:_waitView]; + linphone_address_unref(remoteAddress); } #pragma mark - Buttons signals diff --git a/Classes/HistoryDetailsView.m b/Classes/HistoryDetailsView.m index 02d08c27c..2e2cd994e 100644 --- a/Classes/HistoryDetailsView.m +++ b/Classes/HistoryDetailsView.m @@ -194,17 +194,8 @@ static UICompositeViewDescription *compositeDescription = nil; const LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog); if (addr == NULL) return; - ChatConversationView *view = VIEW(ChatConversationView); - 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, addr); - if (!room) { - bctbx_list_t *addresses = bctbx_list_new((void*)addr); - [PhoneMainView.instance createChatRoomWithSubject:LINPHONE_DUMMY_SUBJECT addresses:addresses andWaitView:_waitView]; - bctbx_list_free_with_data(addresses, (void (*)(void *))linphone_address_unref); - return; - } - [view setChatRoom:room]; - [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; + + [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView]; } @end diff --git a/Classes/LinphoneUI/UIContactDetailsCell.m b/Classes/LinphoneUI/UIContactDetailsCell.m index 155af1f1f..ed4b55256 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.m +++ b/Classes/LinphoneUI/UIContactDetailsCell.m @@ -138,17 +138,7 @@ if (addr == NULL) return; - 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, addr); - if (!room) { - bctbx_list_t *addresses = bctbx_list_new(addr); - [PhoneMainView.instance createChatRoomWithSubject:LINPHONE_DUMMY_SUBJECT addresses:addresses andWaitView:_waitView]; - bctbx_list_free_with_data(addresses, (void (*)(void *))linphone_address_unref); - return; - } - ChatConversationView *view = VIEW(ChatConversationView); - [view setChatRoom:room]; - [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; + [PhoneMainView.instance getOrCreateOneToOneChatRoom:addr waitView:_waitView]; linphone_address_destroy(addr); } diff --git a/Classes/PhoneMainView.h b/Classes/PhoneMainView.h index 29b8a5f64..3d3f39c3b 100644 --- a/Classes/PhoneMainView.h +++ b/Classes/PhoneMainView.h @@ -108,6 +108,7 @@ - (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; + (PhoneMainView*) instance; diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index af54626e9..51d4045cc 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -859,6 +859,20 @@ static RootViewManager *rootViewManagerInstance = nil; #pragma mark - Chat room Functions +- (void) getOrCreateOneToOneChatRoom:(const LinphoneAddress *)remoteAddress waitView:(UIView *)waitView { + 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); + if (!room) { + bctbx_list_t *addresses = bctbx_list_new((void*)remoteAddress); + [self createChatRoomWithSubject:LINPHONE_DUMMY_SUBJECT addresses:addresses andWaitView:waitView]; + bctbx_list_free_with_data(addresses, (void (*)(void *))linphone_address_unref); + return; + } + ChatConversationView *view = VIEW(ChatConversationView); + [view setChatRoom:room]; + [self changeCurrentView:view.compositeViewDescription]; +} + - (void)createChatRoomWithSubject:(const char *)subject addresses:(bctbx_list_t *)addresses andWaitView:(UIView *)waitView { _waitView = waitView; _waitView.hidden = NO;