diff --git a/toxygen/app.py b/toxygen/app.py index 7810751..4bca27c 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -107,6 +107,7 @@ class App: self._tray.hide() self._save_profile() self._settings.close() + self._unset_callbacks() self._kill_toxav() del self._tox @@ -319,6 +320,7 @@ class App: self._stop_threads(False) data = self._tox.get_savedata() self._save_profile(data) + self._unset_callbacks() self._kill_toxav() del self._tox # create new tox instance @@ -408,6 +410,9 @@ class App: self._calls_manager, self._file_transfer_handler, self._ms, self._tray, self._messenger, self._groups_service, self._contacts_provider) + def _unset_callbacks(self): + callbacks.unset_callbacks(self._tox) + def _init_profile(self): if not self._profile.has_avatar(): self._profile.reset_avatar(self._settings['identicons']) diff --git a/toxygen/contacts/contact.py b/toxygen/contacts/contact.py index ecf944d..e88acf2 100644 --- a/toxygen/contacts/contact.py +++ b/toxygen/contacts/contact.py @@ -146,8 +146,7 @@ class Contact(basecontact.BaseContact): # ----------------------------------------------------------------------------------------------------------------- def delete_message(self, message_id): - elem = list(filter(lambda m: type(m) in (TextMessage, GroupChatMessage) and m.message_id == message_id, - self._corr))[0] + elem = list(filter(lambda m: m.message_id == message_id, self._corr))[0] tmp = list(filter(lambda m: m.type in (MESSAGE_TYPE['TEXT'], MESSAGE_TYPE['ACTION']), self._corr)) if elem in tmp[-self._unsaved_messages:] and self._unsaved_messages: self._unsaved_messages -= 1 diff --git a/toxygen/contacts/contact_menu.py b/toxygen/contacts/contact_menu.py index 865e7d5..8178d31 100644 --- a/toxygen/contacts/contact_menu.py +++ b/toxygen/contacts/contact_menu.py @@ -110,7 +110,7 @@ class BaseContactMenuGenerator: (history_menu_builder .with_name(util_ui.tr('Chat history')) .with_action(util_ui.tr('Clear history'), lambda: history_loader.clear_history(self._contact) - and main_screen.messages.clear()) + or main_screen.messages.clear()) .with_action(util_ui.tr('Export as text'), lambda: history_loader.export_history(self._contact)) .with_action(util_ui.tr('Export as HTML'), lambda: history_loader.export_history(self._contact, False)) ) diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py index 50dbc87..156c409 100644 --- a/toxygen/contacts/contacts_manager.py +++ b/toxygen/contacts/contacts_manager.py @@ -90,6 +90,7 @@ class ContactsManager(ToxSave): self._screen.typing.setVisible(False) current_contact = self.get_curr_contact() if current_contact is not None: + # TODO: send when needed current_contact.typing_notification_handler.send(self._tox, False) current_contact.remove_messages_widgets() # TODO: if required self._unsubscribe_from_events(current_contact) @@ -118,6 +119,7 @@ class ContactsManager(ToxSave): self._messages_items_factory.create_inline_item(message.data) else: self._messages_items_factory.create_message_item(message) + self._messages.scrollToBottom() # if value in self._call: # self._screen.active_call() # elif value in self._incoming_calls: @@ -365,6 +367,8 @@ class ContactsManager(ToxSave): def add_group_peer(self, group, peer): contact = self._contact_provider.get_group_peer_by_id(group, peer.id) + if self.check_if_contact_exists(contact.tox_id): + return self._contacts.append(contact) contact.reset_avatar(self._settings['identicons']) self._save_profile() diff --git a/toxygen/middleware/callbacks.py b/toxygen/middleware/callbacks.py index 77a029d..5fcce03 100644 --- a/toxygen/middleware/callbacks.py +++ b/toxygen/middleware/callbacks.py @@ -604,3 +604,50 @@ def init_callbacks(tox, profile, settings, plugin_loader, contacts_manager, tox.callback_group_password(group_password(contacts_provider), 0) tox.callback_group_peer_limit(group_peer_limit(contacts_provider), 0) tox.callback_group_privacy_state(group_privacy_state(contacts_provider), 0) + + +def unset_callbacks(tox): + # self callbacks + tox.callback_self_connection_status(0) + + # friend callbacks + tox.callback_friend_status(0) + tox.callback_friend_message(0) + tox.callback_friend_connection_status(0) + tox.callback_friend_name(0) + tox.callback_friend_status_message(0) + tox.callback_friend_request(0) + tox.callback_friend_typing(0) + tox.callback_friend_read_receipt(0) + + # file transfer + tox.callback_file_recv(0) + tox.callback_file_recv_chunk(0) + tox.callback_file_chunk_request(0) + tox.callback_file_recv_control(0) + + # av + toxav = tox.AV + toxav.callback_call_state(0, 0) + toxav.callback_call(0, 0) + toxav.callback_audio_receive_frame(0, 0) + toxav.callback_video_receive_frame(0, 0) + + # custom packets + tox.callback_friend_lossless_packet(0) + tox.callback_friend_lossy_packet(0) + + # gc callbacks + tox.callback_group_message(0, 0) + tox.callback_group_private_message(0, 0) + tox.callback_group_invite(0, 0) + tox.callback_group_self_join(0, 0) + tox.callback_group_peer_join(0, 0) + tox.callback_group_peer_exit(0, 0) + tox.callback_group_peer_name(0, 0) + tox.callback_group_peer_status(0, 0) + tox.callback_group_topic(0, 0) + tox.callback_group_moderation(0, 0) + tox.callback_group_password(0, 0) + tox.callback_group_peer_limit(0, 0) + tox.callback_group_privacy_state(0, 0) diff --git a/toxygen/ui/menu.py b/toxygen/ui/menu.py index 75db280..45e8765 100644 --- a/toxygen/ui/menu.py +++ b/toxygen/ui/menu.py @@ -594,7 +594,6 @@ class InterfaceSettings(CenteredWidget): app.removeTranslator(app.translator) app.translator.load(join_path(get_translations_directory(), path)) app.installTranslator(app.translator) - self._settings.save() app_closing_setting = 0 if self.hideRadioButton.isChecked(): @@ -602,6 +601,7 @@ class InterfaceSettings(CenteredWidget): elif self.closeToTrayRadioButton.isChecked(): app_closing_setting = 2 self._settings['close_app'] = app_closing_setting + self._settings.save() if restart: util_ui.message_box(util_ui.tr('Restart app to apply settings'), util_ui.tr('Restart required')) diff --git a/toxygen/wrapper/tox.py b/toxygen/wrapper/tox.py index 6ca7741..1ba0bbc 100644 --- a/toxygen/wrapper/tox.py +++ b/toxygen/wrapper/tox.py @@ -121,6 +121,7 @@ class Tox: self.AV = ToxAV(self._tox_pointer) def __del__(self): + del self.AV Tox.libtoxcore.tox_kill(self._tox_pointer) # -----------------------------------------------------------------------------------------------------------------