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:
# 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:

View File

@ -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()

View File

@ -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)

View File

@ -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
# -----------------------------------------------------------------------------------------------------------------

View File

@ -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']):

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_finished_event.add_callback(self._on_call_finished)
def __repr__(self):
return "<Messenger>"
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)

View File

@ -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,

View File

@ -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)

View File

@ -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)

View File

@ -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()

View File

@ -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