This commit is contained in:
emdee 2022-10-12 09:17:53 +00:00
parent fd7f2620ba
commit d2fe721072
11 changed files with 81 additions and 17 deletions

View File

@ -63,12 +63,12 @@ class ContactProvider(tox_save.ToxSave):
if True: if True:
# original code # original code
public_key = self._tox.group_get_chat_id(group_number) 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) return self.get_group_by_public_key(public_key)
else: else:
# guessing # guessing
chat_id = self._tox.group_get_chat_id(group_number) 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) group = self.get_contact_by_tox_id(chat_id)
return group return group
except Exception as e: except Exception as e:

View File

@ -13,7 +13,13 @@ from groups.group_peer import GroupChatPeer
global LOG global LOG
import logging import logging
LOG = logging.getLogger('app.'+__name__) 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 UINT32_MAX = 2 ** 32 -1
@ -291,7 +297,7 @@ class ContactsManager(ToxSave):
group = self.get_group_by_number(group_number) group = self.get_group_by_number(group_number)
peer = group.get_peer_by_id(peer_id) peer = group.get_peer_by_id(peer_id)
if peer: # broken 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))) LOG.error(f'no peer public_key ' + repr(dir(peer)))
else: else:
if not self.check_if_contact_exists(peer.public_key): if not self.check_if_contact_exists(peer.public_key):
@ -547,10 +553,17 @@ class ContactsManager(ToxSave):
def update_groups_numbers(self): def update_groups_numbers(self):
groups = self._contact_provider.get_all_groups() 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)): for i in range(len(groups)):
chat_id = self._tox.group_get_chat_id(i) 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) group = self.get_contact_by_tox_id(chat_id)
if not group:
LOG.warn(f"update_groups_numbers {i} group")
continue
group.number = i group.number = i
self.update_filtration() self.update_filtration()

View File

@ -2,6 +2,15 @@ from messenger.messenger import *
import utils.util as util import utils.util as util
from file_transfers.file_transfers import * 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: class FileTransfersMessagesService:
@ -40,8 +49,13 @@ class FileTransfersMessagesService:
return tm return tm
def add_inline_message(self, transfer, index): def add_inline_message(self, transfer, index):
"""callback"""
if not self._is_friend_active(transfer.friend_number): if not self._is_friend_active(transfer.friend_number):
return 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() count = self._messages.count()
if count + index + 1 >= 0: if count + index + 1 >= 0:
self._create_inline_item(transfer.data, count + index + 1) self._create_inline_item(transfer.data, count + index + 1)

View File

@ -13,7 +13,8 @@ class GroupChatPeer:
self._public_key = public_key self._public_key = public_key
self._is_current_user = is_current_user self._is_current_user = is_current_user
self._is_muted = is_muted self._is_muted = is_muted
# unused?
self._kind = 'grouppeer'
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Readonly properties # Readonly properties
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------

View File

@ -58,8 +58,10 @@ class History:
file_name += '.' + extension file_name += '.' + extension
history = self.generate_history(contact, as_text) history = self.generate_history(contact, as_text)
assert history
with open(file_name, 'wt') as fl: with open(file_name, 'wt') as fl:
fl.write(history) fl.write(history)
LOG.info(f"wrote history to {file_name}")
def delete_message(self, message): def delete_message(self, message):
contact = self._contacts_manager.get_curr_contact() contact = self._contacts_manager.get_curr_contact()

View File

@ -25,6 +25,9 @@ class Messenger(tox_save.ToxSave):
calls_manager.call_started_event.add_callback(self._on_call_started) calls_manager.call_started_event.add_callback(self._on_call_started)
calls_manager.call_finished_event.add_callback(self._on_call_finished) calls_manager.call_finished_event.add_callback(self._on_call_finished)
def __repr__(self):
return "<Messenger>"
def get_last_message(self): def get_last_message(self):
contact = self._contacts_manager.get_curr_contact() contact = self._contacts_manager.get_curr_contact()
if contact is None: if contact is None:
@ -67,7 +70,7 @@ class Messenger(tox_save.ToxSave):
if self._contacts_manager.is_active_a_friend(): if self._contacts_manager.is_active_a_friend():
self.send_message_to_friend(text, message_type) self.send_message_to_friend(text, message_type)
elif self._contacts_manager.is_active_a_group(): 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(): elif self._contacts_manager.is_active_a_group_chat_peer():
self.send_message_to_group_peer(text, message_type) self.send_message_to_group_peer(text, message_type)

