plugin OTR: add bridge method skipOTR to desactivate OTR handling for a given profile

This commit is contained in:
souliane 2014-09-01 15:45:35 +02:00
commit 75c79aba58

View file

@ -190,8 +190,10 @@ class OTR(object):
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 @@ class OTR(object):
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 @@ class OTR(object):
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 @@ class OTR(object):
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