2018-05-01 13:39:09 +00:00
|
|
|
from contacts import contact, common
|
2018-01-26 20:21:46 +00:00
|
|
|
from messenger.messages import *
|
2017-03-04 19:15:42 +00:00
|
|
|
import os
|
2016-06-08 19:53:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Friend(contact.Contact):
|
|
|
|
"""
|
2016-10-24 21:10:11 +00:00
|
|
|
Friend in list of friends.
|
2016-06-08 19:53:41 +00:00
|
|
|
"""
|
|
|
|
|
2018-04-18 20:55:51 +00:00
|
|
|
def __init__(self, profile_manager, message_getter, number, name, status_message, widget, tox_id):
|
|
|
|
super().__init__(profile_manager, message_getter, number, name, status_message, widget, tox_id)
|
2016-06-08 19:53:41 +00:00
|
|
|
self._receipts = 0
|
2018-05-01 13:39:09 +00:00
|
|
|
self._typing_notification_handler = common.FriendTypingNotificationHandler(number)
|
2016-06-15 12:38:42 +00:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# File transfers support
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-06-08 19:53:41 +00:00
|
|
|
def update_transfer_data(self, file_number, status, inline=None):
|
|
|
|
"""
|
|
|
|
Update status of active transfer and load inline if needed
|
|
|
|
"""
|
|
|
|
try:
|
2016-06-21 11:58:11 +00:00
|
|
|
tr = list(filter(lambda x: x.get_type() == MESSAGE_TYPE['FILE_TRANSFER'] and x.is_active(file_number),
|
2016-10-22 21:43:18 +00:00
|
|
|
self._corr))[0]
|
2016-06-08 19:53:41 +00:00
|
|
|
tr.set_status(status)
|
2016-06-16 21:10:26 +00:00
|
|
|
i = self._corr.index(tr)
|
2016-06-08 19:53:41 +00:00
|
|
|
if inline: # inline was loaded
|
|
|
|
self._corr.insert(i, inline)
|
2016-06-16 21:10:26 +00:00
|
|
|
return i - len(self._corr)
|
2016-06-08 19:53:41 +00:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2016-06-15 12:38:42 +00:00
|
|
|
def get_unsent_files(self):
|
|
|
|
messages = filter(lambda x: type(x) is UnsentFile, self._corr)
|
|
|
|
return messages
|
2016-06-14 18:47:03 +00:00
|
|
|
|
2016-06-15 12:38:42 +00:00
|
|
|
def clear_unsent_files(self):
|
2016-06-21 11:58:11 +00:00
|
|
|
self._corr = list(filter(lambda x: type(x) is not UnsentFile, self._corr))
|
2016-06-14 18:47:03 +00:00
|
|
|
|
2017-03-04 19:15:42 +00:00
|
|
|
def remove_invalid_unsent_files(self):
|
|
|
|
def is_valid(message):
|
|
|
|
if type(message) is not UnsentFile:
|
|
|
|
return True
|
|
|
|
if message.get_data()[1] is not None:
|
|
|
|
return True
|
|
|
|
return os.path.exists(message.get_data()[0])
|
|
|
|
self._corr = list(filter(is_valid, self._corr))
|
|
|
|
|
2016-06-15 12:38:42 +00:00
|
|
|
def delete_one_unsent_file(self, time):
|
2016-06-21 11:58:11 +00:00
|
|
|
self._corr = list(filter(lambda x: not (type(x) is UnsentFile and x.get_data()[2] == time), self._corr))
|
2016-06-14 18:47:03 +00:00
|
|
|
|
2016-06-08 19:53:41 +00:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
2016-10-22 18:23:03 +00:00
|
|
|
# History support
|
2016-06-08 19:53:41 +00:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-10-22 18:23:03 +00:00
|
|
|
def get_receipts(self):
|
|
|
|
return self._receipts
|
2016-06-08 19:53:41 +00:00
|
|
|
|
2016-10-22 18:23:03 +00:00
|
|
|
receipts = property(get_receipts) # read receipts
|
2016-06-08 19:53:41 +00:00
|
|
|
|
2016-10-22 18:23:03 +00:00
|
|
|
def inc_receipts(self):
|
|
|
|
self._receipts += 1
|
2016-06-08 19:53:41 +00:00
|
|
|
|
2016-10-22 18:23:03 +00:00
|
|
|
def dec_receipt(self):
|
|
|
|
if self._receipts:
|
|
|
|
self._receipts -= 1
|
|
|
|
self.mark_as_sent()
|
2017-07-18 18:36:14 +00:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Full status
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def get_full_status(self):
|
|
|
|
return self._status_message
|
2018-05-01 13:39:09 +00:00
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Typing notifications
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def get_typing_notification_handler(self):
|
|
|
|
return self._typing_notification_handler
|