From 9365ca291363311031a54f7b6ee615fa332fffa8 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 17 May 2018 21:45:35 +0300 Subject: [PATCH] file transfers fixes - part 5 --- toxygen/contacts/friend.py | 4 ++-- toxygen/file_transfers/file_transfers_handler.py | 15 ++++++++------- toxygen/ui/messages_widgets.py | 4 +++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/toxygen/contacts/friend.py b/toxygen/contacts/friend.py index 4b189a9..9c4e719 100644 --- a/toxygen/contacts/friend.py +++ b/toxygen/contacts/friend.py @@ -49,8 +49,8 @@ class Friend(contact.Contact): self._corr = list(filter(is_valid, self._corr)) - def delete_one_unsent_file(self, time): - self._corr = list(filter(lambda x: not (type(x) is UnsentFile and x.get_data()[2] == time), self._corr)) + def delete_one_unsent_file(self, message_id): + self._corr = list(filter(lambda m: not (type(m) is UnsentFile and m.message_id == message_id), self._corr)) # ----------------------------------------------------------------------------------------------------------------- # History support diff --git a/toxygen/file_transfers/file_transfers_handler.py b/toxygen/file_transfers/file_transfers_handler.py index d060ae7..4ee1282 100644 --- a/toxygen/file_transfers/file_transfers_handler.py +++ b/toxygen/file_transfers/file_transfers_handler.py @@ -81,8 +81,8 @@ class FileTransfersHandler: elif not already_cancelled: self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL']) - def cancel_not_started_transfer(self, cancel_time): - self.get_curr_friend().delete_one_unsent_file(cancel_time) + def cancel_not_started_transfer(self, friend_number, message_id): + self._get_friend_by_number(friend_number).delete_one_unsent_file(message_id) def pause_transfer(self, friend_number, file_number, by_friend=False): """ @@ -128,7 +128,8 @@ class FileTransfersHandler: def send_screenshot(self, data, friend_number): """ Send screenshot - :param data: raw data - png + :param data: raw data - png format + :param friend_number: friend number """ self.send_inline(data, 'toxygen_inline.png', friend_number) @@ -158,7 +159,7 @@ class FileTransfersHandler: """ friend = self._get_friend_by_number(friend_number) if friend.status is None and not is_resend: - m = UnsentFile(path, None, time.time()) + m = UnsentFile(path, None, util.get_unix_time()) friend.append_message(m) return elif friend.status is None and is_resend: @@ -220,9 +221,9 @@ class FileTransfersHandler: if friend_num == friend_number: ft = self._file_transfers[(friend_num, file_num)] if type(ft) is SendTransfer: - self._paused_file_transfers[ft.get_id()] = [ft.get_path(), friend_num, False, -1] + self._paused_file_transfers[ft.file_id] = [ft.path, friend_num, False, -1] elif type(ft) is ReceiveTransfer and ft.state != FILE_TRANSFER_STATE['INCOMING_NOT_STARTED']: - self._paused_file_transfers[ft.get_id()] = [ft.get_path(), friend_num, True, ft.total_size()] + self._paused_file_transfers[ft.file_id] = [ft.path, friend_num, True, ft.total_size()] self.cancel_transfer(friend_num, file_num, True) # ----------------------------------------------------------------------------------------------------------------- @@ -235,7 +236,7 @@ class FileTransfersHandler: :param avatar_path: path to avatar or None if reset """ sa = SendAvatar(avatar_path, self._tox, friend_number) - self._file_transfers[(friend_number, sa.get_file_number())] = sa + self._file_transfers[(friend_number, sa.file_number)] = sa def incoming_avatar(self, friend_number, file_number, size): """ diff --git a/toxygen/ui/messages_widgets.py b/toxygen/ui/messages_widgets.py index 5d86b64..818f766 100644 --- a/toxygen/ui/messages_widgets.py +++ b/toxygen/ui/messages_widgets.py @@ -397,9 +397,11 @@ class UnsentFileItem(FileTransferItem): movie = QtGui.QMovie(util.join_path(util.get_images_directory(), 'spinner.gif')) self.time.setMovie(movie) movie.start() + self._message_id = transfer_message.message_id + self._friend_number = transfer_message.friend_number def cancel_transfer(self, *args): - self._file_transfer_handler.cancel_not_started_transfer(self._time) + self._file_transfer_handler.cancel_not_started_transfer(self._friend_number, self._message_id) class InlineImageItem(QtWidgets.QScrollArea):