diff options
author | Florent Le Coz <louiz@louiz.org> | 2014-07-30 17:15:03 +0200 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2014-07-30 17:35:21 +0200 |
commit | b0accad5c0e21a2fcec329af5169f000e7c51e7f (patch) | |
tree | 1c32d141b528a3eb84dd3a02ca25ede4f3891ce6 /src/core | |
parent | 39c8319ec4c155e7323429ccbf56984d85a195a6 (diff) | |
download | poezio-b0accad5c0e21a2fcec329af5169f000e7c51e7f.tar.gz poezio-b0accad5c0e21a2fcec329af5169f000e7c51e7f.tar.bz2 poezio-b0accad5c0e21a2fcec329af5169f000e7c51e7f.tar.xz poezio-b0accad5c0e21a2fcec329af5169f000e7c51e7f.zip |
Make the bookmark stuff non-blocking
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/commands.py | 26 | ||||
-rw-r--r-- | src/core/handlers.py | 48 |
2 files changed, 43 insertions, 31 deletions
diff --git a/src/core/commands.py b/src/core/commands.py index 5254464a..5f1af49c 100644 --- a/src/core/commands.py +++ b/src/core/commands.py @@ -6,6 +6,7 @@ import logging log = logging.getLogger(__name__) +import functools import sys from datetime import datetime from gettext import gettext as _ @@ -440,7 +441,7 @@ def command_bookmark_local(self, arg=''): new_bookmarks.extend(bookmark.bookmarks) bookmark.bookmarks = new_bookmarks bookmark.save_local() - bookmark.save_remote(self.xmpp) + bookmark.save_remote(self.xmpp, None) self.information('Bookmarks added and saved.', 'Info') return else: @@ -508,12 +509,13 @@ def command_bookmark(self, arg=''): new_bookmarks.append(b) new_bookmarks.extend(bookmark.bookmarks) bookmark.bookmarks = new_bookmarks - - if bookmark.save_remote(self.xmpp): - bookmark.save_local() - self.information("Bookmarks added.", "Info") - else: - self.information("Could not add the bookmarks.", "Info") + def _cb(self, iq): + if iq["type"] != "error": + bookmark.save_local() + self.information("Bookmarks added.", "Info") + else: + self.information("Could not add the bookmarks.", "Info") + bookmark.save_remote(self.xmpp, functools.partial(_cb, self)) return else: info = safeJID(args[0]) @@ -542,14 +544,16 @@ def command_bookmark(self, arg=''): if password: bm.password = password bm.autojoin = autojoin - if bookmark.save_remote(self.xmpp): - self.information('Bookmark added.', 'Info') + def _cb(self, iq): + if iq["type"] != "error": + self.information('Bookmark added.', 'Info') + else: + self.information("Could not add the bookmarks.", "Info") + bookmark.save_remote(self.xmpp, functools.partial(_cb, self)) remote = [] for each in bookmark.bookmarks: if each.method in ('pep', 'privatexml'): remote.append(each) - self.information(_('Your remote bookmarks are now: %s') % remote, - _('Info')) def command_bookmarks(self, arg=''): """/bookmarks""" diff --git a/src/core/handlers.py b/src/core/handlers.py index 94a0614b..2dd31abd 100644 --- a/src/core/handlers.py +++ b/src/core/handlers.py @@ -869,27 +869,35 @@ def on_session_start(self, event): self.events.trigger('send_normal_presence', pres) pres.send() bookmark.get_local() + def _join_initial_rooms(bookmarks): + """Join all rooms given in the iterator `bookmarks`""" + for bm in bookmarks: + tab = self.get_tab_by_name(bm.jid, tabs.MucTab) + nick = bm.nick if bm.nick else self.own_nick + if not tab: + self.open_new_room(bm.jid, nick, False) + self.initial_joins.append(bm.jid) + histo_length = config.get('muc_history_length', 20) + if histo_length == -1: + histo_length = None + if histo_length is not None: + histo_length = str(histo_length) + # do not join rooms that do not have autojoin + # but display them anyway + if bm.autojoin: + muc.join_groupchat(self, bm.jid, nick, + passwd=bm.password, + maxhistory=histo_length, + status=self.status.message, + show=self.status.show) + def _join_remote_only(): + remote_bookmarks = (bm for bm in bookmark.bookmarks if (bm.method in ("pep", "privatexml"))) + _join_initial_rooms(remote_bookmarks) if not self.xmpp.anon and config.get('use_remote_bookmarks', True): - bookmark.get_remote(self.xmpp) - for bm in bookmark.bookmarks: - tab = self.get_tab_by_name(bm.jid, tabs.MucTab) - nick = bm.nick if bm.nick else self.own_nick - if not tab: - self.open_new_room(bm.jid, nick, False) - self.initial_joins.append(bm.jid) - histo_length = config.get('muc_history_length', 20) - if histo_length == -1: - histo_length = None - if histo_length is not None: - histo_length = str(histo_length) - # do not join rooms that do not have autojoin - # but display them anyway - if bm.autojoin: - muc.join_groupchat(self, bm.jid, nick, - passwd=bm.password, - maxhistory=histo_length, - status=self.status.message, - show=self.status.show) + bookmark.get_remote(self.xmpp, _join_remote_only) + # join all the available bookmarks. As of yet, this is just the local + # ones + _join_initial_rooms(bookmark.bookmarks) if config.get('enable_user_nick', True): self.xmpp.plugin['xep_0172'].publish_nick(nick=self.own_nick, callback=dumb_callback) |