summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-03-04 16:20:07 +0100
committermathieui <mathieui@mathieui.net>2013-03-04 16:20:07 +0100
commitd99c09ffc3fffe95ebb8a1e137df45506e467167 (patch)
tree8816a61d24898549347d4886b7d6df56e343b85e /src
parentf40cfe26699a60191ab7dfd719206ced739d3955 (diff)
downloadpoezio-d99c09ffc3fffe95ebb8a1e137df45506e467167.tar.gz
poezio-d99c09ffc3fffe95ebb8a1e137df45506e467167.tar.bz2
poezio-d99c09ffc3fffe95ebb8a1e137df45506e467167.tar.xz
poezio-d99c09ffc3fffe95ebb8a1e137df45506e467167.zip
Make /affiliation and /role non-blocking (fix #2235)
Diffstat (limited to 'src')
-rw-r--r--src/multiuserchat.py17
-rw-r--r--src/tabs.py14
2 files changed, 23 insertions, 8 deletions
diff --git a/src/multiuserchat.py b/src/multiuserchat.py
index 58d2771a..0617adda 100644
--- a/src/multiuserchat.py
+++ b/src/multiuserchat.py
@@ -91,7 +91,7 @@ def leave_groupchat(xmpp, jid, own_nick, msg):
except KeyError:
log.debug("muc.leave_groupchat: could not leave the room %s" % jid)
-def set_user_role(xmpp, jid, nick, reason, role):
+def set_user_role(xmpp, jid, nick, reason, role, callback=None):
"""
(try to) Set the role of a MUC user
(role = 'none': eject user)
@@ -107,17 +107,28 @@ def set_user_role(xmpp, jid, nick, reason, role):
query.append(item)
iq.append(query)
iq['to'] = jid
+ if callback:
+ return iq.send(block=False, callback=callback)
try:
return iq.send()
except Exception as e:
return e.iq
-def set_user_affiliation(xmpp, muc_jid, affiliation, nick=None, jid=None, reason=None):
+def set_user_affiliation(xmpp, muc_jid, affiliation, nick=None, jid=None, reason=None, callback=None):
"""
(try to) Set the affiliation of a MUC user
"""
- jid = safeJID(jid)
muc_jid = safeJID(muc_jid)
+ query = ET.Element('{http://jabber.org/protocol/muc#admin}query')
+ if nick:
+ item = ET.Element('{http://jabber.org/protocol/muc#admin}item', {'affiliation':affiliation, 'nick':nick})
+ else:
+ item = ET.Element('{http://jabber.org/protocol/muc#admin}item', {'affiliation':affiliation, 'jid':str(jid)})
+ query.append(item)
+ iq = xmpp.makeIqSet(query)
+ iq['to'] = muc_jid
+ if callback:
+ return iq.send(block=False, callback=callback)
try:
return xmpp.plugin['xep_0045'].setAffiliation(str(muc_jid), str(jid) if jid else None, nick, affiliation)
except:
diff --git a/src/tabs.py b/src/tabs.py
index 0b2cfc2e..3e7dc5f3 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -1162,6 +1162,9 @@ class MucTab(ChatTab):
Changes the role of an user
roles can be: none, visitor, participant, moderator
"""
+ def callback(iq):
+ if iq['type'] == 'error':
+ self.core.room_error(iq, self.get_name())
args = common.shell_split(arg)
if len(args) < 2:
self.core.command_help('role')
@@ -1176,9 +1179,7 @@ class MucTab(ChatTab):
return
if not safeJID(self.get_name() + '/' + nick):
return self.core('Invalid nick', 'Info')
- res = muc.set_user_role(self.core.xmpp, self.get_name(), nick, reason, role)
- if res['type'] == 'error':
- self.core.room_error(res, self.get_name())
+ muc.set_user_role(self.core.xmpp, self.get_name(), nick, reason, role, callback=callback)
def command_affiliation(self, arg):
"""
@@ -1186,6 +1187,9 @@ class MucTab(ChatTab):
Changes the affiliation of an user
affiliations can be: outcast, none, member, admin, owner
"""
+ def callback(iq):
+ if iq['type'] == 'error':
+ self.core.room_error(iq, self.get_name())
args = common.shell_split(arg)
if len(args) < 2:
self.core.command_help('affiliation')
@@ -1197,9 +1201,9 @@ class MucTab(ChatTab):
self.core.command_help('affiliation')
return
if nick in [user.nick for user in self.users]:
- res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), affiliation, nick=nick)
+ res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), affiliation, nick=nick, callback=callback)
else:
- res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), affiliation, jid=safeJID(nick))
+ res = muc.set_user_affiliation(self.core.xmpp, self.get_name(), affiliation, jid=safeJID(nick), callback=callback)
if not res:
self.core.information('Could not set affiliation', 'Error')