From d2fe721072e73ffe037dcca5842f4ebda16ca845 Mon Sep 17 00:00:00 2001 From: emdee Date: Wed, 12 Oct 2022 09:17:53 +0000 Subject: [PATCH] Bugfixes --- toxygen/contacts/contact_provider.py | 4 ++-- toxygen/contacts/contacts_manager.py | 19 +++++++++++++--- .../file_transfers_messages_service.py | 14 ++++++++++++ toxygen/groups/group_peer.py | 3 ++- toxygen/history/history.py | 4 +++- toxygen/messenger/messenger.py | 5 ++++- toxygen/middleware/callbacks.py | 5 +++-- toxygen/ui/items_factories.py | 19 +++++++++++++++- toxygen/ui/main_screen.py | 1 + toxygen/ui/main_screen_widgets.py | 22 ++++++++++++++----- toxygen/user_data/settings.py | 2 +- 11 files changed, 81 insertions(+), 17 deletions(-) diff --git a/toxygen/contacts/contact_provider.py b/toxygen/contacts/contact_provider.py index 33bb187..564d2fe 100644 --- a/toxygen/contacts/contact_provider.py +++ b/toxygen/contacts/contact_provider.py @@ -63,12 +63,12 @@ class ContactProvider(tox_save.ToxSave): if True: # original code public_key = self._tox.group_get_chat_id(group_number) - LOG.info(f"group_get_chat_id {group_number} {public_key}") +# LOG.info(f"group_get_chat_id {group_number} {public_key}") return self.get_group_by_public_key(public_key) else: # guessing chat_id = self._tox.group_get_chat_id(group_number) - LOG.info(f"group_get_chat_id {group_number} {chat_id}") +# LOG.info(f"group_get_chat_id {group_number} {chat_id}") group = self.get_contact_by_tox_id(chat_id) return group except Exception as e: diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index 51c65b5..1f6ddd6 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -13,7 +13,13 @@ from groups.group_peer import GroupChatPeer global LOG import logging LOG = logging.getLogger('app.'+__name__) -log = lambda x: LOG.info(x) + +def LOG_ERROR(l): print('ERROR_: '+l) +def LOG_WARN(l): print('WARN_: '+l) +def LOG_INFO(l): print('INFO_: '+l) +def LOG_DEBUG(l): print('DEBUG_: '+l) +def LOG_TRACE(l): pass # print('TRACE+ '+l) + UINT32_MAX = 2 ** 32 -1 @@ -291,7 +297,7 @@ class ContactsManager(ToxSave): group = self.get_group_by_number(group_number) peer = group.get_peer_by_id(peer_id) if peer: # broken - if not hasattr(peer, 'public_key'): + if not hasattr(peer, 'public_key') or not peer.public_key: LOG.error(f'no peer public_key ' + repr(dir(peer))) else: if not self.check_if_contact_exists(peer.public_key): @@ -547,10 +553,17 @@ class ContactsManager(ToxSave): def update_groups_numbers(self): groups = self._contact_provider.get_all_groups() - LOG.info("update_groups_numbers len(groups)={len(groups)}") + LOG.info(f"update_groups_numbers len(groups)={len(groups)}") + # Thread 76 "ToxIterateThrea" received signal SIGSEGV, Segmentation fault. for i in range(len(groups)): chat_id = self._tox.group_get_chat_id(i) + if not chat_id: + LOG.warn(f"update_groups_numbers {i} chat_id") + continue group = self.get_contact_by_tox_id(chat_id) + if not group: + LOG.warn(f"update_groups_numbers {i} group") + continue group.number = i self.update_filtration() diff --git a/toxygen/file_transfers/file_transfers_messages_service.py b/toxygen/file_transfers/file_transfers_messages_service.py index 4509183..0657fca 100644 --- a/toxygen/file_transfers/file_transfers_messages_service.py +++ b/toxygen/file_transfers/file_transfers_messages_service.py @@ -2,6 +2,15 @@ from messenger.messenger import * import utils.util as util from file_transfers.file_transfers import * +global LOG +import logging +LOG = logging.getLogger('app.'+__name__) + +def LOG_ERROR(l): print('ERROR_: '+l) +def LOG_WARN(l): print('WARN_: '+l) +def LOG_INFO(l): print('INFO_: '+l) +def LOG_DEBUG(l): print('DEBUG_: '+l) +def LOG_TRACE(l): pass # print('TRACE+ '+l) class FileTransfersMessagesService: @@ -40,8 +49,13 @@ class FileTransfersMessagesService: return tm def add_inline_message(self, transfer, index): + """callback""" if not self._is_friend_active(transfer.friend_number): return + if transfer is None or not hasattr(transfer, 'data') or \ + not transfer.data: + LOG_ERROR(f"add_inline_message empty data") + return count = self._messages.count() if count + index + 1 >= 0: self._create_inline_item(transfer.data, count + index + 1) diff --git a/toxygen/groups/group_peer.py b/toxygen/groups/group_peer.py index 4eaf255..3cd2fa7 100644 --- a/toxygen/groups/group_peer.py +++ b/toxygen/groups/group_peer.py @@ -13,7 +13,8 @@ class GroupChatPeer: self._public_key = public_key self._is_current_user = is_current_user self._is_muted = is_muted - + # unused? + self._kind = 'grouppeer' # ----------------------------------------------------------------------------------------------------------------- # Readonly properties # ----------------------------------------------------------------------------------------------------------------- diff --git a/toxygen/history/history.py b/toxygen/history/history.py index 6bab3ab..ba5680e 100644 --- a/toxygen/history/history.py +++ b/toxygen/history/history.py @@ -58,9 +58,11 @@ class History: file_name += '.' + extension history = self.generate_history(contact, as_text) + assert history with open(file_name, 'wt') as fl: fl.write(history) - + LOG.info(f"wrote history to {file_name}") + def delete_message(self, message): contact = self._contacts_manager.get_curr_contact() if message.type in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']): diff --git a/toxygen/messenger/messenger.py b/toxygen/messenger/messenger.py index b235e9e..ccc494b 100644 --- a/toxygen/messenger/messenger.py +++ b/toxygen/messenger/messenger.py @@ -25,6 +25,9 @@ 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) + def __repr__(self): + return "" + def get_last_message(self): contact = self._contacts_manager.get_curr_contact() if contact is None: @@ -67,7 +70,7 @@ class Messenger(tox_save.ToxSave): if self._contacts_manager.is_active_a_friend(): self.send_message_to_friend(text, message_type) elif self._contacts_manager.is_active_a_group(): - self.send_message_to_group(text, message_type) + self.send_message_to_group('~'+text, message_type) elif self._contacts_manager.is_active_a_group_chat_peer(): self.send_message_to_group_peer(text, message_type) diff --git a/toxygen/middleware/callbacks.py b/toxygen/middleware/callbacks.py index 8c9c618..1545ae2 100644 --- a/toxygen/middleware/callbacks.py +++ b/toxygen/middleware/callbacks.py @@ -265,8 +265,9 @@ def tox_file_recv(window, tray, profile, file_transfer_handler, contacts_manager invoke_in_main_thread(tray_notification, file_from + ' ' + friend.name, file_name, tray, window) if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']: sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER']) - icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png') - invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon)) + if tray: + icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png') + invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon)) else: # avatar LOG_DEBUG(f'file_transfer_handler Avatar') invoke_in_main_thread(file_transfer_handler.incoming_avatar, diff --git a/toxygen/ui/items_factories.py b/toxygen/ui/items_factories.py index 7346f8f..9daa1b1 100644 --- a/toxygen/ui/items_factories.py +++ b/toxygen/ui/items_factories.py @@ -44,10 +44,27 @@ class MessagesItemsFactory: self._messages.setItemWidget(elem, item) return item + +# File "/var/local/src/toxygen/toxygen/file_transfers/file_transfers_handler.py", line 216, in transfer_finished +# self._file_transfers_message_service.add_inline_message(transfer, index) +# File "/var/local/src/toxygen/toxygen/file_transfers/file_transfers_messages_service.py", line 47, in add_inline_message +# self._create_inline_item(transfer.data, count + index + 1) +# File "/var/local/src/toxygen/toxygen/file_transfers/file_transfers_messages_service.py", line 75, in _create_inline_item +# return self._messages_items_factory.create_inline_item(data, False, position) +# File "/var/local/src/toxygen/toxygen/ui/items_factories.py", line 50, in create_inline_item +# item = InlineImageItem(message.data, self._messages.width(), elem, self._messages) +# AttributeError: 'bytes' object has no attribute 'data' def create_inline_item(self, message, append=True, position=0): elem = QtWidgets.QListWidgetItem() - item = InlineImageItem(message.data, self._messages.width(), elem, self._messages) + # AttributeError: 'bytes' object has no attribute 'data' + if type(message) == bytes: + data = message + elif hasattr(message, 'data'): + data = message.data + else: + return + item = InlineImageItem(data, self._messages.width(), elem, self._messages) elem.setSizeHint(QtCore.QSize(self._messages.width(), item.height())) if append: self._messages.addItem(elem) diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index b9f62bd..dc53731 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -350,6 +350,7 @@ class MainWindow(QtWidgets.QMainWindow): self.messageEdit.setGeometry(QtCore.QRect(0, 3, 450, 55)) font = QtGui.QFont() font.setPointSize(11) + font.setBold(True) font.setFamily(self._settings['font']) self.messageEdit.setFont(font) diff --git a/toxygen/ui/main_screen_widgets.py b/toxygen/ui/main_screen_widgets.py index 122561b..623bdfc 100644 --- a/toxygen/ui/main_screen_widgets.py +++ b/toxygen/ui/main_screen_widgets.py @@ -1,7 +1,11 @@ -from PyQt5 import QtCore, QtGui, QtWidgets -from ui.widgets import RubberBandWindow, create_menu, QRightClickButton, CenteredWidget, LineEdit +# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- + import urllib import re + +from PyQt5 import QtCore, QtGui, QtWidgets + +from ui.widgets import RubberBandWindow, create_menu, QRightClickButton, CenteredWidget, LineEdit import utils.util as util import utils.ui as util_ui from stickers.stickers import load_stickers @@ -12,7 +16,8 @@ class MessageArea(QtWidgets.QPlainTextEdit): def __init__(self, parent, form): super().__init__(parent) - self._messenger = self._contacts_manager = self._file_transfer_handler = None + self._messenger = None + self._contacts_manager = self._file_transfer_handler = None self.parent = form self.setAcceptDrops(True) self._timer = QtCore.QTimer(self) @@ -31,6 +36,7 @@ class MessageArea(QtWidgets.QPlainTextEdit): self.pasteEvent(url.toString()) else: self.pasteEvent() + elif event.key() in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter): modifiers = event.modifiers() if modifiers & QtCore.Qt.ControlModifier or modifiers & QtCore.Qt.ShiftModifier: @@ -38,10 +44,16 @@ class MessageArea(QtWidgets.QPlainTextEdit): else: if self._timer.isActive(): self._timer.stop() - self._messenger.send_typing(False) - self._messenger.send_message() + try: + self._messenger.send_typing(False) + self._messenger.send_message() + except Exception as e: + util_ui.message_box(str(e), + util_ui.tr(f"ERROR send_message to {self._messenger}")) + elif event.key() == QtCore.Qt.Key_Up and not self.toPlainText(): self.appendPlainText(self._messenger.get_last_message()) + elif event.key() == QtCore.Qt.Key_Tab and self._contacts_manager.is_active_a_group(): text = self.toPlainText() text_cursor = self.textCursor() diff --git a/toxygen/user_data/settings.py b/toxygen/user_data/settings.py index f29ea89..1b516a8 100644 --- a/toxygen/user_data/settings.py +++ b/toxygen/user_data/settings.py @@ -48,7 +48,7 @@ def clean_settings(self): # overrides self['mirror_mode'] = False # REQUIRED!! - if self['ipv6_enabled'] and not os.path.exists('/proc/sys/net/ipv6'): + if not os.path.exists('/proc/sys/net/ipv6'): LOG.warn('Disabling IPV6 because /proc/sys/net/ipv6 does not exist') self['ipv6_enabled'] = False