From 4ecf666b2f5f66bf7563d6234b9e1f03308b9eed Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 9 Aug 2018 23:30:05 +0300 Subject: [PATCH] various fixes --- toxygen/contacts/contact.py | 2 +- toxygen/history/history.py | 2 +- toxygen/messenger/messenger.py | 3 ++- toxygen/ui/main_screen.py | 8 +------- toxygen/utils/util.py | 1 + toxygen/wrapper/libtox.py | 28 +++++++++++++++------------- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/toxygen/contacts/contact.py b/toxygen/contacts/contact.py index 418ac15..ecf944d 100644 --- a/toxygen/contacts/contact.py +++ b/toxygen/contacts/contact.py @@ -135,7 +135,7 @@ class Contact(basecontact.BaseContact): def mark_as_sent(self, tox_message_id): try: - message = list(filter(lambda m: m.author.type == MESSAGE_AUTHOR['NOT_SENT'] + message = list(filter(lambda m: m.author is not None and m.author.type == MESSAGE_AUTHOR['NOT_SENT'] and m.tox_message_id == tox_message_id, self._corr))[0] message.mark_as_sent() except Exception as ex: diff --git a/toxygen/history/history.py b/toxygen/history/history.py index c430117..4850f7d 100644 --- a/toxygen/history/history.py +++ b/toxygen/history/history.py @@ -48,7 +48,7 @@ class History: def delete_message(self, message): contact = self._contacts_manager.get_curr_contact() - if message.type in (MESSAGE_TYPE['NORMAL'], MESSAGE_TYPE['ACTION']): + if message.type in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']): if message.is_saved(): self._db.delete_message(contact.tox_id, message.id) contact.delete_message(message.message_id) diff --git a/toxygen/messenger/messenger.py b/toxygen/messenger/messenger.py index cce619d..9ee86dd 100644 --- a/toxygen/messenger/messenger.py +++ b/toxygen/messenger/messenger.py @@ -224,7 +224,8 @@ class Messenger(tox_save.ToxSave): return message = util_ui.tr('User {} is now known as {}') message = message.format(old_name, new_name) - friend.actions = True + if self._contacts_manager.is_friend_active(friend.number): + friend.actions = True self._add_info_message(friend.number, message) # ----------------------------------------------------------------------------------------------------------------- diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index 9b80576..7b2b17d 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -645,7 +645,7 @@ class MainWindow(QtWidgets.QMainWindow): self._contacts_manager.delete_friend(num) def block_friend(self, num): - friend = self._contacts_managere.get_contact(num) + friend = self._contacts_manager.get_contact(num) self._contacts_manager.block_user(friend.tox_id) @staticmethod @@ -656,12 +656,6 @@ class MainWindow(QtWidgets.QMainWindow): def clear_history(self, num): self._contacts_manager.clear_history(num) - def leave_gc(self, num): - self.profile.leave_gc(num) - - def set_title(self, num): - self.profile.set_title(num) - def auto_accept(self, num, value): tox_id = self._contacts_manager.friend_public_key(num) if value: diff --git a/toxygen/utils/util.py b/toxygen/utils/util.py index 3c6910e..5bd5c3a 100644 --- a/toxygen/utils/util.py +++ b/toxygen/utils/util.py @@ -165,5 +165,6 @@ def is_re_valid(regex): return True +@cached def get_platform(): return platform.system() diff --git a/toxygen/wrapper/libtox.py b/toxygen/wrapper/libtox.py index d5f599a..01d41f1 100644 --- a/toxygen/wrapper/libtox.py +++ b/toxygen/wrapper/libtox.py @@ -1,4 +1,3 @@ -from platform import system from ctypes import CDLL import utils.util as util @@ -6,16 +5,17 @@ import utils.util as util class LibToxCore: def __init__(self): - if system() == 'Windows': - self._libtoxcore = CDLL(util.curr_directory() + '/libs/libtox.dll') - elif system() == 'Darwin': + platform = util.get_platform() + if platform == 'Windows': + self._libtoxcore = CDLL(util.join_path(util.get_libs_directory(), 'libtox.dll')) + elif platform == 'Darwin': self._libtoxcore = CDLL('libtoxcore.dylib') else: # libtoxcore and libsodium must be installed in your os try: self._libtoxcore = CDLL('libtoxcore.so') except: - self._libtoxcore = CDLL(util.curr_directory() + '/libs/libtoxcore.so') + self._libtoxcore = CDLL(util.join_path(util.get_libs_directory(), 'libtoxcore.so')) def __getattr__(self, item): return self._libtoxcore.__getattr__(item) @@ -24,17 +24,18 @@ class LibToxCore: class LibToxAV: def __init__(self): - if system() == 'Windows': + platform = util.get_platform() + if platform == 'Windows': # on Windows av api is in libtox.dll - self._libtoxav = CDLL(util.curr_directory() + '/libs/libtox.dll') - elif system() == 'Darwin': + self._libtoxav = CDLL(util.join_path(util.get_libs_directory(), 'libtox.dll')) + elif platform == 'Darwin': self._libtoxav = CDLL('libtoxcore.dylib') else: # /usr/lib/libtoxcore.so must exists try: self._libtoxav = CDLL('libtoxcore.so') except: - self._libtoxav = CDLL(util.curr_directory() + '/libs/libtoxcore.so') + self._libtoxav = CDLL(util.join_path(util.get_libs_directory(), 'libtoxcore.so')) def __getattr__(self, item): return self._libtoxav.__getattr__(item) @@ -43,17 +44,18 @@ class LibToxAV: class LibToxEncryptSave: def __init__(self): - if system() == 'Windows': + platform = util.get_platform() + if platform == 'Windows': # on Windows profile encryption api is in libtox.dll - self._lib_tox_encrypt_save = CDLL(util.curr_directory() + '/libs/libtox.dll') - elif system() == 'Darwin': + self._lib_tox_encrypt_save = CDLL(util.join_path(util.get_libs_directory(), 'libtox.dll')) + elif platform == 'Darwin': self._lib_tox_encrypt_save = CDLL('libtoxcore.dylib') else: # /usr/lib/libtoxcore.so must exists try: self._lib_tox_encrypt_save = CDLL('libtoxcore.so') except: - self._lib_tox_encrypt_save = CDLL(util.curr_directory() + '/libs/libtoxcore.so') + self._lib_tox_encrypt_save = CDLL(util.join_path(util.get_libs_directory(), 'libtoxcore.so')) def __getattr__(self, item): return self._lib_tox_encrypt_save.__getattr__(item)