View File

@ -265,6 +265,7 @@ 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) 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']: if settings['sound_notifications'] and profile.status != TOX_USER_STATUS['BUSY']:
sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER']) sound_notification(SOUND_NOTIFICATION['FILE_TRANSFER'])
if tray:
icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png') icon = util.join_path(util.get_images_directory(), 'icon_new_messages.png')
invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon)) invoke_in_main_thread(tray.setIcon, QtGui.QIcon(icon))
else: # avatar else: # avatar

View File

@ -45,9 +45,26 @@ class MessagesItemsFactory:
return 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): def create_inline_item(self, message, append=True, position=0):
elem = QtWidgets.QListWidgetItem() 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())) elem.setSizeHint(QtCore.QSize(self._messages.width(), item.height()))
if append: if append:
self._messages.addItem(elem) self._messages.addItem(elem)

View File

@ -350,6 +350,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.messageEdit.setGeometry(QtCore.QRect(0, 3, 450, 55)) self.messageEdit.setGeometry(QtCore.QRect(0, 3, 450, 55))
font = QtGui.QFont() font = QtGui.QFont()
font.setPointSize(11) font.setPointSize(11)
font.setBold(True)
font.setFamily(self._settings['font']) font.setFamily(self._settings['font'])
self.messageEdit.setFont(font) self.messageEdit.setFont(font)

View File

@ -1,7 +1,11 @@
from PyQt5 import QtCore, QtGui, QtWidgets # -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
from ui.widgets import RubberBandWindow, create_menu, QRightClickButton, CenteredWidget, LineEdit
import urllib import urllib
import re 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.util as util
import utils.ui as util_ui import utils.ui as util_ui
from stickers.stickers import load_stickers from stickers.stickers import load_stickers
@ -12,7 +16,8 @@ class MessageArea(QtWidgets.QPlainTextEdit):
def __init__(self, parent, form): def __init__(self, parent, form):
super().__init__(parent) 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.parent = form
self.setAcceptDrops(True) self.setAcceptDrops(True)
self._timer = QtCore.QTimer(self) self._timer = QtCore.QTimer(self)
@ -31,6 +36,7 @@ class MessageArea(QtWidgets.QPlainTextEdit):
self.pasteEvent(url.toString()) self.pasteEvent(url.toString())
else: else:
self.pasteEvent() self.pasteEvent()
elif event.key() in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter): elif event.key() in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter):
modifiers = event.modifiers() modifiers = event.modifiers()
if modifiers & QtCore.Qt.ControlModifier or modifiers & QtCore.Qt.ShiftModifier: if modifiers & QtCore.Qt.ControlModifier or modifiers & QtCore.Qt.ShiftModifier:
@ -38,10 +44,16 @@ class MessageArea(QtWidgets.QPlainTextEdit):
else: else:
if self._timer.isActive(): if self._timer.isActive():
self._timer.stop() self._timer.stop()
try:
self._messenger.send_typing(False) self._messenger.send_typing(False)
self._messenger.send_message() 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(): elif event.key() == QtCore.Qt.Key_Up and not self.toPlainText():
self.appendPlainText(self._messenger.get_last_message()) self.appendPlainText(self._messenger.get_last_message())
elif event.key() == QtCore.Qt.Key_Tab and self._contacts_manager.is_active_a_group(): elif event.key() == QtCore.Qt.Key_Tab and self._contacts_manager.is_active_a_group():
text = self.toPlainText() text = self.toPlainText()
text_cursor = self.textCursor() text_cursor = self.textCursor()

View File

@ -48,7 +48,7 @@ def clean_settings(self):
# overrides # overrides
self['mirror_mode'] = False self['mirror_mode'] = False
# REQUIRED!! # 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') LOG.warn('Disabling IPV6 because /proc/sys/net/ipv6 does not exist')
self['ipv6_enabled'] = False self['ipv6_enabled'] = False