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
|
: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)
|
return list(messages)
|
||||||
|
|
||||||
def get_unsent_messages_for_saving(self):
|
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)
|
and x.author.type == MESSAGE_AUTHOR['NOT_SENT'], self._corr)
|
||||||
return list(map(lambda x: x.get_data(), messages))
|
return list(map(lambda x: x.get_data(), messages))
|
||||||
|
|
||||||
def mark_as_sent(self):
|
def mark_as_sent(self, tox_message_id):
|
||||||
try:
|
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()
|
message.mark_as_sent()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
util.log('Mark as sent ex: ' + str(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 = list(filter(lambda m: not (type(m) is UnsentFileMessage and m.message_id == message_id),
|
||||||
self._corr))
|
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
|
# Full status
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -64,6 +64,8 @@ class Message:
|
||||||
|
|
||||||
def mark_as_sent(self):
|
def mark_as_sent(self):
|
||||||
self._author.author_type = MESSAGE_AUTHOR['ME']
|
self._author.author_type = MESSAGE_AUTHOR['ME']
|
||||||
|
if self._widget is not None:
|
||||||
|
self._widget.mark_as_sent()
|
||||||
|
|
||||||
def _create_widget(self, *args):
|
def _create_widget(self, *args):
|
||||||
pass
|
pass
|
||||||
|
@ -111,7 +113,10 @@ class OutgoingTextMessage(TextMessage):
|
||||||
def get_tox_message_id(self):
|
def get_tox_message_id(self):
|
||||||
return self._tox_message_id
|
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):
|
class GroupChatMessage(TextMessage):
|
||||||
|
|
|
@ -98,10 +98,8 @@ class Messenger(tox_save.ToxSave):
|
||||||
messages = friend.get_unsent_messages()
|
messages = friend.get_unsent_messages()
|
||||||
try:
|
try:
|
||||||
for message in messages:
|
for message in messages:
|
||||||
tox_messages = self._split_message(message.text)
|
message_id = self._tox.friend_send_message(friend_number, message.type, message.text.encode('utf-8'))
|
||||||
for tox_message in tox_messages:
|
message.tox_message_id = message_id
|
||||||
self._tox.friend_send_message(friend_number, message.message_type, tox_message)
|
|
||||||
friend.inc_receipts()
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
util.log('Sending pending messages failed with ' + str(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):
|
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
|
# Typing notifications
|
||||||
|
@ -171,8 +170,7 @@ class Messenger(tox_save.ToxSave):
|
||||||
for friend in self._contacts_provider.get_all_friends():
|
for friend in self._contacts_provider.get_all_friends():
|
||||||
friend.append_message(InfoMessage(message, util.get_unix_time()))
|
friend.append_message(InfoMessage(message, util.get_unix_time()))
|
||||||
if self._contacts_manager.is_active_a_friend():
|
if self._contacts_manager.is_active_a_friend():
|
||||||
self._items_factory.create_message_item(message)
|
self._create_info_message_item(message)
|
||||||
self._screen.messages.scrollToBottom()
|
|
||||||
self._profile_name = new_name
|
self._profile_name = new_name
|
||||||
|
|
||||||
def _on_call_started(self, friend_number, audio, video, is_outgoing):
|
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")
|
text = util_ui.tr("Outgoing video call") if video else util_ui.tr("Outgoing audio call")
|
||||||
else:
|
else:
|
||||||
text = util_ui.tr("Incoming video call") if video else util_ui.tr("Incoming audio call")
|
text = util_ui.tr("Incoming video call") if video else util_ui.tr("Incoming audio call")
|
||||||
friend = self._get_friend_by_number(friend_number)
|
self._add_info_message(friend_number, text)
|
||||||
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()
|
|
||||||
|
|
||||||
def _on_call_finished(self, friend_number, is_declined):
|
def _on_call_finished(self, friend_number, is_declined):
|
||||||
text = util_ui.tr("Call declined") if is_declined else util_ui.tr("Call finished")
|
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)
|
friend = self._get_friend_by_number(friend_number)
|
||||||
message = InfoMessage(text, util.get_unix_time())
|
message = InfoMessage(text, util.get_unix_time())
|
||||||
friend.append_message(message)
|
friend.append_message(message)
|
||||||
if self._contacts_manager.is_friend_active(friend_number):
|
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._items_factory.create_message_item(message)
|
||||||
self._screen.messages.scrollToBottom()
|
self._screen.messages.scrollToBottom()
|
||||||
|
|
|
@ -1207,12 +1207,12 @@ MessageItem
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageEdit
|
MessageBrowser
|
||||||
{
|
{
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageEdit::focus
|
MessageBrowser::focus
|
||||||
{
|
{
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
@ -1222,7 +1222,7 @@ MessageItem::focus
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageEdit:hover
|
MessageBrowser:hover
|
||||||
{
|
{
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
@ -1243,7 +1243,7 @@ QPushButton:hover
|
||||||
background-color: #1E90FF;
|
background-color: #1E90FF;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageEdit
|
MessageBrowser
|
||||||
{
|
{
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
from PyQt5 import QtWidgets, QtGui, QtCore
|
|
||||||
from wrapper.toxcore_enums_and_consts import *
|
from wrapper.toxcore_enums_and_consts import *
|
||||||
import ui.widgets as widgets
|
import ui.widgets as widgets
|
||||||
import utils.ui as util_ui
|
|
||||||
import utils.util as util
|
import utils.util as util
|
||||||
import ui.menu as menu
|
import ui.menu as menu
|
||||||
import html as h
|
import html as h
|
||||||
|
|
Loading…
Reference in a new issue