From ed964d873635bd1e4dc6082a0ab6b00e746d09e7 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Thu, 10 Feb 2022 16:17:55 +0100 Subject: [PATCH] fix chatroominfoview crash by reconfiguring the chatroom after entering background puis foreground --- Classes/ChatConversationInfoView.h | 3 +-- Classes/ChatConversationInfoView.m | 42 +++++++++++++++++++++--------- Classes/ChatConversationView.m | 1 + Classes/LinphoneAppDelegate.m | 4 --- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/Classes/ChatConversationInfoView.h b/Classes/ChatConversationInfoView.h index 2f2632d47..68cb3ab89 100644 --- a/Classes/ChatConversationInfoView.h +++ b/Classes/ChatConversationInfoView.h @@ -34,6 +34,7 @@ @property(nonatomic) NSString *oldSubject; @property(nonatomic) LinphoneChatRoom *room; @property(nonatomic) LinphoneChatRoomCbs *chatRoomCbs; +@property(nonatomic) const char *peerAddress; @property (weak, nonatomic) IBOutlet UIIconButton *nextButton; @property (weak, nonatomic) IBOutlet UIRoundBorderedButton *quitButton; @@ -49,6 +50,4 @@ - (IBAction)onBackClick:(id)sender; - (IBAction)onQuitClick:(id)sender; -- (void)removeCallbacks; - @end diff --git a/Classes/ChatConversationInfoView.m b/Classes/ChatConversationInfoView.m index ef9d61714..ea775a880 100644 --- a/Classes/ChatConversationInfoView.m +++ b/Classes/ChatConversationInfoView.m @@ -83,12 +83,30 @@ static UICompositeViewDescription *compositeDescription = nil; _oldContacts = [[NSMutableArray alloc] init]; _room = NULL; _chatRoomCbs = NULL; + _peerAddress = NULL; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; _waitView.hidden = YES; + [self configure]; + [NSNotificationCenter.defaultCenter addObserver:self + selector:@selector(onLinphoneCoreReady:) + name:kLinphoneGlobalStateUpdate + object:nil]; +} + +- (void)viewWillDisappear:(BOOL)animated { + [NSNotificationCenter.defaultCenter removeObserver:self]; + if (!_room || !_chatRoomCbs) + return; + + linphone_chat_room_remove_callbacks(_room, _chatRoomCbs); + _chatRoomCbs = NULL; +} + +- (void)configure { if (_create) _room = NULL; @@ -131,20 +149,20 @@ static UICompositeViewDescription *compositeDescription = nil; [_tableView reloadData]; } -- (void)viewWillDisappear:(BOOL)animated { - [self removeCallbacks]; -} - -- (void)removeCallbacks { - if (!_room || !_chatRoomCbs) - return; - - linphone_chat_room_remove_callbacks(_room, _chatRoomCbs); - _chatRoomCbs = NULL; -} - #pragma mark - next functions +- (void)onLinphoneCoreReady:(NSNotification *)notif { + if ((LinphoneGlobalState)[[[notif userInfo] valueForKey:@"state"] integerValue] == LinphoneGlobalOn) { + if (!_create && _peerAddress) { + LinphoneAddress *peerAddr = linphone_core_create_address([LinphoneManager getLc], _peerAddress); + if (peerAddr) { + _room = linphone_core_get_chat_room([LinphoneManager getLc], peerAddr); + } + [self configure]; + } + } +} + - (void)onCreate { bctbx_list_t *addresses = NULL; for (NSString *addr in _contacts) { diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index b7570c1c4..3804f8a36 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -888,6 +888,7 @@ static UICompositeViewDescription *compositeDescription = nil; view.oldAdmins = [admins mutableCopy]; view.oldSubject = [NSString stringWithUTF8String:linphone_chat_room_get_subject(_chatRoom) ?: LINPHONE_DUMMY_SUBJECT]; view.room = _chatRoom; + view.peerAddress = _peerAddress; [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; } diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index a1147c08a..4f464118a 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -69,10 +69,6 @@ [view removeCallBacks]; [view.tableController setChatRoom:NULL]; [view setChatRoom:NULL]; - } else if (PhoneMainView.instance.currentView == ChatConversationInfoView.compositeViewDescription) { - ChatConversationInfoView *view = VIEW(ChatConversationInfoView); - [view removeCallbacks]; - [view setRoom:NULL]; } else if (PhoneMainView.instance.currentView == RecordingsListView.compositeViewDescription || PhoneMainView.instance.currentView == DevicesListView.compositeViewDescription) { // To avoid crash [PhoneMainView.instance changeCurrentView:DialerView.compositeViewDescription];