From 10f8fe2bb5f9cf1899cf9b35e5a1ef4a33f508e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Fri, 18 Aug 2017 18:52:04 +0200 Subject: [PATCH] Use unique id as action name instead of jid A jid can contain characters that are not allowed in an action name. This creates a unique UUID4 for each MessageControl and uses it as action name instead. We can reuse the UUID for other actions that belong to the MessageControl Fixes #8636 --- gajim/chat_control.py | 2 +- gajim/chat_control_base.py | 2 +- gajim/groupchat_control.py | 2 +- gajim/gui_menu_builder.py | 9 ++++----- gajim/message_control.py | 5 ++++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gajim/chat_control.py b/gajim/chat_control.py index 88a281bb9..1e2573b7e 100644 --- a/gajim/chat_control.py +++ b/gajim/chat_control.py @@ -288,7 +288,7 @@ class ChatControl(ChatControlBase): self.encryption_menu = self.xml.get_object('encryption_menu') self.encryption_menu.set_menu_model( - gui_menu_builder.get_encryption_menu(self.contact, self.type_id)) + gui_menu_builder.get_encryption_menu(self.control_id, self.type_id)) self.set_encryption_menu_icon() # restore previous conversation self.restore_conversation() diff --git a/gajim/chat_control_base.py b/gajim/chat_control_base.py index 561821527..541248af2 100644 --- a/gajim/chat_control_base.py +++ b/gajim/chat_control_base.py @@ -416,7 +416,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): def add_window_actions(self): action = Gio.SimpleAction.new_stateful( - "%s-encryptiongroup" % self.contact.jid, + "set-encryption-%s" % self.control_id, GLib.VariantType.new("s"), GLib.Variant("s", self.encryption or 'disabled')) action.connect("change-state", self.change_encryption) diff --git a/gajim/groupchat_control.py b/gajim/groupchat_control.py index e0c652f0f..656df0f49 100644 --- a/gajim/groupchat_control.py +++ b/gajim/groupchat_control.py @@ -495,7 +495,7 @@ class GroupchatControl(ChatControlBase): self.encryption_menu = self.xml.get_object('encryption_menu') self.encryption_menu.set_menu_model( - gui_menu_builder.get_encryption_menu(self.contact, self.type_id)) + gui_menu_builder.get_encryption_menu(self.control_id, self.type_id)) self.set_encryption_menu_icon() gajim.ged.register_event_handler('gc-presence-received', ged.GUI1, diff --git a/gajim/gui_menu_builder.py b/gajim/gui_menu_builder.py index 446f900b1..097bc609f 100644 --- a/gajim/gui_menu_builder.py +++ b/gajim/gui_menu_builder.py @@ -752,11 +752,10 @@ def build_bookmark_menu(account): menu.insert_submenu(1, label, bookmark_menu) -def get_encryption_menu(contact, type_id): +def get_encryption_menu(control_id, type_id): menu = Gio.Menu() menu.append( - 'Disabled', 'win.{}-encryptiongroup::{}'.format(contact.jid, - 'disabled')) + 'Disabled', 'win.set-encryption-{}::{}'.format(control_id, 'disabled')) for name, plugin in gajim.plugin_manager.encryption_plugins.items(): if type_id == 'gc': if not hasattr(plugin, 'allow_groupchat'): @@ -764,8 +763,8 @@ def get_encryption_menu(contact, type_id): if type_id == 'pm': if not hasattr(plugin, 'allow_privatchat'): continue - menu_action = 'win.{}-encryptiongroup::{}'.format( - contact.jid, name) + menu_action = 'win.set-encryption-{}::{}'.format( + control_id, name) menu.append(name, menu_action) if menu.get_n_items() == 1: return None diff --git a/gajim/message_control.py b/gajim/message_control.py index 4f75a02c0..a9e702317 100644 --- a/gajim/message_control.py +++ b/gajim/message_control.py @@ -27,6 +27,7 @@ ## import gtkgui_helpers +import uuid from common import gajim from common import helpers @@ -58,7 +59,9 @@ class MessageControl(object): self.account = account self.hide_chat_buttons = False self.resource = resource - + # control_id is a unique id for the control, + # its used as action name for actions that belong to a control + self.control_id = str(uuid.uuid4()) self.session = None gajim.last_message_time[self.account][self.get_full_jid()] = 0