diff --git a/Classes/ChatConversationCreateTableView.m b/Classes/ChatConversationCreateTableView.m index 0e069f238..b0a0ab0ff 100644 --- a/Classes/ChatConversationCreateTableView.m +++ b/Classes/ChatConversationCreateTableView.m @@ -95,6 +95,11 @@ [view setChatRoom:room]; [PhoneMainView.instance popCurrentView]; [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; + // refresh list of chatrooms if we are using fragment + if (IPAD) { + ChatsListView *listView = VIEW(ChatsListView); + [listView.tableController loadData]; + } } } diff --git a/Classes/ChatConversationTableView.h b/Classes/ChatConversationTableView.h index 87d19bf89..62830af62 100644 --- a/Classes/ChatConversationTableView.h +++ b/Classes/ChatConversationTableView.h @@ -32,16 +32,15 @@ @interface ChatConversationTableView : UICheckBoxTableView { @private - LinphoneChatRoom *chatRoom; MSList *messageList; } +@property(nonatomic) LinphoneChatRoom *chatRoom; @property(nonatomic, strong) id chatRoomDelegate; - (void)addChatEntry:(LinphoneChatMessage *)chat; - (void)scrollToBottom:(BOOL)animated; - (void)scrollToLastUnread:(BOOL)animated; - (void)updateChatEntry:(LinphoneChatMessage *)chat; -- (void)setChatRoom:(LinphoneChatRoom *)room; @end diff --git a/Classes/ChatConversationTableView.m b/Classes/ChatConversationTableView.m index e26d24f6d..487cfd733 100644 --- a/Classes/ChatConversationTableView.m +++ b/Classes/ChatConversationTableView.m @@ -45,16 +45,16 @@ } - (void)updateData { - if (!chatRoom) + if (!_chatRoom) return; [self clearMessageList]; - messageList = linphone_chat_room_get_history(chatRoom, 0); + messageList = linphone_chat_room_get_history(_chatRoom, 0); // also append transient upload messages because they are not in history yet! for (FileTransferDelegate *ftd in [LinphoneManager.instance fileTransferDelegates]) { const LinphoneAddress *ftd_peer = linphone_chat_room_get_peer_address(linphone_chat_message_get_chat_room(ftd.message)); - const LinphoneAddress *peer = linphone_chat_room_get_peer_address(chatRoom); + const LinphoneAddress *peer = linphone_chat_room_get_peer_address(_chatRoom); if (linphone_address_equal(ftd_peer, peer) && linphone_chat_message_is_outgoing(ftd.message)) { LOGI(@"Appending transient upload message %p", ftd.message); messageList = ms_list_append(messageList, linphone_chat_message_ref(ftd.message)); @@ -109,7 +109,7 @@ } - (void)scrollToLastUnread:(BOOL)animated { - if (messageList == nil || chatRoom == nil) { + if (messageList == nil || _chatRoom == nil) { return; } @@ -127,7 +127,7 @@ index = count - 1; } - linphone_chat_room_mark_as_read(chatRoom); + linphone_chat_room_mark_as_read(_chatRoom); TabBarView *tab = (TabBarView *)[PhoneMainView.instance.mainViewController getCachedController:NSStringFromClass(TabBarView.class)]; [tab update:YES]; @@ -144,7 +144,7 @@ #pragma mark - Property Functions - (void)setChatRoom:(LinphoneChatRoom *)room { - chatRoom = room; + _chatRoom = room; [self reloadData]; } @@ -197,7 +197,7 @@ if (editingStyle == UITableViewCellEditingStyleDelete) { [tableView beginUpdates]; LinphoneChatMessage *chat = ms_list_nth_data(messageList, (int)[indexPath row]); - linphone_chat_room_delete_message(chatRoom, chat); + linphone_chat_room_delete_message(_chatRoom, chat); messageList = ms_list_remove(messageList, chat); [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] @@ -209,7 +209,7 @@ - (void)removeSelectionUsing:(void (^)(NSIndexPath *))remover { [super removeSelectionUsing:^(NSIndexPath *indexPath) { LinphoneChatMessage *chat = ms_list_nth_data(messageList, (int)[indexPath row]); - linphone_chat_room_delete_message(chatRoom, chat); + linphone_chat_room_delete_message(_chatRoom, chat); messageList = ms_list_remove(messageList, chat); }]; } diff --git a/Classes/ChatConversationView.h b/Classes/ChatConversationView.h index cf28ebac1..70d787bbc 100644 --- a/Classes/ChatConversationView.h +++ b/Classes/ChatConversationView.h @@ -33,12 +33,13 @@ @interface ChatConversationView : TPMultiLayoutViewController { - LinphoneChatRoom *chatRoom; OrderedDictionary *imageQualities; BOOL scrollOnGrowingEnabled; BOOL composingVisible; } +@property(nonatomic) LinphoneChatRoom *chatRoom; + @property(weak, nonatomic) IBOutlet UIIconButton *backButton; @property(nonatomic, strong) IBOutlet ChatConversationTableView *tableController; @property(weak, nonatomic) IBOutlet HPGrowingTextView *messageField; @@ -65,6 +66,4 @@ - (IBAction)onDeleteClick:(id)sender; - (IBAction)onEditionChangeClick:(id)sender; -- (void)setChatRoom:(LinphoneChatRoom *)room; - @end diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 8e142b5be..d8760986c 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -31,7 +31,7 @@ self = [super initWithNibName:NSStringFromClass(self.class) bundle:[NSBundle mainBundle]]; if (self != nil) { scrollOnGrowingEnabled = TRUE; - chatRoom = NULL; + _chatRoom = NULL; imageQualities = [[OrderedDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithFloat:0.9], NSLocalizedString(@"Maximum", nil), [NSNumber numberWithFloat:0.5], NSLocalizedString(@"Average", nil), @@ -152,16 +152,16 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark - -- (void)setChatRoom:(LinphoneChatRoom *)room { - chatRoom = room; +- (void)setChatRoom:(LinphoneChatRoom *)chatRoom { + _chatRoom = chatRoom; [_messageField setText:@""]; - [_tableController setChatRoom:room]; + [_tableController setChatRoom:_chatRoom]; - if (chatRoom != NULL) { + if (_chatRoom != NULL) { _chatView.hidden = NO; [self update]; - linphone_chat_room_mark_as_read(chatRoom); - [self setComposingVisible:linphone_chat_room_is_remote_composing(chatRoom) withDelay:0]; + linphone_chat_room_mark_as_read(_chatRoom); + [self setComposingVisible:linphone_chat_room_is_remote_composing(_chatRoom) withDelay:0]; TabBarView *tab = (TabBarView *)[PhoneMainView.instance.mainViewController getCachedController:NSStringFromClass(TabBarView.class)]; [tab update:YES]; @@ -172,8 +172,8 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)applicationWillEnterForeground:(NSNotification *)notif { - if (chatRoom != nil) { - linphone_chat_room_mark_as_read(chatRoom); + if (_chatRoom != nil) { + linphone_chat_room_mark_as_read(_chatRoom); TabBarView *tab = (TabBarView *)[PhoneMainView.instance.mainViewController getCachedController:NSStringFromClass(TabBarView.class)]; [tab update:YES]; @@ -186,12 +186,12 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)update { - if (chatRoom == NULL) { + if (_chatRoom == NULL) { LOGW(@"Cannot update chat room header: null contact"); return; } - const LinphoneAddress *addr = linphone_chat_room_get_peer_address(chatRoom); + const LinphoneAddress *addr = linphone_chat_room_get_peer_address(_chatRoom); if (addr == NULL) { [PhoneMainView.instance popCurrentView]; UIAlertView *error = [[UIAlertView alloc] @@ -211,12 +211,12 @@ static UICompositeViewDescription *compositeDescription = nil; } - (BOOL)sendMessage:(NSString *)message withExterlBodyUrl:(NSURL *)externalUrl withInternalURL:(NSURL *)internalUrl { - if (chatRoom == NULL) { + if (_chatRoom == NULL) { LOGW(@"Cannot send message: No chatroom"); return FALSE; } - LinphoneChatMessage *msg = linphone_chat_room_create_message(chatRoom, [message UTF8String]); + LinphoneChatMessage *msg = linphone_chat_room_create_message(_chatRoom, [message UTF8String]); if (externalUrl) { linphone_chat_message_set_external_body_url(msg, [[externalUrl absoluteString] UTF8String]); } @@ -226,7 +226,7 @@ static UICompositeViewDescription *compositeDescription = nil; [LinphoneManager setValueInMessageAppData:[internalUrl absoluteString] forKey:@"localimage" inMessage:msg]; } - linphone_chat_room_send_chat_message(chatRoom, msg); + linphone_chat_room_send_chat_message(_chatRoom, msg); [_tableController addChatEntry:msg]; [_tableController scrollToBottom:true]; @@ -322,7 +322,7 @@ static UICompositeViewDescription *compositeDescription = nil; } char *fromStr = linphone_address_as_string_uri_only(from); - const LinphoneAddress *cr_from = linphone_chat_room_get_peer_address(chatRoom); + const LinphoneAddress *cr_from = linphone_chat_room_get_peer_address(_chatRoom); char *cr_from_string = linphone_address_as_string_uri_only(cr_from); if (fromStr && cr_from_string) { @@ -341,7 +341,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)textComposeEvent:(NSNotification *)notif { LinphoneChatRoom *room = [[[notif userInfo] objectForKey:@"room"] pointerValue]; - if (room && room == chatRoom) { + if (room && room == _chatRoom) { BOOL composing = linphone_chat_room_is_remote_composing(room); [self setComposingVisible:composing withDelay:0.3]; } @@ -363,8 +363,8 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)growingTextChanged:(HPGrowingTextView *)growingTextView text:(NSString *)text { - if ([text length] > 0 && chatRoom) - linphone_chat_room_compose(chatRoom); + if ([text length] > 0 && _chatRoom) + linphone_chat_room_compose(_chatRoom); } - (void)growingTextView:(HPGrowingTextView *)growingTextView willChangeHeight:(float)height { @@ -426,7 +426,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)textViewDidChange:(UITextView *)textView { if ([textView.text length] > 0) { - linphone_chat_room_compose(chatRoom); + linphone_chat_room_compose(_chatRoom); } } @@ -515,7 +515,7 @@ static UICompositeViewDescription *compositeDescription = nil; } - (IBAction)onCallClick:(id)sender { - [LinphoneManager.instance call:linphone_chat_room_get_peer_address(chatRoom)]; + [LinphoneManager.instance call:linphone_chat_room_get_peer_address(_chatRoom)]; } - (IBAction)onListSwipe:(id)sender { @@ -539,7 +539,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (BOOL)startImageUpload:(UIImage *)image url:(NSURL *)url { FileTransferDelegate *fileTransfer = [[FileTransferDelegate alloc] init]; - [fileTransfer upload:image withURL:url forChatRoom:chatRoom]; + [fileTransfer upload:image withURL:url forChatRoom:_chatRoom]; [_tableController addChatEntry:linphone_chat_message_ref(fileTransfer.message)]; [_tableController scrollToBottom:true]; return TRUE; diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index 5085209a2..9af1904af 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -119,11 +119,16 @@ static void chatTable_free_chatrooms(void *data) { [super loadData]; if (IPAD) { - // reset conversation view since in fragment mode, conversations are relative to current data - // select first conversation if any + // if conversation view is using a chatroom that does not exist anymore, update it if (data != NULL) { ChatConversationView *view = VIEW(ChatConversationView); - [view setChatRoom:(LinphoneChatRoom *)ms_list_nth_data(data, 0)]; + LinphoneChatRoom *current = [view chatRoom]; + // cannot find it anymore: replace it with the first one + if (ms_list_find(data, current) == NULL) { + [view setChatRoom:(LinphoneChatRoom *)ms_list_nth_data(data, 0)]; + } + } else { + [PhoneMainView.instance changeCurrentView:ChatConversationCreateView.compositeViewDescription]; } } } diff --git a/Classes/ContactsListTableView.m b/Classes/ContactsListTableView.m index cb1c5ac64..29703d0f2 100644 --- a/Classes/ContactsListTableView.m +++ b/Classes/ContactsListTableView.m @@ -144,13 +144,13 @@ static int ms_strcmpfuz(const char *fuzzy_word, const char *sentence) { } } [super loadData]; + if (IPAD) { - // reset details view since in fragment mode, details are relative to current data - // select first contact if any + // if contact details view is using a contact that does not exist anymore, update it + ContactDetailsView *view = VIEW(ContactDetailsView); ABRecordRef contact = ([self totalNumberOfItems] > 0) ? [self contactForIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] : nil; - ContactDetailsView *view = VIEW(ContactDetailsView); [view setContact:contact]; } }