From 87b185f9079b878b3244394f8827372845600efa Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Thu, 2 Jul 2015 13:53:59 +0200 Subject: [PATCH] Filetransfer: temporary fix to display all upload photos in simultanous upload --- Classes/LinphoneUI/UIChatRoomCell.m | 17 ++++++++++++++++- Classes/Utils/FileTransferDelegate.h | 1 + Classes/Utils/FileTransferDelegate.m | 3 +-- KifTests/ChatTester.m | 11 ++++++----- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Classes/LinphoneUI/UIChatRoomCell.m b/Classes/LinphoneUI/UIChatRoomCell.m index 4fd1734bd..b92ab009e 100644 --- a/Classes/LinphoneUI/UIChatRoomCell.m +++ b/Classes/LinphoneUI/UIChatRoomCell.m @@ -444,9 +444,24 @@ static UIFont *CELL_FONT = nil; } } } -#pragma mark - State changed handler +#pragma mark - State changed handling static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState state) { UIChatRoomCell *thiz = (__bridge UIChatRoomCell *)linphone_chat_message_get_user_data(msg); + LOGI(@"State for message [%p] changed to %s", msg, linphone_chat_message_state_to_string(state)); + if (linphone_chat_message_get_file_transfer_information(msg) != NULL && + (state == LinphoneChatMessageStateDelivered || state == LinphoneChatMessageStateNotDelivered)) { + // we need to refresh the tableview because the filetransfer delegate unreffed + // the chat message before state was LinphoneChatMessageStateFileTransferDone - + // if we are coming back from another view between unreffing and change of state, + // the transient message will not be found and it will not appear in the list of + // message, so we must refresh the table when we change to this state to ensure that + // all transient messages apppear + ChatRoomViewController *controller = DYNAMIC_CAST( + [[PhoneMainView instance] changeCurrentView:[ChatRoomViewController compositeViewDescription] push:TRUE], + ChatRoomViewController); + [controller.tableController setChatRoom:linphone_chat_message_get_chat_room(msg)]; + // UGLY HACK, must be fixed in file transfer cb + } [thiz update]; } diff --git a/Classes/Utils/FileTransferDelegate.h b/Classes/Utils/FileTransferDelegate.h index a62af10e0..652d42129 100644 --- a/Classes/Utils/FileTransferDelegate.h +++ b/Classes/Utils/FileTransferDelegate.h @@ -15,6 +15,7 @@ - (void)upload:(UIImage *)image withURL:(NSURL *)url forChatRoom:(LinphoneChatRoom *)chatRoom; - (void)cancel; - (BOOL)download:(LinphoneChatMessage *)message; +- (void)stopAndDestroy; @property() LinphoneChatMessage *message; @end diff --git a/Classes/Utils/FileTransferDelegate.m b/Classes/Utils/FileTransferDelegate.m index de3e54c4f..296ade26b 100644 --- a/Classes/Utils/FileTransferDelegate.m +++ b/Classes/Utils/FileTransferDelegate.m @@ -122,6 +122,7 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m // this is the last time we will be notified, so destroy ourselve if (remaining <= size) { + LOGI(@"Upload ended, unreffing %p", thiz.message); linphone_chat_message_unref(thiz.message); thiz.message = NULL; [thiz stopAndDestroy]; @@ -187,8 +188,6 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m [[[LinphoneManager instance] fileTransferDelegates] removeObject:self]; if (_message != NULL) { LOGI(@"%p Cancelling transferm from %p", self, _message); - linphone_chat_message_cbs_set_file_transfer_progress_indication(linphone_chat_message_get_callbacks(_message), - NULL); linphone_chat_message_cbs_set_file_transfer_send(linphone_chat_message_get_callbacks(_message), NULL); linphone_chat_message_cbs_set_file_transfer_recv(linphone_chat_message_get_callbacks(_message), NULL); linphone_chat_message_cancel_file_transfer(_message); diff --git a/KifTests/ChatTester.m b/KifTests/ChatTester.m index 6222610b0..a32c66988 100644 --- a/KifTests/ChatTester.m +++ b/KifTests/ChatTester.m @@ -154,7 +154,6 @@ UITableView *tv = [self findTableView:@"Chat list"]; long messagesCount = [tv numberOfRowsInSection:0]; - long delegatesCount = [[[LinphoneManager instance] fileTransferDelegates] count]; [tester tapViewWithAccessibilityLabel:@"Send picture"]; [tester tapViewWithAccessibilityLabel:@"Photo library"]; // if popup "Linphone would access your photo" pops up, click OK. @@ -164,8 +163,8 @@ #endif } - // select another photo if already uploading one - [tester choosePhotoInAlbum:@"Camera Roll" atRow:1 + delegatesCount column:1]; + // select random photo to avoid having the same multiple times + [tester choosePhotoInAlbum:@"Camera Roll" atRow:1 + messagesCount column:1]; // wait for the quality popup to show up [tester waitForTimeInterval:1]; @@ -175,8 +174,6 @@ return [element.accessibilityLabel containsString:quality]; }]; [tester tapViewWithAccessibilityLabel:element.accessibilityLabel]; - - ASSERT_EQ([tv numberOfRowsInSection:0], messagesCount + 1); } - (void)testUploadImage { @@ -249,6 +246,7 @@ } - (void)test3DownloadsSimultanously { + [self startChatWith:[self me]]; [self uploadImageWithQuality:@"Maximum"]; [self uploadImageWithQuality:@"Average"]; @@ -261,10 +259,13 @@ break; } ASSERT_EQ([[LinphoneManager instance] fileTransferDelegates].count, 0); + [tester scrollViewWithAccessibilityIdentifier:@"Chat list" byFractionOfSizeHorizontal:0.f vertical:1]; for (int i = 0; i < 3; i++) { [tester waitForViewWithAccessibilityLabel:@"Download"]; [tester tapViewWithAccessibilityLabel:@"Download"]; [tester waitForTimeInterval:.5f]; // just wait a few secs to start download + if (i != 2) + [tester scrollViewWithAccessibilityIdentifier:@"Chat list" byFractionOfSizeHorizontal:0.f vertical:-.5f]; } }