Commit 992fe725 authored by louiz’'s avatar louiz’

Fix a few blocking iq, and remove all block=False function arguments

parent 3ec9e80d
......@@ -33,4 +33,4 @@ class Plugin(BasePlugin):
return
iq = self.core.xmpp.makeIqGet(ito=jid.server)
iq.append(ET.Element('{jabber:iq:last}query'))
iq.send(block=False, callback=callback)
iq.send(callback=callback)
......@@ -275,7 +275,6 @@ def command_list(self, arg):
self.add_tab(list_tab, True)
cb = list_tab.on_muc_list_item_received
self.xmpp.plugin['xep_0030'].get_items(jid=server,
block=False,
callback=cb)
def command_version(self, arg):
......@@ -695,7 +694,6 @@ def command_last_activity(self, arg):
if jid == '':
return self.command_help('last_activity')
self.xmpp.plugin['xep_0012'].get_last_activity(jid,
block=False,
callback=callback)
def command_mood(self, arg):
......@@ -704,7 +702,8 @@ def command_mood(self, arg):
"""
args = common.shell_split(arg)
if not args:
return self.xmpp.plugin['xep_0107'].stop(block=False)
self.xmpp.plugin['xep_0107'].stop()
return
mood = args[0]
if mood not in pep.MOODS:
return self.information(_('%s is not a correct value for a mood.')
......@@ -714,10 +713,8 @@ def command_mood(self, arg):
text = args[1]
else:
text = None
self.xmpp.plugin['xep_0107'].publish_mood(mood,
text,
callback=dumb_callback,
block=False)
self.xmpp.plugin['xep_0107'].publish_mood(mood, text,
callback=dumb_callback)
def command_activity(self, arg):
"""
......@@ -726,7 +723,8 @@ def command_activity(self, arg):
args = common.shell_split(arg)
length = len(args)
if not length:
return self.xmpp.plugin['xep_0108'].stop(block=False)
self.xmpp.plugin['xep_0108'].stop()
return
general = args[0]
if general not in pep.ACTIVITIES:
return self.information(_('%s is not a correct value for an activity')
......@@ -746,11 +744,8 @@ def command_activity(self, arg):
return self.information(_('%s is not a correct value '
'for an activity') % specific,
_('Error'))
self.xmpp.plugin['xep_0108'].publish_activity(general,
specific,
text,
callback=dumb_callback,
block=False)
self.xmpp.plugin['xep_0108'].publish_activity(general, specific, text,
callback=dumb_callback)
def command_gaming(self, arg):
"""
......@@ -758,7 +753,8 @@ def command_gaming(self, arg):
"""
args = common.shell_split(arg)
if not args:
return self.xmpp.plugin['xep_0196'].stop(block=False)
self.xmpp.plugin['xep_0196'].stop()
return
name = args[0]
if len(args) > 1:
address = args[1]
......@@ -766,8 +762,7 @@ def command_gaming(self, arg):
address = None
return self.xmpp.plugin['xep_0196'].publish_gaming(name=name,
server_address=address,
callback=dumb_callback,
block=False)
callback=dumb_callback)
def command_invite(self, arg):
"""/invite <to> <room> [reason]"""
......@@ -956,9 +951,7 @@ def command_adhoc(self, arg):
list_tab = tabs.AdhocCommandsListTab(jid)
self.add_tab(list_tab, True)
cb = list_tab.on_list_received
self.xmpp.plugin['xep_0050'].get_commands(jid=jid,
local=False,
block=False,
self.xmpp.plugin['xep_0050'].get_commands(jid=jid, local=False,
callback=cb)
def command_self(self, arg=None):
......
......@@ -106,22 +106,7 @@ def completion_join(self, the_input):
if the_input.last_completion:
return the_input.new_completion([], 1, quotify=True)
if jid.server and not jid.user:
# no room was given: complete the node
try:
response = self.xmpp.plugin['xep_0030'].get_items(jid=jid.server, block=True, timeout=1)
except:
log.error('/join completion: Unable to get the list of rooms for %s',
jid.server,
exc_info=True)
response = None
if response:
items = response['disco_items'].get_items()
else:
return True
items = sorted('%s/%s' % (tup[0], jid.resource) for tup in items)
return the_input.new_completion(items, 1, quotify=True, override=True)
elif jid.user:
if jid.user:
# we are writing the server: complete the server
serv_list = []
for tab in self.get_tabs(tabs.MucTab):
......
......@@ -849,8 +849,8 @@ class Core(object):
self.xmpp.plugin['xep_0045'].invite(room, jid,
reason=reason or '')
self.xmpp.plugin['xep_0030'].get_info(jid=jid, block=False,
timeout=5, callback=callback)
self.xmpp.plugin['xep_0030'].get_info(jid=jid, timeout=5,
callback=callback)
def get_error_message(self, stanza, deprecated=False):
"""
......
......@@ -8,6 +8,7 @@ log = logging.getLogger(__name__)
import curses
import ssl
import time
import functools
from hashlib import sha1
from gettext import gettext as _
......@@ -48,47 +49,54 @@ def on_session_start_features(self, _):
self.xmpp.plugin['xep_0280'].enable()
self.xmpp.add_event_handler('carbon_received', self.on_carbon_received)
self.xmpp.add_event_handler('carbon_sent', self.on_carbon_sent)
features = self.xmpp.plugin['xep_0030'].get_info(jid=self.xmpp.boundjid.domain, callback=callback, block=False)
self.xmpp.plugin['xep_0030'].get_info(jid=self.xmpp.boundjid.domain,
callback=callback)
def on_carbon_received(self, message):
"""
Carbon <received/> received
"""
def ignore_message(recv):
log.debug('%s has category conference, ignoring carbon',
recv['from'].server)
def receive_message(recv):
recv['to'] = self.xmpp.boundjid.full
if recv['receipt']:
return self.on_receipt(recv)
self.on_normal_message(recv)
recv = message['carbon_received']
if (recv['from'].bare not in roster or
roster[recv['from'].bare].subscription == 'none'):
try:
if fixes.has_identity(self.xmpp, recv['from'].server,
identity='conference'):
log.debug('%s has category conference, ignoring carbon',
recv['from'].server)
return
except:
log.debug('Traceback when getting the identity of a server:',
exc_info=True)
recv['to'] = self.xmpp.boundjid.full
if recv['receipt']:
return self.on_receipt(recv)
self.on_normal_message(recv)
roster[recv['from'].bare].subscription == 'none'):
fixes.has_identity(self.xmpp, recv['from'].server,
identity='conference',
on_true=functools.partial(ignore_message, recv),
on_false=functools.partial(receive_message, recv))
return
else:
receive_message(recv)
def on_carbon_sent(self, message):
"""
Carbon <sent/> received
"""
def ignore_message(sent):
log.debug('%s has category conference, ignoring carbon',
sent['to'].server)
def send_message(sent):
sent['from'] = self.xmpp.boundjid.full
self.on_normal_message(sent)
sent = message['carbon_sent']
if (sent['to'].bare not in roster or
roster[sent['to'].bare].subscription == 'none'):
try:
if fixes.has_identity(self.xmpp, sent['to'].server,
identity='conference'):
log.debug('%s has category conference, ignoring carbon',
sent['to'].server)
return
except:
log.debug('Traceback when getting the identity of a server:',
exc_info=True)
sent['from'] = self.xmpp.boundjid.full
self.on_normal_message(sent)
fixes.has_identity(self.xmpp, sent['to'].server,
identity='conference',
on_true=functools.partial(ignore_message, sent),
on_false=functools.partial(send_message, sent))
else:
send_message(sent)
### Invites ###
......
......@@ -12,14 +12,15 @@ import logging
log = logging.getLogger(__name__)
def has_identity(xmpp, jid, identity):
try:
iq = xmpp.plugin['xep_0030'].get_info(jid=jid, block=True, timeout=1)
def has_identity(xmpp, jid, identity, on_true=None, on_false=None):
def _cb(iq):
ident = lambda x: x[0]
return identity in map(ident, iq['disco_info']['identities'])
except:
log.debug('Traceback while retrieving identity', exc_info=True)
return False
res = identity in map(ident, iq['disco_info']['identities'])
if res and on_true is not None:
on_true()
if not res and on_false is not None:
on_false()
xmpp.plugin['xep_0030'].get_info(jid=jid, callback=_cb)
def get_version(xmpp, jid, callback=None, **kwargs):
def handle_result(res):
......
......@@ -726,7 +726,7 @@ class OneToOneTab(ChatTab):
"check the features supported by the other party"
if safeJID(self.get_dest_jid()).resource:
self.core.xmpp.plugin['xep_0030'].get_info(
jid=self.get_dest_jid(), block=False, timeout=5,
jid=self.get_dest_jid(), timeout=5,
callback=self.features_checked)
def command_attention(self, message=''):
......
......@@ -187,7 +187,7 @@ class ConversationTab(OneToOneTab):
self.add_message(msg)
self.core.refresh_window()
self.core.xmpp.plugin['xep_0012'].get_last_activity(self.general_jid, block=False, callback=callback)
self.core.xmpp.plugin['xep_0012'].get_last_activity(self.general_jid, callback=callback)
@refresh_wrapper.conditional
def command_info(self, arg):
......
......@@ -175,7 +175,7 @@ class RosterInfoTab(Tab):
jid = item.bare_jid
elif isinstance(item, Resource):
jid = item.jid.bare
self.core.xmpp.plugin['xep_0191'].block(jid, block=False, callback=callback)
self.core.xmpp.plugin['xep_0191'].block(jid, callback=callback)
def completion_block(self, the_input):
"""
......@@ -202,22 +202,21 @@ class RosterInfoTab(Tab):
jid = item.bare_jid
elif isinstance(item, Resource):
jid = item.jid.bare
self.core.xmpp.plugin['xep_0191'].unblock(jid, block=False, callback=callback)
self.core.xmpp.plugin['xep_0191'].unblock(jid, callback=callback)
def completion_unblock(self, the_input):
"""
Completion for /unblock
"""
def on_result(iq):
if iq['type'] == 'error':
return
l = sorted(str(item) for item in iq['blocklist']['items'])
return the_input.new_completion(l, 1, quotify=False)
if the_input.get_argument_position():
try:
iq = self.core.xmpp.plugin['xep_0191'].get_blocked(block=True)
except Exception as e:
iq = e.iq
finally:
if iq['type'] == 'error':
return
l = sorted(str(item) for item in iq['blocklist']['items'])
return the_input.new_completion(l, 1, quotify=False)
self.core.xmpp.plugin['xep_0191'].get_blocked(callback=on_result)
return True
def command_list_blocks(self, arg=None):
"""
......@@ -235,7 +234,7 @@ class RosterInfoTab(Tab):
s = 'No blocked JIDs.'
self.core.information(s, 'Info')
self.core.xmpp.plugin['xep_0191'].get_blocked(block=False, callback=callback)
self.core.xmpp.plugin['xep_0191'].get_blocked(callback=callback)
def command_reconnect(self, args=None):
"""
......@@ -422,8 +421,8 @@ class RosterInfoTab(Tab):
if 'none' in groups:
groups.remove('none')
subscription = contact.subscription
self.core.xmpp.update_roster(jid, name=name, groups=groups, subscription=subscription,
callback=callback, block=False)
self.core.xmpp.update_roster(jid, name=name, groups=groups,
subscription=subscription, callback=callback)
def command_groupadd(self, args):
"""
......@@ -462,8 +461,8 @@ class RosterInfoTab(Tab):
self.core.information('The group could not be set.', 'Error')
log.debug('Error in groupadd:\n%s', iq)
self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription,
callback=callback, block=False)
self.core.xmpp.update_roster(jid, name=name, groups=new_groups,
subscription=subscription, callback=callback)
def command_groupmove(self, arg):
"""
......@@ -517,8 +516,8 @@ class RosterInfoTab(Tab):
self.core.information('The group could not be set')
log.debug('Error in groupmove:\n%s', iq)
self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription,
callback=callback, block=False)
self.core.xmpp.update_roster(jid, name=name, groups=new_groups,
subscription=subscription, callback=callback)
def command_groupremove(self, args):
"""
......@@ -557,8 +556,8 @@ class RosterInfoTab(Tab):
self.core.information('The group could not be set')
log.debug('Error in groupremove:\n%s', iq)
self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription,
callback=callback, block=False)
self.core.xmpp.update_roster(jid, name=name, groups=new_groups,
subscription=subscription, callback=callback)
def command_remove(self, args):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment