From 9712dcedc22c72f79a47bf3785985a630c623d03 Mon Sep 17 00:00:00 2001 From: Marin Date: Thu, 16 Jan 2014 09:40:51 +0200 Subject: [PATCH] Fixes the problem with the not working 'automatically initiate private conversation' in the Secure chat menu --- .../plugin/otr/OtrContactMenu.java | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/net/java/sip/communicator/plugin/otr/OtrContactMenu.java b/src/net/java/sip/communicator/plugin/otr/OtrContactMenu.java index dc2beb637..721e9704a 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrContactMenu.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrContactMenu.java @@ -121,25 +121,68 @@ public OtrContactMenu( OtrContact otrContact, * Since we now support OTRv3 we have to make sure that the user's * cached policy is up-to-date with the latest allowed version of the * protocol. We have to set the ALLOW_V3 bit manually for the users. + * + * UPDATE: The WHITESPACE_START_AKE bit should also be manually set + * for any user that have all three ALLOW_V bits set to 1. + * + * All of this is needed because the old users have cached otr policies + * that would not benefit from the recently updated otr functionality + * if these policies are not properly updated. */ + updateOldOtrPoliciesIfNeeded(otrContact); + + buildMenu(); + } + + private void updateOldOtrPoliciesIfNeeded(OtrContact otrContact) + { OtrPolicy policy = OtrActivator.scOtrEngine.getContactPolicy(otrContact.contact); + + /* + * This flag is used to indicate whether there are changes in the + * current policy or not. If there are not any changes then we don't + * have to access the configuration service and re-cache the policy. + * This greatly optimizes performance on big configurations. + */ + boolean isChangedFlag = false; + if (policy.getAllowV1() && policy.getAllowV2() && !policy.getAllowV3()) { policy.setAllowV3(true); + isChangedFlag = true; + } + + if (policy.getEnableManual() && !policy.getWhitespaceStartAKE()) + { + policy.setWhitespaceStartAKE(true); + isChangedFlag = true; + } + + if (isChangedFlag) + { OtrActivator.scOtrEngine.setContactPolicy(contact.contact, policy); } policy = OtrActivator.scOtrEngine.getGlobalPolicy(); + isChangedFlag = false; if (policy.getAllowV1() && policy.getAllowV2() && !policy.getAllowV3()) { policy.setAllowV3(true); - OtrActivator.scOtrEngine.setGlobalPolicy(policy); + isChangedFlag = true; } - buildMenu(); - } + if (policy.getEnableManual() && !policy.getWhitespaceStartAKE()) + { + policy.setWhitespaceStartAKE(true); + isChangedFlag = true; + } + if (isChangedFlag) + { + OtrActivator.scOtrEngine.setGlobalPolicy(policy); + } + } /* * Implements ActionListener#actionPerformed(ActionEvent). */