From 42049d6a44928b926e3b24951adddab569b767ea Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 18 May 2018 18:40:41 +0300 Subject: [PATCH] messaing fixes - receipts, faux offline messages --- toxygen/contacts/contact.py | 7 ++++--- toxygen/contacts/friend.py | 17 ----------------- toxygen/messenger/messages.py | 7 ++++++- toxygen/messenger/messenger.py | 29 ++++++++++++++--------------- toxygen/styles/dark_style.qss | 8 ++++---- toxygen/ui/messages_widgets.py | 2 -- 6 files changed, 28 insertions(+), 42 deletions(-) diff --git a/toxygen/contacts/contact.py b/toxygen/contacts/contact.py index 7faf36d..fb0267c 100644 --- a/toxygen/contacts/contact.py +++ b/toxygen/contacts/contact.py @@ -118,7 +118,7 @@ class Contact(basecontact.BaseContact): """ :return list of unsent messages """ - messages = filter(lambda x: x.author.type == MESSAGE_AUTHOR['NOT_SENT'], self._corr) + messages = filter(lambda m: m.author.type == MESSAGE_AUTHOR['NOT_SENT'], self._corr) return list(messages) def get_unsent_messages_for_saving(self): @@ -129,9 +129,10 @@ class Contact(basecontact.BaseContact): and x.author.type == MESSAGE_AUTHOR['NOT_SENT'], self._corr) return list(map(lambda x: x.get_data(), messages)) - def mark_as_sent(self): + def mark_as_sent(self, tox_message_id): try: - message = list(filter(lambda x: x.author.type == MESSAGE_AUTHOR['NOT_SENT'], self._corr))[0] + message = list(filter(lambda m: m.author.type == MESSAGE_AUTHOR['NOT_SENT'] + and m.tox_message_id == tox_message_id, self._corr))[0] message.mark_as_sent() except Exception as ex: util.log('Mark as sent ex: ' + str(ex)) diff --git a/toxygen/contacts/friend.py b/toxygen/contacts/friend.py index 63edd6a..0bc7b99 100644 --- a/toxygen/contacts/friend.py +++ b/toxygen/contacts/friend.py @@ -52,23 +52,6 @@ class Friend(contact.Contact): self._corr = list(filter(lambda m: not (type(m) is UnsentFileMessage and m.message_id == message_id), self._corr)) - # ----------------------------------------------------------------------------------------------------------------- - # History support - # ----------------------------------------------------------------------------------------------------------------- - - def get_receipts(self): - return self._receipts - - receipts = property(get_receipts) # read receipts - - def inc_receipts(self): - self._receipts += 1 - - def dec_receipt(self): - if self._receipts: - self._receipts -= 1 - self.mark_as_sent() - # ----------------------------------------------------------------------------------------------------------------- # Full status # ----------------------------------------------------------------------------------------------------------------- diff --git a/toxygen/messenger/messages.py b/toxygen/messenger/messages.py index 62f8804..85b16f7 100644 --- a/toxygen/messenger/messages.py +++ b/toxygen/messenger/messages.py @@ -64,6 +64,8 @@ class Message: def mark_as_sent(self): self._author.author_type = MESSAGE_AUTHOR['ME'] + if self._widget is not None: + self._widget.mark_as_sent() def _create_widget(self, *args): pass @@ -111,7 +113,10 @@ class OutgoingTextMessage(TextMessage): def get_tox_message_id(self): return self._tox_message_id - tox_message_id = property(get_tox_message_id) + def set_tox_message_id(self, tox_message_id): + self._tox_message_id = tox_message_id + + tox_message_id = property(get_tox_message_id, set_tox_message_id) class GroupChatMessage(TextMessage): diff --git a/toxygen/messenger/messenger.py b/toxygen/messenger/messenger.py index 8f3feb2..6042db5 100644 --- a/toxygen/messenger/messenger.py +++ b/toxygen/messenger/messenger.py @@ -98,10 +98,8 @@ class Messenger(tox_save.ToxSave): messages = friend.get_unsent_messages() try: for message in messages: - tox_messages = self._split_message(message.text) - for tox_message in tox_messages: - self._tox.friend_send_message(friend_number, message.message_type, tox_message) - friend.inc_receipts() + message_id = self._tox.friend_send_message(friend_number, message.type, message.text.encode('utf-8')) + message.tox_message_id = message_id except Exception as ex: util.log('Sending pending messages failed with ' + str(ex)) @@ -110,7 +108,8 @@ class Messenger(tox_save.ToxSave): # ----------------------------------------------------------------------------------------------------------------- def receipt(self, friend_number, message_id): - pass # TODO: process + friend = self._get_friend_by_number(friend_number) + friend.mark_as_sent(message_id) # ----------------------------------------------------------------------------------------------------------------- # Typing notifications @@ -171,8 +170,7 @@ class Messenger(tox_save.ToxSave): for friend in self._contacts_provider.get_all_friends(): friend.append_message(InfoMessage(message, util.get_unix_time())) if self._contacts_manager.is_active_a_friend(): - self._items_factory.create_message_item(message) - self._screen.messages.scrollToBottom() + self._create_info_message_item(message) self._profile_name = new_name def _on_call_started(self, friend_number, audio, video, is_outgoing): @@ -180,18 +178,19 @@ class Messenger(tox_save.ToxSave): text = util_ui.tr("Outgoing video call") if video else util_ui.tr("Outgoing audio call") else: text = util_ui.tr("Incoming video call") if video else util_ui.tr("Incoming audio call") - friend = self._get_friend_by_number(friend_number) - message = InfoMessage(text, util.get_unix_time()) - friend.append_message(message) - if self._contacts_manager.is_friend_active(friend_number): - self._items_factory.create_message_item(message) - self._screen.messages.scrollToBottom() + self._add_info_message(friend_number, text) def _on_call_finished(self, friend_number, is_declined): text = util_ui.tr("Call declined") if is_declined else util_ui.tr("Call finished") + self._add_info_message(friend_number, text) + + def _add_info_message(self, friend_number, text): friend = self._get_friend_by_number(friend_number) message = InfoMessage(text, util.get_unix_time()) friend.append_message(message) if self._contacts_manager.is_friend_active(friend_number): - self._items_factory.create_message_item(message) - self._screen.messages.scrollToBottom() + self._create_info_message_item(message) + + def _create_info_message_item(self, message): + self._items_factory.create_message_item(message) + self._screen.messages.scrollToBottom() diff --git a/toxygen/styles/dark_style.qss b/toxygen/styles/dark_style.qss index 0216f23..714f946 100644 --- a/toxygen/styles/dark_style.qss +++ b/toxygen/styles/dark_style.qss @@ -1207,12 +1207,12 @@ MessageItem border: none; } -MessageEdit +MessageBrowser { border: none; } -MessageEdit::focus +MessageBrowser::focus { border: none; } @@ -1222,7 +1222,7 @@ MessageItem::focus border: none; } -MessageEdit:hover +MessageBrowser:hover { border: none; } @@ -1243,7 +1243,7 @@ QPushButton:hover background-color: #1E90FF; } -MessageEdit +MessageBrowser { background-color: transparent; } diff --git a/toxygen/ui/messages_widgets.py b/toxygen/ui/messages_widgets.py index 9b5f1cb..f69cbfb 100644 --- a/toxygen/ui/messages_widgets.py +++ b/toxygen/ui/messages_widgets.py @@ -1,7 +1,5 @@ -from PyQt5 import QtWidgets, QtGui, QtCore from wrapper.toxcore_enums_and_consts import * import ui.widgets as widgets -import utils.ui as util_ui import utils.util as util import ui.menu as menu import html as h