From f3aa0aeda354969da9ce4bffde406a3559f22934 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Wed, 16 May 2018 19:31:08 +0300 Subject: [PATCH] file transfers fixes - part 2 --- toxygen/contacts/contact.py | 14 +++++++------- toxygen/messenger/messages.py | 6 ++++++ toxygen/ui/items_factories.py | 2 +- toxygen/ui/messages_widgets.py | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/toxygen/contacts/contact.py b/toxygen/contacts/contact.py index 8c1fb06..c5c0dac 100644 --- a/toxygen/contacts/contact.py +++ b/toxygen/contacts/contact.py @@ -75,7 +75,7 @@ class Contact(basecontact.BaseContact): Get data to save in db :return: list of unsaved messages or [] """ - messages = list(filter(lambda x: x.get_type() in (MESSAGE_TYPE['NORMAL'], MESSAGE_TYPE['ACTION']), self._corr)) + messages = list(filter(lambda x: x.get_type() in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']), self._corr)) return messages[-self._unsaved_messages:] if self._unsaved_messages else [] def get_corr(self): @@ -86,11 +86,11 @@ class Contact(basecontact.BaseContact): :param message: text or file transfer message """ self._corr.append(message) - if message.get_type() in (MESSAGE_TYPE['NORMAL'], MESSAGE_TYPE['ACTION']): + if message.get_type() in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']): self._unsaved_messages += 1 def get_last_message_text(self): - messages = list(filter(lambda x: x.get_type() in (MESSAGE_TYPE['NORMAL'], MESSAGE_TYPE['ACTION']) + messages = list(filter(lambda x: x.get_type() in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']) and x.get_owner() != MESSAGE_AUTHOR['FRIEND'], self._corr)) if messages: return messages[-1].text @@ -123,7 +123,7 @@ class Contact(basecontact.BaseContact): """ :return list of unsent messages for saving """ - messages = filter(lambda x: x.get_type() in (MESSAGE_TYPE['NORMAL'], MESSAGE_TYPE['ACTION']) + messages = filter(lambda x: x.get_type() in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']) and x.get_owner() == MESSAGE_AUTHOR['NOT_SENT'], self._corr) return list(map(lambda x: x.get_data(), messages)) @@ -141,7 +141,7 @@ class Contact(basecontact.BaseContact): def delete_message(self, message_id): elem = list(filter(lambda x: type(x) in (TextMessage, GroupChatMessage) and x.message_id == message_id, self._corr))[0] - tmp = list(filter(lambda x: x.get_type() in (MESSAGE_TYPE['NORMAL'], MESSAGE_TYPE['ACTION']), self._corr)) + tmp = list(filter(lambda x: x.get_type() in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']), self._corr)) if elem in tmp[-self._unsaved_messages:] and self._unsaved_messages: self._unsaved_messages -= 1 self._corr.remove(elem) @@ -159,7 +159,7 @@ class Contact(basecontact.BaseContact): old = filter(save_message, self._corr[:-SAVE_MESSAGES]) self._corr = list(old) + self._corr[-SAVE_MESSAGES:] - text_messages = filter(lambda x: x.get_type() in (MESSAGE_TYPE['NORMAL'], MESSAGE_TYPE['ACTION']), self._corr) + text_messages = filter(lambda x: x.get_type() in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']), self._corr) self._unsaved_messages = min(self._unsaved_messages, len(list(text_messages))) self._search_index = 0 @@ -177,7 +177,7 @@ class Contact(basecontact.BaseContact): self._unsaved_messages = 0 else: self._corr = list(filter(lambda x: (x.get_type() == 2 and x.get_status() in ft.ACTIVE_FILE_TRANSFERS) - or (x.get_type() in (MESSAGE_TYPE['NORMAL'], MESSAGE_TYPE['ACTION']) + or (x.get_type() in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']) and x.get_owner() == MESSAGE_AUTHOR['NOT_SENT']), self._corr)) self._unsaved_messages = len(self.get_unsent_messages()) diff --git a/toxygen/messenger/messages.py b/toxygen/messenger/messages.py index 0dfc797..34aff38 100644 --- a/toxygen/messenger/messages.py +++ b/toxygen/messenger/messages.py @@ -164,6 +164,9 @@ class TransferMessage(Message): file_name = property(get_file_name) + def _create_widget(self, *args): + return FileTransferItem(self, *args) + class UnsentFile(Message): @@ -189,6 +192,9 @@ class InlineImage(Message): data = property(get_data) + def _create_widget(self, *args): + return InlineImageItem(self, *args) + class InfoMessage(TextMessage): diff --git a/toxygen/ui/items_factories.py b/toxygen/ui/items_factories.py index 3257279..674291c 100644 --- a/toxygen/ui/items_factories.py +++ b/toxygen/ui/items_factories.py @@ -70,7 +70,7 @@ class MessagesItemsFactory: return item def create_file_transfer_item(self, tm, append=True): - item = FileTransferItem(self._file_transfers_handler, self._settings, tm, self._messages.width()) + item = tm.get_widget(self._file_transfers_handler, self._settings, tm, self._messages.width()) elem = QtWidgets.QListWidgetItem() elem.setSizeHint(QtCore.QSize(self._messages.width() - 30, 34)) if append: diff --git a/toxygen/ui/messages_widgets.py b/toxygen/ui/messages_widgets.py index 89e4ac3..c5b2120 100644 --- a/toxygen/ui/messages_widgets.py +++ b/toxygen/ui/messages_widgets.py @@ -246,7 +246,7 @@ class FileTransferItem(QtWidgets.QListWidget): font.setPointSize(10) font.setBold(False) self.time.setFont(font) - self.time.setText(util.convert_time(time)) + self.time.setText(util.convert_time(transfer_message.time)) self.cancel = QtWidgets.QPushButton(self) self.cancel.setGeometry(QtCore.QRect(width - 125, 2, 30, 30))