From d2731268d76d3344460cee40aac926cd22c46f52 Mon Sep 17 00:00:00 2001 From: js Date: Sun, 11 May 2008 13:20:22 +0000 Subject: [PATCH] [Kjell Braden] Fix OTR for chat and GC queries for real now. --- src/gajim.py | 28 ++++++++++++++++++++++++---- src/otr_windows.py | 2 +- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/gajim.py b/src/gajim.py index d925b0e09..b54d165ab 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -286,17 +286,37 @@ class OtrlMessageAppOps: tim = time.localtime() if not no_print: - ctrl = gajim.interface.msg_win_mgr.get_control( - gajim.get_jid_without_resource(fjid), account) + ctrl = self.get_control(fjid, account) if ctrl: ctrl.print_conversation_line(u" [OTR] %s"%msg, 'status', '', None) id = gajim.logger.write('chat_msg_recv', fjid, message=msg, tim=tim) + # gajim.logger.write() only marks a message as unread (and so only + # returns an id) when fjid is a real contact (NOT if it's a GC private + # chat) if id: gajim.logger.set_read_messages([id]) + + def get_control(self, fjid, account): + # first try to get the window with the full jid + ctrl = gajim.interface.msg_win_mgr.get_control(fjid, account) + if ctrl: + # got one, be happy + return ctrl + + # otherwise try without the resource + ctrl = gajim.interface.msg_win_mgr.get_control( + gajim.get_jid_without_resource(fjid), account) + # but only use it when it is not a GC window + if ctrl and ctrl.TYPE_ID == message_control.TYPE_CHAT: + return ctrl def policy(self, opdata=None, context=None): - policy = gajim.config.get_per("contacts", - gajim.get_jid_without_resource(context.username), "otr_flags") + policy = gajim.config.get_per("contacts", context.username, + "otr_flags") + if policy <= 0: + policy = gajim.config.get_per("contacts", + gajim.get_jid_without_resource(context.username), + "otr_flags") if policy <= 0: policy = gajim.config.get_per("accounts", opdata['account'], "otr_flags") return policy diff --git a/src/otr_windows.py b/src/otr_windows.py index ac1878f92..17d73eff5 100644 --- a/src/otr_windows.py +++ b/src/otr_windows.py @@ -224,7 +224,7 @@ class ContactOtrWindow: otr_flags = gajim.config.get_per("contacts", self.contact.jid, "otr_flags") - if otr_flags > 0: + if otr_flags >= 0: self.gw("otr_default_checkbutton").set_active(0) for w in self.gw("otr_settings_vbox").get_children(): w.set_sensitive(True)