plugin XEP-0045, XEP-0054, XEP-0096: deprecated bridge method are not used anymore

This commit is contained in:
Goffi 2016-08-28 18:20:55 +02:00
commit 0de4df1051
3 changed files with 25 additions and 23 deletions

View file

@ -65,6 +65,7 @@ default_conf = {"default_muc": u'sat@chat.jabberfr.org'}
class XEP_0045(object):
# TODO: handle invitations
def __init__(self, host):
log.info(_("Plugin XEP_0045 initialization"))

View file

@ -252,30 +252,26 @@ class XEP_0054(object):
defer.returnValue(dictionary)
def _VCardCb(self, answer, client):
def _getCardCb(self, iq_elt, to_jid, client):
"""Called after the first get IQ"""
log.debug(_("VCard found"))
if answer.firstChildElement().name == "vCard":
try:
from_jid = jid.JID(answer["from"])
except KeyError:
from_jid = client.jid.userhostJID()
d = self.vCard2Dict(client, answer.firstChildElement(), from_jid)
d.addCallback(lambda data: self.host.bridge.actionResult("RESULT", answer['id'], data, client.profile))
else:
log.error(_("FIXME: vCard not found as first child element"))
self.host.bridge.actionResult("SUPPRESS", answer['id'], {}, client.profile) # FIXME: maybe an error message would be better
def _VCardEb(self, failure, client):
"""Called when something is wrong with registration"""
try:
self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}, client.profile) # FIXME: maybe an error message would be better
log.warning(_(u"Can't find VCard of %s") % failure.value.stanza['from'])
self.updateCache(client, jid.JID(failure.value.stanza['from']), "avatar", '')
except (AttributeError, KeyError):
# 'ConnectionLost' object has no attribute 'stanza' + sometimes 'from' key doesn't exist
log.warning(_(u"Can't find VCard: %s") % failure.getErrorMessage())
vcard_elt = iq_elt.elements(NS_VCARD, "vCard").next()
except StopIteration:
log.warning(u"Can't find vCard element in answer for jid {jid}", jid=to_jid.full())
return
try:
from_jid = jid.JID(iq_elt["from"])
except KeyError:
from_jid = client.jid.userhostJID()
d = self.vCard2Dict(client, vcard_elt, from_jid)
return d
def _getCardEb(self, failure_, to_jid, client):
"""Called when something is wrong with registration"""
log.warning(u"Can't get vCard for {jid}: {failure}".format(jid=to_jid.full, failure=failure_))
self.updateCache(client, to_jid, "avatar", '')
def _getCard(self, target_s, profile_key=C.PROF_KEY_NONE):
client = self.host.getClient(profile_key)
@ -293,7 +289,7 @@ class XEP_0054(object):
reg_request["from"] = client.jid.full()
reg_request["to"] = to_jid.userhost()
reg_request.addElement('vCard', NS_VCARD)
reg_request.send(to_jid.userhost()).addCallbacks(self._VCardCb, self._VCardEb, callbackArgs=[client], errbackArgs=[client])
reg_request.send(to_jid.userhost()).addCallbacks(self._getCardCb, self._getCardEb, callbackArgs=[to_jid, client], errbackArgs=[to_jid, client])
return reg_request["id"]
def getAvatarFile(self, avatar_hash):

View file

@ -17,11 +17,12 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from sat.core.i18n import _
from sat.core.i18n import _, D_
from sat.core.constants import Const as C
from sat.core.log import getLogger
log = getLogger(__name__)
from sat.core import exceptions
from sat.tools import xml_tools
from twisted.words.xish import domish
from twisted.words.protocols.jabber import jid
from twisted.words.protocols.jabber import error
@ -333,10 +334,14 @@ class XEP_0096(object):
if stanza_err.code == '403' and stanza_err.condition == 'forbidden':
from_s = stanza_err.stanza['from']
log.info(u"File transfer refused by {}".format(from_s))
self.host.bridge.newAlert(_("The contact {} has refused your file").format(from_s), _("File refused"), "INFO", client.profile)
msg = D_(u"The contact {} has refused your file").format(from_s)
title = D_(u"File refused")
xml_tools.quickNote(self.host, client, msg, title, C.XMLUI_DATA_LVL_INFO)
else:
log.warning(_(u"Error during file transfer"))
self.host.bridge.newAlert(_(u"Something went wrong during the file transfer session initialisation: {reason}").format(reason=unicode(stanza_err)), _("File transfer error"), "ERROR", client.profile)
msg = D_(u"Something went wrong during the file transfer session initialisation: {reason}").format(reason=unicode(stanza_err))
title = D_(u"File transfer error")
xml_tools.quickNote(self.host, client, msg, title, C.XMLUI_DATA_LVL_ERROR)
elif failure.check(exceptions.DataError):
log.warning(u'Invalid stanza received')
else: