name changing fixes
This commit is contained in:
parent
b591ac13ba
commit
6495aa9920
4 changed files with 39 additions and 33 deletions
|
@ -118,7 +118,7 @@ class Contact(basecontact.BaseContact):
|
|||
"""
|
||||
:return list of unsent messages
|
||||
"""
|
||||
messages = filter(lambda m: m.author.type == MESSAGE_AUTHOR['NOT_SENT'], self._corr)
|
||||
messages = filter(lambda m: m.author is not None and m.author.type == MESSAGE_AUTHOR['NOT_SENT'], self._corr)
|
||||
return list(messages)
|
||||
|
||||
def get_unsent_messages_for_saving(self):
|
||||
|
@ -248,6 +248,9 @@ class Contact(basecontact.BaseContact):
|
|||
def set_alias(self, alias):
|
||||
self._alias = bool(alias)
|
||||
|
||||
def has_alias(self):
|
||||
return self._alias
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Visibility in friends' list
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -219,22 +219,6 @@ class ContactsManager:
|
|||
def is_active_online(self):
|
||||
return self._active_contact + 1 and self.get_curr_contact().status is not None
|
||||
|
||||
def new_name(self, number, name):
|
||||
# TODO: move to somewhere else?
|
||||
friend = self.get_friend_by_number(number)
|
||||
tmp = friend.name
|
||||
friend.set_name(name)
|
||||
if friend.name == name and tmp != name:
|
||||
# TODO: move to friend?
|
||||
message = util_ui.tr('User {} is now known as {}')
|
||||
# message = message.format(tmp, name)
|
||||
# friend.append_message(InfoMessage(0, message, util.get_unix_time()))
|
||||
# friend.actions = True
|
||||
# if number == self.get_active_number():
|
||||
# self.create_message_item(message, time.time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
|
||||
# self._messages.scrollToBottom()
|
||||
# self.set_active(None)
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Work with friends (remove, block, set alias, get public key)
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
@ -251,7 +235,7 @@ class ContactsManager:
|
|||
if ok:
|
||||
aliases = self._settings['friends_aliases']
|
||||
if text:
|
||||
friend.name = bytes(text, 'utf-8')
|
||||
friend.name = text
|
||||
try:
|
||||
index = list(map(lambda x: x[0], aliases)).index(friend.tox_id)
|
||||
aliases[index] = (friend.tox_id, text)
|
||||
|
@ -259,7 +243,7 @@ class ContactsManager:
|
|||
aliases.append((friend.tox_id, text))
|
||||
friend.set_alias(text)
|
||||
else: # use default name
|
||||
friend.name = bytes(self._tox.friend_get_name(friend.number), 'utf-8')
|
||||
friend.name = self._tox.friend_get_name(friend.number)
|
||||
friend.set_alias('')
|
||||
try:
|
||||
index = list(map(lambda x: x[0], aliases)).index(friend.tox_id)
|
||||
|
|
|
@ -19,14 +19,6 @@ class Messenger(tox_save.ToxSave):
|
|||
calls_manager.call_started_event.add_callback(self._on_call_started)
|
||||
calls_manager.call_finished_event.add_callback(self._on_call_finished)
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Private methods
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
def _create_message_item(self, text_message):
|
||||
# pixmap = self._contacts_manager.get_curr_contact().get_pixmap()
|
||||
self._items_factory.create_message_item(text_message)
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Messaging - friends
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
@ -168,6 +160,18 @@ class Messenger(tox_save.ToxSave):
|
|||
if self._contacts_manager.is_friend_active(friend_number):
|
||||
self._screen.typing.setVisible(typing)
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Contact info updated
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
def new_friend_name(self, friend, old_name, new_name):
|
||||
if old_name == new_name or friend.has_alias():
|
||||
return
|
||||
message = util_ui.tr('User {} is now known as {}')
|
||||
message = message.format(old_name, new_name)
|
||||
friend.actions = True
|
||||
self._add_info_message(friend.number, message)
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Private methods
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
@ -206,9 +210,7 @@ class Messenger(tox_save.ToxSave):
|
|||
message = util_ui.tr('User {} is now known as {}')
|
||||
message = message.format(self._profile_name, new_name)
|
||||
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._create_info_message_item(message)
|
||||
self._add_info_message(friend.number, message)
|
||||
self._profile_name = new_name
|
||||
|
||||
def _on_call_started(self, friend_number, audio, video, is_outgoing):
|
||||
|
@ -243,3 +245,7 @@ class Messenger(tox_save.ToxSave):
|
|||
contact.append_message(text_message)
|
||||
if not contact.visibility:
|
||||
self._contacts_manager.update_filtration()
|
||||
|
||||
def _create_message_item(self, text_message):
|
||||
# pixmap = self._contacts_manager.get_curr_contact().get_pixmap()
|
||||
self._items_factory.create_message_item(text_message)
|
||||
|
|
|
@ -80,13 +80,17 @@ def friend_connection_status(contacts_manager, profile, settings, plugin_loader,
|
|||
return wrapped
|
||||
|
||||
|
||||
def friend_name(contacts_manager):
|
||||
def friend_name(contacts_provider, messenger):
|
||||
def wrapped(tox, friend_number, name, size, user_data):
|
||||
"""
|
||||
Friend changed his name
|
||||
"""
|
||||
print('New name friend #' + str(friend_number))
|
||||
invoke_in_main_thread(contacts_manager.new_name, friend_number, str(name, 'utf-8'))
|
||||
friend = contacts_provider.get_friend_by_number(friend_number)
|
||||
old_name = friend.name
|
||||
new_name = str(name, 'utf-8')
|
||||
invoke_in_main_thread(friend.set_name, new_name)
|
||||
invoke_in_main_thread(messenger.new_friend_name, friend, old_name, new_name)
|
||||
|
||||
return wrapped
|
||||
|
||||
|
@ -423,6 +427,14 @@ def group_peer_status(contacts_provider):
|
|||
return wrapped
|
||||
|
||||
|
||||
def group_topic(contacts_provider):
|
||||
def wrapped(tox, group_number, peer_id, topic, length, user_data):
|
||||
group = contacts_provider.get_group_by_number(group_number)
|
||||
topic = str(topic[:length], 'utf-8')
|
||||
invoke_in_main_thread(group.set_status_message, topic)
|
||||
|
||||
return wrapped
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Callbacks - initialization
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
@ -453,7 +465,7 @@ def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager,
|
|||
tox.callback_friend_message(friend_message(messenger, contacts_manager, profile, settings, main_window, tray), 0)
|
||||
tox.callback_friend_connection_status(friend_connection_status(contacts_manager, profile, settings, plugin_loader,
|
||||
file_transfer_handler, messenger, calls_manager), 0)
|
||||
tox.callback_friend_name(friend_name(contacts_manager), 0)
|
||||
tox.callback_friend_name(friend_name(contacts_provider, messenger), 0)
|
||||
tox.callback_friend_status_message(friend_status_message(contacts_manager, messenger), 0)
|
||||
tox.callback_friend_request(friend_request(contacts_manager), 0)
|
||||
tox.callback_friend_typing(friend_typing(messenger), 0)
|
||||
|
@ -484,3 +496,4 @@ def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager,
|
|||
tox.callback_group_peer_join(group_peer_join(contacts_provider), 0)
|
||||
tox.callback_group_peer_name(group_peer_name(contacts_provider), 0)
|
||||
tox.callback_group_peer_status(group_peer_status(contacts_provider), 0)
|
||||
tox.callback_group_topic(group_topic(contacts_provider), 0)
|
||||
|
|
Loading…
Reference in a new issue