From 62b6669c1a559499c1519ac4a6ef48d68efa216c Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Tue, 16 Jun 2015 14:53:01 +0200 Subject: [PATCH] FileTransfer: fix crash when deleting a chat room with pending transfers --- Classes/ChatRoomTableViewController.m | 1 - Classes/ChatTableViewController.m | 12 ++++++++++-- Classes/Utils/FileTransferDelegate.m | 4 ++-- KifTests/ChatTester.m | 7 +++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Classes/ChatRoomTableViewController.m b/Classes/ChatRoomTableViewController.m index 2cc654e1e..425b06662 100644 --- a/Classes/ChatRoomTableViewController.m +++ b/Classes/ChatRoomTableViewController.m @@ -194,7 +194,6 @@ [tableView beginUpdates]; LinphoneChatMessage *chat = ms_list_nth_data(self->messageList, (int)[indexPath row]); if( chat ){ - linphone_chat_room_delete_message(chatRoom, chat); messageList = ms_list_remove(messageList, chat); diff --git a/Classes/ChatTableViewController.m b/Classes/ChatTableViewController.m index c5f38c70a..e6ce9be78 100644 --- a/Classes/ChatTableViewController.m +++ b/Classes/ChatTableViewController.m @@ -20,6 +20,8 @@ #import "ChatTableViewController.h" #import "UIChatCell.h" +#import "FileTransferDelegate.h" + #import "linphone/linphonecore.h" #import "PhoneMainView.h" #import "UACellBackgroundView.h" @@ -171,8 +173,14 @@ static void chatTable_free_chatrooms(void *data){ linphone_chat_message_unref(last_msg); linphone_chat_room_set_user_data(chatRoom, NULL); } - linphone_chat_room_delete_history(chatRoom); - linphone_chat_room_unref(chatRoom); + + for (FileTransferDelegate *ftd in [[LinphoneManager instance] fileTransferDelegates]) { + if (linphone_chat_message_get_chat_room(ftd.message) == chatRoom) { + [ftd cancel]; + } + } + linphone_chat_room_delete_history(chatRoom); + linphone_chat_room_unref(chatRoom); data = ms_list_remove(data, chatRoom); // will force a call to [self loadData] diff --git a/Classes/Utils/FileTransferDelegate.m b/Classes/Utils/FileTransferDelegate.m index 6a6adf1ef..36419cbf4 100644 --- a/Classes/Utils/FileTransferDelegate.m +++ b/Classes/Utils/FileTransferDelegate.m @@ -73,7 +73,7 @@ static void linphone_iphone_file_transfer_recv(LinphoneChatMessage *message, con CFRelease((__bridge CFTypeRef)thiz); }]; } else { - LOGI(@"Transfer of %s (%d bytes): already %ld sent, adding %ld", linphone_content_get_name(content), + LOGD(@"Transfer of %s (%d bytes): already %ld sent, adding %ld", linphone_content_get_name(content), linphone_content_get_size(content), [thiz.data length], size); [thiz.data appendBytes:linphone_buffer_get_string_content(buffer) length:size]; [[NSNotificationCenter defaultCenter] @@ -97,7 +97,7 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m @"state" : @(linphone_chat_message_get_state(message)), @"progress" : @(offset * 1.f / total), }]; - LOGI(@"Transfer of %s (%d bytes): already sent %ld, remaining %ld", linphone_content_get_name(content), total, + LOGD(@"Transfer of %s (%d bytes): already sent %ld, remaining %ld", linphone_content_get_name(content), total, offset, remaining); [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneFileTransferSendUpdate object:thiz diff --git a/KifTests/ChatTester.m b/KifTests/ChatTester.m index 2b890443a..76cd623c5 100644 --- a/KifTests/ChatTester.m +++ b/KifTests/ChatTester.m @@ -211,6 +211,13 @@ - (void)downloadImage { [self uploadImage]; + // wait for the upload to terminate... + for (int i = 0; i < 15; i++) { + [tester waitForTimeInterval:1.f]; + if ([[[LinphoneManager instance] fileTransferDelegates] count] == 0) + break; + } + [tester waitForViewWithAccessibilityLabel:LOCALIZED(@"Download")]; [tester tapViewWithAccessibilityLabel:LOCALIZED(@"Download")]; [tester waitForTimeInterval:.5f]; // just wait a few secs to start download XCTAssertEqual([[[LinphoneManager instance] fileTransferDelegates] count], 1);