plugins XEP-0045, XEP-0249, parrot: use JID instead of unicode in many methods + class attributes
This commit is contained in:
parent
2a7bf77142
commit
d9cc2f181e
1 changed files with 58 additions and 56 deletions
|
|
@ -120,18 +120,18 @@ class XEP_0249(object):
|
|||
#TODO: check parameters validity
|
||||
self.invite(jid.JID(target), jid.JID("%s@%s" % (roomId, service)), options, profile_key)
|
||||
|
||||
def _accept(self, room, profile_key=C.PROF_KEY_NONE):
|
||||
"""
|
||||
Accept the invitation to join a MUC
|
||||
@param room: room jid as string
|
||||
def _accept(self, room_jid, profile_key=C.PROF_KEY_NONE):
|
||||
"""Accept the invitation to join a MUC.
|
||||
|
||||
@param room (jid.JID): JID of the room
|
||||
"""
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
if not profile:
|
||||
log.error(_("Profile doesn't exists !"))
|
||||
return
|
||||
log.info(_('Invitation accepted for room %(room)s [%(profile)s]') % {'room': room, 'profile': profile})
|
||||
log.info(_('Invitation accepted for room %(room)s [%(profile)s]') % {'room': room_jid.userhost(), 'profile': profile})
|
||||
_jid, xmlstream = self.host.getJidNStream(profile)
|
||||
d = self.host.plugins["XEP-0045"].join(jid.JID(room), _jid.user, {}, profile)
|
||||
d = self.host.plugins["XEP-0045"].join(room_jid, _jid.user, {}, profile)
|
||||
return d
|
||||
|
||||
def onInvitation(self, message, profile):
|
||||
|
|
@ -141,28 +141,29 @@ class XEP_0249(object):
|
|||
@profile: %(doc_profile)s
|
||||
"""
|
||||
try:
|
||||
room = message.firstChildElement()['jid']
|
||||
log.info(_('Invitation received for room %(room)s [%(profile)s]') % {'room': room, 'profile': profile})
|
||||
room_jid_s = message.firstChildElement()['jid']
|
||||
log.info(_('Invitation received for room %(room)s [%(profile)s]') % {'room': room_jid_s, 'profile': profile})
|
||||
except:
|
||||
log.error(_('Error while parsing invitation'))
|
||||
return
|
||||
from_ = message["from"]
|
||||
if room in self.host.plugins["XEP-0045"].clients[profile].joined_rooms:
|
||||
from_jid_s = message["from"]
|
||||
room_jid = jid.JID(room_jid_s)
|
||||
if room_jid in self.host.plugins["XEP-0045"].clients[profile].joined_rooms:
|
||||
log.info(_("Invitation silently discarded because user is already in the room."))
|
||||
return
|
||||
autojoin = self.host.memory.getParamA(AUTOJOIN_NAME, AUTOJOIN_KEY, profile_key=profile)
|
||||
|
||||
def accept_cb(conf_id, accepted, data, profile):
|
||||
if conf_id == room and accepted:
|
||||
self._accept(room, profile)
|
||||
if conf_id == room_jid_s and accepted:
|
||||
self._accept(room_jid, profile)
|
||||
|
||||
if autojoin == "always":
|
||||
self._accept(room, profile)
|
||||
self._accept(room_jid, profile)
|
||||
elif autojoin == "never":
|
||||
self.host.bridge.newAlert(_("An invitation from %(user)s to join the room %(room)s has been declined according to your personal settings.") % {'user': from_, 'room': room}, _("MUC invitation"), "INFO", profile)
|
||||
self.host.bridge.newAlert(_("An invitation from %(user)s to join the room %(room)s has been declined according to your personal settings.") % {'user': from_jid_s, 'room': room_jid_s}, _("MUC invitation"), "INFO", profile)
|
||||
else: # leave the default value here
|
||||
data = {"message": _("You have been invited by %(user)s to join the room %(room)s. Do you accept?") % {'user': from_, 'room': room}, "title": _("MUC invitation")}
|
||||
self.host.askConfirmation(room, "YES/NO", data, accept_cb, profile)
|
||||
data = {"message": _("You have been invited by %(user)s to join the room %(room)s. Do you accept?") % {'user': from_jid_s, 'room': room_jid_s}, "title": _("MUC invitation")}
|
||||
self.host.askConfirmation(room_jid_s, "YES/NO", data, accept_cb, profile)
|
||||
|
||||
def cmd_invite(self, mess_data, profile):
|
||||
"""invite someone in the room
|
||||
|
|
|
|||
Loading…
Reference in a new issue