toxygen/toxygen/contacts/friend.py

75 lines
3.0 KiB
Python
Raw Normal View History

from contacts import contact, common
from messenger.messages import *
2017-03-04 19:15:42 +00:00
import os
from contacts.contact_menu import *
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
"""
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
self._typing_notification_handler = common.FriendTypingNotificationHandler(number)
# -----------------------------------------------------------------------------------------------------------------
# File transfers support
# -----------------------------------------------------------------------------------------------------------------
2018-05-18 09:26:02 +00:00
def insert_inline(self, before_message_id, inline):
2016-06-08 19:53:41 +00:00
"""
Update status of active transfer and load inline if needed
"""
try:
2018-05-19 18:25:57 +00:00
tr = list(filter(lambda m: m.message_id == before_message_id, self._corr))[0]
i = self._corr.index(tr)
2016-06-08 19:53:41 +00:00
if inline: # inline was loaded
self._corr.insert(i, inline)
return i - len(self._corr)
2016-06-08 19:53:41 +00:00
except:
pass
def get_unsent_files(self):
2018-05-19 18:25:57 +00:00
messages = filter(lambda m: type(m) is UnsentFileMessage, self._corr)
return list(messages)
2016-06-14 18:47:03 +00:00
def clear_unsent_files(self):
2018-05-19 18:25:57 +00:00
self._corr = list(filter(lambda m: type(m) is not UnsentFileMessage, self._corr))
2016-06-14 18:47:03 +00:00
2018-05-18 18:07:59 +00:00
def remove_invalid_unsent_files(self):
2017-03-04 19:15:42 +00:00
def is_valid(message):
if type(message) is not UnsentFileMessage:
2017-03-04 19:15:42 +00:00
return True
2018-05-18 18:07:59 +00:00
if message.data is not None:
2017-03-04 19:15:42 +00:00
return True
2018-05-18 18:07:59 +00:00
return os.path.exists(message.path)
2017-03-04 19:15:42 +00:00
self._corr = list(filter(is_valid, self._corr))
2018-05-17 18:45:35 +00:00
def delete_one_unsent_file(self, message_id):
self._corr = list(filter(lambda m: not (type(m) is UnsentFileMessage and m.message_id == message_id),
self._corr))
2016-06-14 18:47:03 +00:00
2016-06-08 19:53:41 +00:00
# -----------------------------------------------------------------------------------------------------------------
2017-07-18 18:36:14 +00:00
# Full status
# -----------------------------------------------------------------------------------------------------------------
def get_full_status(self):
return self._status_message
# -----------------------------------------------------------------------------------------------------------------
# Typing notifications
# -----------------------------------------------------------------------------------------------------------------
def get_typing_notification_handler(self):
return self._typing_notification_handler
# -----------------------------------------------------------------------------------------------------------------
# Context menu support
# -----------------------------------------------------------------------------------------------------------------
def get_context_menu_generator(self):
return FriendMenuGenerator(self)