From 1291e7dee4350199c6c6540f555fd3b4d89d4a9c Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Mon, 21 Nov 2022 14:46:44 +0100 Subject: [PATCH 1/3] Protect _chatRoom dependent sub function calls --- Classes/ChatConversationView.m | 46 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 00184dfaa..a7128c1ee 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -335,19 +335,19 @@ static UICompositeViewDescription *compositeDescription = nil; LinphoneAddress *peerAddr = linphone_core_create_address([LinphoneManager getLc], _peerAddress); if (peerAddr) { _chatRoom = linphone_core_get_chat_room([LinphoneManager getLc], peerAddr); - isOneToOne = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesOneToOne; - isEncrypted = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesEncrypted; - if (_chatRoom) + if (_chatRoom) { + isOneToOne = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesOneToOne; + isEncrypted = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesEncrypted; [self setComposingVisible:!composingVisible withDelay:0]; + [self configureForRoom:true]; + [_tableController scrollToBottom:true]; + } } - [self configureForRoom:true]; _backButton.hidden = _tableController.isEditing; - [_tableController scrollToBottom:true]; - [self refreshImageDrawer]; + [self refreshImageDrawer]; [self stopAllPlays]; [self keyboardWillHide:nil]; - } #pragma mark - @@ -501,25 +501,25 @@ static UICompositeViewDescription *compositeDescription = nil; // reload the chatroom after the core starts - (void)onLinphoneCoreReady:(NSNotification *)notif { - // if ((LinphoneGlobalState)[[[notif userInfo] valueForKey:@"state"] integerValue] == LinphoneGlobalOn) { if (linphone_core_get_global_state(LC) == LinphoneGlobalOn) { - LinphoneAddress *peerAddr = linphone_core_create_address([LinphoneManager getLc], _peerAddress); - if (peerAddr) { - _chatRoom = linphone_core_get_chat_room([LinphoneManager getLc], peerAddr); - isOneToOne = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesOneToOne; - isEncrypted = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesEncrypted; - } - [self configureForRoom:self.editing]; - if (_chatRoom && _markAsRead) { - if (IPAD) { - [VIEW(ChatsListView).tableController loadData]; + LinphoneAddress *peerAddr = linphone_core_create_address([LinphoneManager getLc], _peerAddress); + if (peerAddr) { + _chatRoom = linphone_core_get_chat_room([LinphoneManager getLc], peerAddr); + if (_chatRoom) { + isOneToOne = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesOneToOne; + isEncrypted = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesEncrypted; + [self configureForRoom:self.editing]; + if (_chatRoom && _markAsRead) { + if (IPAD) { + [VIEW(ChatsListView).tableController loadData]; + } + [ChatConversationView markAsRead:_chatRoom]; + } + _markAsRead = TRUE; } - - [ChatConversationView markAsRead:_chatRoom]; - } - _markAsRead = TRUE; + } [SVProgressHUD dismiss]; - } + } } - (void)callUpdateEvent:(NSNotification *)notif { From 233865747ef6896e47850bbfe4439cf849f7e6ab Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Mon, 21 Nov 2022 15:56:30 +0100 Subject: [PATCH 2/3] Reworked IMDN cell calculation to make it independent from EventList --- Classes/ChatConversationImdnView.h | 2 +- Classes/ChatConversationImdnView.m | 15 +++---- Classes/ChatConversationTableView.h | 2 + Classes/ChatConversationTableView.m | 50 ++++++++++++----------- Classes/LinphoneUI/UIChatBubbleTextCell.m | 4 +- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/Classes/ChatConversationImdnView.h b/Classes/ChatConversationImdnView.h index 26607f58d..e0bc17f18 100644 --- a/Classes/ChatConversationImdnView.h +++ b/Classes/ChatConversationImdnView.h @@ -32,7 +32,7 @@ NSString *messageText; } -@property(nonatomic) LinphoneChatMessage *msg; +@property(nonatomic) LinphoneEventLog *event; @property(nonatomic) bctbx_list_t *displayedList; @property(nonatomic) bctbx_list_t *receivedList; @property(nonatomic) bctbx_list_t *notReceivedList; diff --git a/Classes/ChatConversationImdnView.m b/Classes/ChatConversationImdnView.m index c99f9859a..a2c485dc4 100644 --- a/Classes/ChatConversationImdnView.m +++ b/Classes/ChatConversationImdnView.m @@ -48,17 +48,12 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewDidLoad { [super viewDidLoad]; - _msg = NULL; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - int index = [VIEW(ChatConversationView).tableController indexOfMesssage:_msg]; - if (index < 0) - [PhoneMainView.instance popToView:ChatConversationView.compositeViewDescription]; - - _cell = (UIChatBubbleTextCell *)[VIEW(ChatConversationView).tableController tableView:VIEW(ChatConversationView).tableController.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0]]; + _cell = [VIEW(ChatConversationView).tableController buildMessageCell:_event]; _cell.frame = CGRectMake(-10,0,_msgView.frame.size.width,_msgView.frame.size.height); _cell.isFirst = true; _cell.isLast = true; @@ -90,7 +85,8 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)updateImdnList { - if (_msg && linphone_chat_message_get_chat_room(_msg)) { + if (_event) { + LinphoneChatMessage *_msg = linphone_event_log_get_chat_message(_event); _displayedList = linphone_chat_message_get_participants_by_imdn_state(_msg, LinphoneChatMessageStateDisplayed); _receivedList = linphone_chat_message_get_participants_by_imdn_state(_msg, LinphoneChatMessageStateDeliveredToUser); _notReceivedList = linphone_chat_message_get_participants_by_imdn_state(_msg, LinphoneChatMessageStateDelivered); @@ -101,7 +97,7 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)fitContent { - + LinphoneChatMessage *_msg = linphone_event_log_get_chat_message(_event); CGSize messageSize = [UIChatBubbleTextCell ViewHeightForMessage:_msg withWidth:self.view.frame.size.width]; [_msgView setFrame:CGRectMake(_msgView.frame.origin.x, _msgView.frame.origin.y, @@ -299,7 +295,8 @@ static UICompositeViewDescription *compositeDescription = nil; f.unitsStyle = NSDateComponentsFormatterUnitsStylePositional; f.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorPad; - if (linphone_chat_message_is_ephemeral(_msg)) { + LinphoneChatMessage *_msg = _event ? linphone_event_log_get_chat_message(_event) : nil; + if (_msg && linphone_chat_message_is_ephemeral(_msg)) { long duration = linphone_chat_message_get_ephemeral_expire_time(_msg) == 0 ? linphone_chat_room_get_ephemeral_lifetime(linphone_chat_message_get_chat_room(_msg)) : linphone_chat_message_get_ephemeral_expire_time(_msg)-[NSDate date].timeIntervalSince1970; diff --git a/Classes/ChatConversationTableView.h b/Classes/ChatConversationTableView.h index 08a7a6d70..58680dd9c 100644 --- a/Classes/ChatConversationTableView.h +++ b/Classes/ChatConversationTableView.h @@ -25,6 +25,7 @@ #import "UICheckBoxTableView.h" + @interface FileContext : NSObject @property NSMutableArray *typesArray; @property NSMutableArray *datasArray; @@ -70,5 +71,6 @@ - (void) dismissMessagesPopups; - (void) scrollToMessage:(LinphoneChatMessage *)message; - (int) indexOfMesssage:(LinphoneChatMessage *)message; +- (void *)buildMessageCell:(LinphoneEventLog *) event; @end diff --git a/Classes/ChatConversationTableView.m b/Classes/ChatConversationTableView.m index 0822e472f..376262a19 100644 --- a/Classes/ChatConversationTableView.m +++ b/Classes/ChatConversationTableView.m @@ -20,7 +20,6 @@ #import "LinphoneManager.h" #import "ChatConversationTableView.h" #import "ChatConversationImdnView.h" -#import "UIChatBubbleTextCell.h" #import "UIChatBubblePhotoCell.h" #import "UIChatNotifiedEventCell.h" #import "PhoneMainView.h" @@ -330,28 +329,32 @@ static const int BASIC_EVENT_LIST=15; } } +-(UIChatBubbleTextCell *)buildMessageCell:(LinphoneEventLog *) event { + NSString *kCellId = nil; + LinphoneChatMessage *chat = linphone_event_log_get_chat_message(event); + BOOL isConferenceIcs = [ICSBubbleView isConferenceInvitationMessageWithCmessage:chat]; + if (!isConferenceIcs && (linphone_chat_message_get_file_transfer_information(chat) || linphone_chat_message_get_external_body_url(chat))) + kCellId = NSStringFromClass(UIChatBubblePhotoCell.class); + else + kCellId = NSStringFromClass(UIChatBubbleTextCell.class); + // To use less memory and to avoid overlapping. To be improved. + UIChatBubbleTextCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellId]; + cell = [[NSClassFromString(kCellId) alloc] initWithIdentifier:kCellId]; + [cell setEvent:event]; + return cell; +} + - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *kCellId = nil; LinphoneEventLog *event = [[eventList objectAtIndex:indexPath.row] pointerValue]; if (linphone_event_log_get_type(event) == LinphoneEventLogTypeConferenceChatMessage) { + UIChatBubbleTextCell *cell = [self buildMessageCell:event]; LinphoneChatMessage *chat = linphone_event_log_get_chat_message(event); - BOOL isConferenceIcs = [ICSBubbleView isConferenceInvitationMessageWithCmessage:chat]; - if (!isConferenceIcs && (linphone_chat_message_get_file_transfer_information(chat) || linphone_chat_message_get_external_body_url(chat))) - kCellId = NSStringFromClass(UIChatBubblePhotoCell.class); - else - kCellId = NSStringFromClass(UIChatBubbleTextCell.class); - - // To use less memory and to avoid overlapping. To be improved. - UIChatBubbleTextCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; - cell = [[NSClassFromString(kCellId) alloc] initWithIdentifier:kCellId]; - - [cell setEvent:event]; - if (chat) { - cell.isFirst = [self isFirstIndexInTableView:indexPath chat:chat]; - cell.isLast = [self isLastIndexInTableView:indexPath chat:chat]; - [cell update]; - } - + if (chat) { + cell.isFirst = [self isFirstIndexInTableView:indexPath chat:chat]; + cell.isLast = [self isLastIndexInTableView:indexPath chat:chat]; + [cell update]; + } [cell setChatRoomDelegate:_chatRoomDelegate]; [super accessoryForCell:cell atPath:indexPath]; cell.selectionStyle = UITableViewCellSelectionStyleNone; @@ -442,12 +445,11 @@ static const CGFloat MESSAGE_SPACING_PERCENTAGE = 1.f; LinphoneEventLog *event = [[eventList objectAtIndex:indexPath.row] pointerValue]; UIContextualAction *imdnAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal - title:NSLocalizedString(@"Info", nil) - handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { - LinphoneChatMessage *msg = linphone_event_log_get_chat_message(event); - ChatConversationImdnView *view = VIEW(ChatConversationImdnView); - view.msg = msg; - [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; + title:NSLocalizedString(@"Info", nil) + handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { + ChatConversationImdnView *view = VIEW(ChatConversationImdnView); + view.event = event; + [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; }]; UISwipeActionsConfiguration *swipeActionConfig; diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 579089a1f..f6f273738 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -848,6 +848,8 @@ static const CGFloat REPLY_OR_FORWARD_TAG_HEIGHT = 18; -(void) buildActions { LinphoneChatMessage *message = self.message; + LinphoneEventLog *event = self.event; + _messageActionsTitles = [[NSMutableArray alloc] init]; _messageActionsBlocks = [[NSMutableArray alloc] init]; _messageActionsIcons = [[NSMutableArray alloc] init]; @@ -905,7 +907,7 @@ static const CGFloat REPLY_OR_FORWARD_TAG_HEIGHT = 18; [_messageActionsBlocks addObject:^{ [thiz dismissPopup]; ChatConversationImdnView *view = VIEW(ChatConversationImdnView); - view.msg = message; + view.event = event; [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; }]; } From 03af1afac1e9d08e9d27fedd7f2ed5720b7090d7 Mon Sep 17 00:00:00 2001 From: QuentinArguillere Date: Mon, 21 Nov 2022 17:26:38 +0100 Subject: [PATCH 3/3] =?UTF-8?q?When=20calling=20setComposingVisible,=20che?= =?UTF-8?q?ck=20that=20the=20=E2=80=9Cis=20composing=E2=80=9D=20message=20?= =?UTF-8?q?is=20visible=20as=20well=20as=20blocking=20text=20before=20scro?= =?UTF-8?q?lling=20to=20the=20bottom=20of=20the=20chat=20conversation=20vi?= =?UTF-8?q?ew?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/ChatConversationView.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index a7128c1ee..ea3c860de 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -677,9 +677,11 @@ static UICompositeViewDescription *compositeDescription = nil; completion:^(BOOL finished) { _composeIndicatorView.hidden = !visible; }]; - if (_tableController.tableView.contentOffset.y + newComposingFrame.size.height >= (_tableController.tableView.contentSize.height - _tableController.tableView.frame.size.height)) { - [_tableController scrollToBottom:TRUE]; - } + if (visible) { + if (_tableController.tableView.contentOffset.y + newComposingFrame.size.height >= (_tableController.tableView.contentSize.height - _tableController.tableView.frame.size.height)) { + [_tableController scrollToBottom:TRUE]; + } + } } - (BOOL) groupCallAvailable {