From 26b8fdb1e11858e7540a5a0935a9482ddec54ba5 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Tue, 27 Feb 2018 15:16:35 +0100 Subject: [PATCH] update linphone and adapt UI to the new chat room cbs API --- Classes/ChatConversationInfoView.h | 1 + Classes/ChatConversationInfoView.m | 38 +++++++++++----------- Classes/ChatConversationView.h | 1 + Classes/ChatConversationView.m | 52 ++++++++++++++---------------- Classes/ChatsListTableView.m | 14 ++++---- Classes/PhoneMainView.m | 8 +++-- submodules/linphone | 2 +- 7 files changed, 57 insertions(+), 59 deletions(-) diff --git a/Classes/ChatConversationInfoView.h b/Classes/ChatConversationInfoView.h index 792464efd..874630dc3 100644 --- a/Classes/ChatConversationInfoView.h +++ b/Classes/ChatConversationInfoView.h @@ -20,6 +20,7 @@ @property(nonatomic, strong) NSMutableArray *oldAdmins; @property(nonatomic) NSString *oldSubject; @property(nonatomic) LinphoneChatRoom *room; +@property(nonatomic) LinphoneChatRoomCbs *chatRoomCbs; @property (weak, nonatomic) IBOutlet UIIconButton *nextButton; @property (weak, nonatomic) IBOutlet UIRoundBorderedButton *quitButton; diff --git a/Classes/ChatConversationInfoView.m b/Classes/ChatConversationInfoView.m index cd4b6ae96..4dc46ae58 100644 --- a/Classes/ChatConversationInfoView.m +++ b/Classes/ChatConversationInfoView.m @@ -65,6 +65,7 @@ static UICompositeViewDescription *compositeDescription = nil; _oldAdmins = [[NSMutableArray alloc] init]; _oldContacts = [[NSMutableArray alloc] init]; _room = NULL; + _chatRoomCbs = NULL; } - (void)viewWillAppear:(BOOL)animated { @@ -100,28 +101,25 @@ static UICompositeViewDescription *compositeDescription = nil; )]; if (_room) { - LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(_room); - linphone_chat_room_cbs_set_state_changed(cbs, main_view_chat_room_state_changed); - linphone_chat_room_cbs_set_subject_changed(cbs, chat_room_subject_changed); - linphone_chat_room_cbs_set_participant_added(cbs, chat_room_participant_added); - linphone_chat_room_cbs_set_participant_removed(cbs, chat_room_participant_removed); - linphone_chat_room_cbs_set_participant_admin_status_changed(cbs, chat_room_participant_admin_status_changed); - linphone_chat_room_cbs_set_user_data(cbs, (__bridge void*)self); + _chatRoomCbs = linphone_factory_create_chat_room_cbs(linphone_factory_get()); + linphone_chat_room_cbs_set_state_changed(_chatRoomCbs, main_view_chat_room_state_changed); + linphone_chat_room_cbs_set_subject_changed(_chatRoomCbs, chat_room_subject_changed); + linphone_chat_room_cbs_set_participant_added(_chatRoomCbs, chat_room_participant_added); + linphone_chat_room_cbs_set_participant_removed(_chatRoomCbs, chat_room_participant_removed); + linphone_chat_room_cbs_set_participant_admin_status_changed(_chatRoomCbs, chat_room_participant_admin_status_changed); + linphone_chat_room_cbs_set_user_data(_chatRoomCbs, (__bridge void*)self); + linphone_chat_room_add_callbacks(_room, _chatRoomCbs); } [_tableView reloadData]; } - (void)viewWillDisappear:(BOOL)animated { - if (_room) { - LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(_room); - linphone_chat_room_cbs_set_state_changed(cbs, NULL); - linphone_chat_room_cbs_set_subject_changed(cbs, NULL); - linphone_chat_room_cbs_set_participant_added(cbs, NULL); - linphone_chat_room_cbs_set_participant_removed(cbs, NULL); - linphone_chat_room_cbs_set_participant_admin_status_changed(cbs, NULL); - linphone_chat_room_cbs_set_user_data(cbs, NULL); - } + if (!_room || !_chatRoomCbs) + return; + + linphone_chat_room_remove_callbacks(_room, _chatRoomCbs); + _chatRoomCbs = NULL; } #pragma mark - next functions @@ -333,12 +331,12 @@ static UICompositeViewDescription *compositeDescription = nil; } void chat_room_subject_changed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { - ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); view.nameLabel.text = [NSString stringWithUTF8String:linphone_event_log_get_subject(event_log)]; } void chat_room_participant_added(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { - ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); NSString *participantAddress = [NSString stringWithUTF8String:linphone_address_as_string(linphone_event_log_get_participant_address(event_log))]; [view.oldContacts addObject:participantAddress]; [view.contacts addObject:participantAddress]; @@ -346,7 +344,7 @@ void chat_room_participant_added(LinphoneChatRoom *cr, const LinphoneEventLog *e } void chat_room_participant_removed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { - ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); NSString *participantAddress = [NSString stringWithUTF8String:linphone_address_as_string(linphone_event_log_get_participant_address(event_log))]; [view.oldContacts removeObject:participantAddress]; [view.contacts removeObject:participantAddress]; @@ -354,7 +352,7 @@ void chat_room_participant_removed(LinphoneChatRoom *cr, const LinphoneEventLog } void chat_room_participant_admin_status_changed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { - ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); NSString *participantAddress = [NSString stringWithUTF8String:linphone_address_as_string(linphone_event_log_get_participant_address(event_log))]; LinphoneParticipant *me = linphone_chat_room_get_me(cr); diff --git a/Classes/ChatConversationView.h b/Classes/ChatConversationView.h index 1ff2e48ab..fcf5d15a7 100644 --- a/Classes/ChatConversationView.h +++ b/Classes/ChatConversationView.h @@ -40,6 +40,7 @@ } @property(nonatomic) LinphoneChatRoom *chatRoom; +@property(nonatomic) LinphoneChatRoomCbs *chatRoomCbs; @property(weak, nonatomic) IBOutlet UIIconButton *backButton; @property(nonatomic, strong) IBOutlet ChatConversationTableView *tableController; diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index bd3195b6a..c890c6b66 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -32,6 +32,7 @@ if (self != nil) { scrollOnGrowingEnabled = TRUE; _chatRoom = NULL; + _chatRoomCbs = NULL; imageQualities = [[OrderedDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithFloat:0.9], NSLocalizedString(@"Maximum", nil), [NSNumber numberWithFloat:0.5], NSLocalizedString(@"Average", nil), @@ -116,16 +117,10 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; - LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(_chatRoom); - linphone_chat_room_cbs_set_state_changed(cbs, NULL); - linphone_chat_room_cbs_set_subject_changed(cbs, NULL); - linphone_chat_room_cbs_set_participant_added(cbs, NULL); - linphone_chat_room_cbs_set_participant_removed(cbs, NULL); - linphone_chat_room_cbs_set_participant_admin_status_changed(cbs, NULL); - linphone_chat_room_cbs_set_user_data(cbs, NULL); - linphone_chat_room_cbs_set_chat_message_received(cbs, NULL); - linphone_chat_room_cbs_set_chat_message_sent(cbs, NULL); - linphone_chat_room_cbs_set_is_composing_received(cbs, NULL); + if (_chatRoom && _chatRoomCbs) { + linphone_chat_room_remove_callbacks(_chatRoom, _chatRoomCbs); + _chatRoomCbs = NULL; + } [_messageField resignFirstResponder]; @@ -158,16 +153,17 @@ static UICompositeViewDescription *compositeDescription = nil; return; } - LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(_chatRoom); - linphone_chat_room_cbs_set_state_changed(cbs, on_chat_room_state_changed); - linphone_chat_room_cbs_set_subject_changed(cbs, on_chat_room_subject_changed); - linphone_chat_room_cbs_set_participant_added(cbs, on_chat_room_participant_added); - linphone_chat_room_cbs_set_participant_removed(cbs, on_chat_room_participant_removed); - linphone_chat_room_cbs_set_participant_admin_status_changed(cbs, on_chat_room_participant_admin_status_changed); - linphone_chat_room_cbs_set_chat_message_received(cbs, on_chat_room_chat_message_received); - linphone_chat_room_cbs_set_chat_message_sent(cbs, on_chat_room_chat_message_sent); - linphone_chat_room_cbs_set_is_composing_received(cbs, on_chat_room_is_composing_received); - linphone_chat_room_cbs_set_user_data(cbs, (__bridge void*)self); + _chatRoomCbs = linphone_factory_create_chat_room_cbs(linphone_factory_get()); + linphone_chat_room_cbs_set_state_changed(_chatRoomCbs, on_chat_room_state_changed); + linphone_chat_room_cbs_set_subject_changed(_chatRoomCbs, on_chat_room_subject_changed); + linphone_chat_room_cbs_set_participant_added(_chatRoomCbs, on_chat_room_participant_added); + linphone_chat_room_cbs_set_participant_removed(_chatRoomCbs, on_chat_room_participant_removed); + linphone_chat_room_cbs_set_participant_admin_status_changed(_chatRoomCbs, on_chat_room_participant_admin_status_changed); + linphone_chat_room_cbs_set_chat_message_received(_chatRoomCbs, on_chat_room_chat_message_received); + linphone_chat_room_cbs_set_chat_message_sent(_chatRoomCbs, on_chat_room_chat_message_sent); + linphone_chat_room_cbs_set_is_composing_received(_chatRoomCbs, on_chat_room_is_composing_received); + linphone_chat_room_cbs_set_user_data(_chatRoomCbs, (__bridge void*)self); + linphone_chat_room_add_callbacks(_chatRoom, _chatRoomCbs); [self updateSuperposedButtons]; @@ -711,14 +707,14 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark - chat room callbacks void on_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomState newState) { - ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); view.messageField.editable = !linphone_chat_room_has_been_left(cr); view.pictureButton.enabled = !linphone_chat_room_has_been_left(cr); view.messageView.userInteractionEnabled = !linphone_chat_room_has_been_left(cr); } void on_chat_room_subject_changed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { - ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); const char *subject = linphone_chat_room_get_subject(cr) ?: linphone_event_log_get_subject(event_log); if (subject) { view.addressLabel.text = [NSString stringWithUTF8String:subject]; @@ -728,27 +724,27 @@ void on_chat_room_subject_changed(LinphoneChatRoom *cr, const LinphoneEventLog * } void on_chat_room_participant_added(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { - ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); [view.tableController addEventEntry:(LinphoneEventLog *)event_log]; [view updateParticipantLabel]; [view.tableController scrollToBottom:true]; } void on_chat_room_participant_removed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { - ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); [view.tableController addEventEntry:(LinphoneEventLog *)event_log]; [view updateParticipantLabel]; [view.tableController scrollToBottom:true]; } void on_chat_room_participant_admin_status_changed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { - ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); [view.tableController addEventEntry:(LinphoneEventLog *)event_log]; [view.tableController scrollToBottom:true]; } void on_chat_room_chat_message_received(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { - ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); LinphoneChatMessage *chat = linphone_event_log_get_chat_message(event_log); if (!chat) @@ -770,13 +766,13 @@ void on_chat_room_chat_message_received(LinphoneChatRoom *cr, const LinphoneEven } void on_chat_room_chat_message_sent(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) { - ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); [view.tableController addEventEntry:(LinphoneEventLog *)event_log]; [view.tableController scrollToBottom:true]; } void on_chat_room_is_composing_received(LinphoneChatRoom *cr, const LinphoneAddress *remoteAddr, bool_t isComposing) { - ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)); + ChatConversationView *view = (__bridge ChatConversationView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_current_callbacks(cr)); BOOL composing = linphone_chat_room_is_remote_composing(cr) || bctbx_list_size(linphone_chat_room_get_composing_addresses(cr)) > 0; [view setComposingVisible:composing withDelay:0.3]; } diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index af82794d7..25fddf6d5 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -64,9 +64,7 @@ if (!chatRoom) continue; - LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(chatRoom); - linphone_chat_room_cbs_set_state_changed(cbs, NULL); - linphone_chat_room_cbs_set_user_data(cbs, NULL); + linphone_chat_room_remove_callbacks(chatRoom, linphone_chat_room_get_current_callbacks(chatRoom)); _chatRooms = _chatRooms->next; } } @@ -173,14 +171,13 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo } void deletion_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomState newState) { - ChatsListTableView *view = (__bridge ChatsListTableView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)) ?: NULL; + LinphoneChatRoomCbs *cbs = linphone_chat_room_get_current_callbacks(cr); + ChatsListTableView *view = (__bridge ChatsListTableView *)linphone_chat_room_cbs_get_user_data(cbs) ?: NULL; if (!view) return; if (newState == LinphoneChatRoomStateDeleted || newState == LinphoneChatRoomStateTerminationFailed) { - LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); - linphone_chat_room_cbs_set_state_changed(cbs, NULL); - linphone_chat_room_cbs_set_user_data(cbs, NULL); + linphone_chat_room_remove_callbacks(cr, cbs); view.chatRooms = bctbx_list_remove(view.chatRooms, cr); view.nbOfChatRoomToDelete--; } @@ -201,9 +198,10 @@ void deletion_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomStat continue; _nbOfChatRoomToDelete++; - LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(chatRoom); + LinphoneChatRoomCbs *cbs = linphone_factory_create_chat_room_cbs(linphone_factory_get()); linphone_chat_room_cbs_set_state_changed(cbs, deletion_chat_room_state_changed); linphone_chat_room_cbs_set_user_data(cbs, (__bridge void*)self); + linphone_chat_room_add_callbacks(chatRoom, cbs); FileTransferDelegate *ftdToDelete = nil; for (FileTransferDelegate *ftd in [LinphoneManager.instance fileTransferDelegates]) { diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 2275985c9..c4b374a24 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -882,8 +882,10 @@ static RootViewManager *rootViewManagerInstance = nil; if (!room) return; - LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(room); + LinphoneChatRoomCbs *cbs = linphone_factory_create_chat_room_cbs(linphone_factory_get()); linphone_chat_room_cbs_set_state_changed(cbs, main_view_chat_room_state_changed); + linphone_chat_room_add_callbacks(room, cbs); + linphone_chat_room_add_participants(room, addresses); } @@ -900,6 +902,7 @@ void main_view_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomSta switch (newState) { case LinphoneChatRoomStateCreated: { LOGI(@"Chat room [%p] created on server.", cr); + linphone_chat_room_remove_callbacks(cr, linphone_chat_room_get_current_callbacks(cr)); [view goToChatRoom:cr]; if (!IPAD) break; @@ -913,9 +916,10 @@ void main_view_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomSta break; } case LinphoneChatRoomStateCreationFailed: + LOGE(@"Chat room [%p] could not be created on server.", cr); + linphone_chat_room_remove_callbacks(cr, linphone_chat_room_get_current_callbacks(cr)); view.waitView.hidden = YES; [ChatConversationInfoView displayCreationError]; - LOGE(@"Chat room [%p] could not be created on server.", cr); break; case LinphoneChatRoomStateTerminated: LOGI(@"Chat room [%p] has been terminated.", cr); diff --git a/submodules/linphone b/submodules/linphone index 79da08fec..9ea10688e 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit 79da08fec1b4d8f17bf3cdef0659d6dfe22a2d14 +Subproject commit 9ea10688efdab858c3952c437dddce56269663d4