Mercurial > libervia-backend
diff src/plugins/plugin_sec_otr.py @ 1149:652cd93dfdb4
plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 01 Sep 2014 15:45:35 +0200 |
parents | 736f1dd6e142 |
children | 39572f9d5249 |
line wrap: on
line diff
--- a/src/plugins/plugin_sec_otr.py Mon Sep 01 15:43:16 2014 +0200 +++ b/src/plugins/plugin_sec_otr.py Mon Sep 01 15:45:35 2014 +0200 @@ -190,8 +190,10 @@ self._fixPotr() # FIXME: to be removed when potr will be fixed self.host = host self.context_managers = {} + self.skipped_profiles = set() host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=100000) host.trigger.add("sendMessage", self.sendMessageTrigger, priority=100000) + host.bridge.addMethod("skipOTR", ".plugin", in_sign='s', out_sign='', method=self._skipOTR) host.importMenu((MAIN_MENU, D_("Start/Refresh")), self._startRefresh, security_limit=0, help_string=D_("Start or refresh an OTR session"), type_=C.MENU_SINGLE) host.importMenu((MAIN_MENU, D_("End session")), self._endSession, security_limit=0, help_string=D_("Finish an OTR session"), type_=C.MENU_SINGLE) host.importMenu((MAIN_MENU, D_("Authenticate")), self._authenticate, security_limit=0, help_string=D_("Authenticate user/see your fingerprint"), type_=C.MENU_SINGLE) @@ -213,8 +215,17 @@ potr.context.Account.getDefaultQueryMessage = getDefaultQueryMessage + def _skipOTR(self, profile): + """Tell the backend to not handle OTR for this profile. + + @param profile (str): %(doc_profile)s + """ + self.skipped_profiles.add(profile) + @defer.inlineCallbacks def profileConnected(self, profile): + if profile in self.skipped_profiles: + return client = self.host.getClient(profile) ctxMng = self.context_managers[profile] = ContextManager(self.host, client) client.otr_data = persistent.PersistentBinaryDict(NS_OTR, profile) @@ -227,6 +238,12 @@ ctxMng.account.privkey = None ctxMng.account.loadTrusts() + def profileDisconnected(self, profile): + try: + self.skipped_profiles.remove(profile) + except KeyError: + pass + def _startRefresh(self, menu_data, profile): """Start or refresh an OTR session @@ -398,10 +415,14 @@ raise failure.Failure(exceptions.CancelError()) # no message at all (no history, no signal) def MessageReceivedTrigger(self, message, post_treat, profile): + if profile in self.skipped_profiles: + return True post_treat.addCallback(self._receivedTreatment, profile) return True def sendMessageTrigger(self, mess_data, pre_xml_treatments, post_xml_treatments, profile): + if profile in self.skipped_profiles: + return True to_jid = mess_data['to'] if mess_data['type'] != 'groupchat' and not to_jid.resource: to_jid.resource = self.host.memory.getLastResource(to_jid, profile) # FIXME: it's dirty, but frontends don't manage resources correctly now, refactoring is planed