offline messaging part 2 - read receipts
This commit is contained in:
parent
42617c8816
commit
d02ee92508
2 changed files with 22 additions and 5 deletions
|
@ -110,7 +110,7 @@ def friend_status_message(tox, friend_num, status_message, size, user_data):
|
||||||
friend = profile.get_friend_by_number(friend_num)
|
friend = profile.get_friend_by_number(friend_num)
|
||||||
invoke_in_main_thread(friend.set_status_message, status_message)
|
invoke_in_main_thread(friend.set_status_message, status_message)
|
||||||
print 'User #{} has new status: {}'.format(friend_num, status_message)
|
print 'User #{} has new status: {}'.format(friend_num, status_message)
|
||||||
profile.send_messages(friend_num)
|
invoke_in_main_thread(profile.send_messages, friend_num)
|
||||||
if profile.get_active_number() == friend_num:
|
if profile.get_active_number() == friend_num:
|
||||||
invoke_in_main_thread(profile.set_active)
|
invoke_in_main_thread(profile.set_active)
|
||||||
|
|
||||||
|
@ -148,6 +148,10 @@ def friend_request(tox, public_key, message, message_size, user_data):
|
||||||
def friend_typing(tox, friend_number, typing, user_data):
|
def friend_typing(tox, friend_number, typing, user_data):
|
||||||
invoke_in_main_thread(Profile.get_instance().friend_typing, friend_number, typing)
|
invoke_in_main_thread(Profile.get_instance().friend_typing, friend_number, typing)
|
||||||
|
|
||||||
|
|
||||||
|
def friend_read_receipt(tox, friend_number, message_id, user_data):
|
||||||
|
Profile.get_instance().get_friend_by_number(friend_number).dec_receipt()
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Callbacks - file transfers
|
# Callbacks - file transfers
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -303,6 +307,7 @@ def init_callbacks(tox, window, tray):
|
||||||
tox.callback_friend_status_message(friend_status_message, 0)
|
tox.callback_friend_status_message(friend_status_message, 0)
|
||||||
tox.callback_friend_request(friend_request, 0)
|
tox.callback_friend_request(friend_request, 0)
|
||||||
tox.callback_friend_typing(friend_typing, 0)
|
tox.callback_friend_typing(friend_typing, 0)
|
||||||
|
tox.callback_friend_read_receipt(friend_read_receipt, 0)
|
||||||
|
|
||||||
tox.callback_file_recv(tox_file_recv(window, tray), 0)
|
tox.callback_file_recv(tox_file_recv(window, tray), 0)
|
||||||
tox.callback_file_recv_chunk(file_recv_chunk, 0)
|
tox.callback_file_recv_chunk(file_recv_chunk, 0)
|
||||||
|
|
|
@ -144,6 +144,7 @@ class Friend(Contact):
|
||||||
self._corr = []
|
self._corr = []
|
||||||
self._unsaved_messages = 0
|
self._unsaved_messages = 0
|
||||||
self._history_loaded = False
|
self._history_loaded = False
|
||||||
|
self._receipts = 0
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.set_visibility(False)
|
self.set_visibility(False)
|
||||||
|
@ -155,6 +156,19 @@ class Friend(Contact):
|
||||||
# History support
|
# History support
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def get_receipts(self):
|
||||||
|
return self._receipts
|
||||||
|
|
||||||
|
receipts = property(get_receipts)
|
||||||
|
|
||||||
|
def inc_receipts(self):
|
||||||
|
self._receipts += 1
|
||||||
|
|
||||||
|
def dec_receipt(self):
|
||||||
|
if self._receipts:
|
||||||
|
self._receipts -= 1
|
||||||
|
self.mark_as_sent(False)
|
||||||
|
|
||||||
def load_corr(self, first_time=True):
|
def load_corr(self, first_time=True):
|
||||||
"""
|
"""
|
||||||
:param first_time: friend became active, load first part of messages
|
:param first_time: friend became active, load first part of messages
|
||||||
|
@ -608,13 +622,11 @@ class Profile(Contact, Singleton):
|
||||||
friend = self._friends[self._active_friend]
|
friend = self._friends[self._active_friend]
|
||||||
if friend.status is not None:
|
if friend.status is not None:
|
||||||
self.split_and_send(friend.number, message_type, text.encode('utf-8'))
|
self.split_and_send(friend.number, message_type, text.encode('utf-8'))
|
||||||
owner = MESSAGE_OWNER['ME']
|
|
||||||
else:
|
|
||||||
owner = MESSAGE_OWNER['NOT_SENT']
|
|
||||||
self.create_message_item(text, curr_time(), self._name, message_type)
|
self.create_message_item(text, curr_time(), self._name, message_type)
|
||||||
self._screen.messageEdit.clear()
|
self._screen.messageEdit.clear()
|
||||||
self._messages.scrollToBottom()
|
self._messages.scrollToBottom()
|
||||||
friend.append_message(TextMessage(text, owner, time.time(), message_type))
|
friend.append_message(TextMessage(text, MESSAGE_OWNER['NOT_SENT'], time.time(), message_type))
|
||||||
|
friend.inc_receipts()
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# History support
|
# History support
|
||||||
|
|
Loading…
Reference in a new issue