messaing fixes - receipts, faux offline messages
This commit is contained in:
parent
ec5bcbddec
commit
42049d6a44
6 changed files with 28 additions and 42 deletions
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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._create_info_message_item(message)
|
||||
|
||||
def _create_info_message_item(self, message):
|
||||
self._items_factory.create_message_item(message)
|
||||
self._screen.messages.scrollToBottom()
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue