identicons fixes. sending messages button fixed

This commit is contained in:
ingvar1995 2018-07-10 00:41:08 +03:00
parent d09609a5e5
commit 7aac248bf9
4 changed files with 23 additions and 8 deletions

View File

@ -148,6 +148,11 @@ class BaseContact:
return util.join_path(directory, '{}.png'.format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2])) return util.join_path(directory, '{}.png'.format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2]))
def has_avatar(self):
path = self.get_contact_avatar_path()
return util.file_exists(path)
def get_avatar_changed_event(self): def get_avatar_changed_event(self):
return self._avatar_changed_event return self._avatar_changed_event

View File

@ -296,11 +296,7 @@ class ContactsManager(ToxSave):
Adds friend to list Adds friend to list
""" """
self._tox.friend_add_norequest(tox_id) self._tox.friend_add_norequest(tox_id)
self._history.add_friend_to_db(tox_id) self._add_friend(tox_id)
friend = self._contact_provider.get_friend_by_public_key(tox_id)
self._contacts.append(friend)
friend.reset_avatar(self._settings['identicons'])
self._save_profile()
def block_user(self, tox_id): def block_user(self, tox_id):
""" """
@ -375,8 +371,7 @@ class ContactsManager(ToxSave):
else: else:
self._tox.friend_add(tox_id, message.encode('utf-8')) self._tox.friend_add(tox_id, message.encode('utf-8'))
tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2] tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2]
friend = self._contact_provider.get_friend_by_public_key(tox_id) self._add_friend(tox_id)
self._contacts.append(friend)
self.save_profile() self.save_profile()
return True return True
except Exception as ex: # wrong data except Exception as ex: # wrong data
@ -430,6 +425,8 @@ class ContactsManager(ToxSave):
self._load_groups() self._load_groups()
if len(self._contacts): if len(self._contacts):
self.set_active(0) self.set_active(0)
for contact in filter(lambda c: not c.has_avatar(), self._contacts):
contact.reset_avatar(self._settings['identicons'])
self.update_filtration() self.update_filtration()
def _load_friends(self): def _load_friends(self):
@ -477,6 +474,14 @@ class ContactsManager(ToxSave):
self._screen.account_avatar.setPixmap(pixmap.scaled(width, width, self._screen.account_avatar.setPixmap(pixmap.scaled(width, width,
QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)) QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation))
def _add_friend(self, tox_id):
self._history.add_friend_to_db(tox_id)
friend = self._contact_provider.get_friend_by_public_key(tox_id)
self._contacts.append(friend)
if not friend.has_avatar():
friend.reset_avatar(self._settings['identicons'])
self._save_profile()
def _save_profile(self): def _save_profile(self):
data = self._tox.get_savedata() data = self._tox.get_savedata()
self._profile_manager.save_profile(data) self._profile_manager.save_profile(data)

View File

@ -17,7 +17,7 @@ class MainWindow(QtWidgets.QMainWindow):
self._plugins_loader = None self._plugins_loader = None
self.setAcceptDrops(True) self.setAcceptDrops(True)
self._saved = False self._saved = False
self._profile = self._toxes = None self._profile = self._toxes = self._messenger = None
self._file_transfer_handler = self._history_loader = self._groups_service = self._calls_manager = None self._file_transfer_handler = self._history_loader = self._groups_service = self._calls_manager = None
self._should_show_group_peers_list = False self._should_show_group_peers_list = False
self.initUI() self.initUI()
@ -34,6 +34,7 @@ class MainWindow(QtWidgets.QMainWindow):
self._calls_manager = calls_manager self._calls_manager = calls_manager
self._groups_service = groups_service self._groups_service = groups_service
self._toxes = toxes self._toxes = toxes
self._messenger = messenger
self._contacts_manager.active_contact_changed.add_callback(self._new_contact_selected) self._contacts_manager.active_contact_changed.add_callback(self._new_contact_selected)
self.messageEdit.set_messenger(messenger) self.messageEdit.set_messenger(messenger)

View File

@ -102,6 +102,10 @@ def join_path(a, b):
return os.path.join(a, b) return os.path.join(a, b)
def file_exists(file_path):
return os.path.exists(file_path)
def copy(src, dest): def copy(src, dest):
if not os.path.exists(dest): if not os.path.exists(dest):
os.makedirs(dest) os.makedirs(dest)