diff options
Diffstat (limited to 'poezio/core/completions.py')
-rw-r--r-- | poezio/core/completions.py | 89 |
1 files changed, 39 insertions, 50 deletions
diff --git a/poezio/core/completions.py b/poezio/core/completions.py index ee3e95bf..084910a2 100644 --- a/poezio/core/completions.py +++ b/poezio/core/completions.py @@ -2,26 +2,23 @@ Completions for the global commands """ import logging -from typing import List, Optional - -log = logging.getLogger(__name__) - import os -from pathlib import Path from functools import reduce +from pathlib import Path +from typing import List, Optional -from slixmpp import JID +from slixmpp import JID, InvalidJID from poezio import common -from poezio import pep from poezio import tabs from poezio import xdg -from poezio.common import safeJID from poezio.config import config from poezio.roster import roster from poezio.core.structs import POSSIBLE_SHOW, Completion +log = logging.getLogger(__name__) + class CompletionCore: def __init__(self, core): @@ -44,6 +41,19 @@ class CompletionCore: ' ', quotify=False) + def roster_barejids(self, the_input): + """Complete roster bare jids""" + jids = sorted( + str(contact.bare_jid) for contact in roster.contacts.values() + if contact.pending_in + ) + return Completion(the_input.new_completion, jids, 1, '', quotify=False) + + def remove(self, the_input): + """Completion for /remove""" + jids = [jid for jid in roster.jids()] + return Completion(the_input.auto_completion, jids, '', quotify=False) + def presence(self, the_input): """ Completion of /presence @@ -70,7 +80,7 @@ class CompletionCore: def theme(self, the_input): """ Completion for /theme""" - themes_dir = config.get('themes_dir') + themes_dir = config.getstr('themes_dir') themes_dir = Path(themes_dir).expanduser( ) if themes_dir else xdg.DATA_HOME / 'themes' try: @@ -112,9 +122,12 @@ class CompletionCore: return False if len(args) == 1: args.append('') - jid = safeJID(args[1]) - if args[1].endswith('@') and not jid.user and not jid.server: - jid.user = args[1][:-1] + try: + jid = JID(args[1]) + except InvalidJID: + jid = JID('') + if args[1].endswith('@'): + jid.user = args[1][:-1] relevant_rooms = [] relevant_rooms.extend(sorted(self.core.pending_invites.keys())) @@ -137,7 +150,8 @@ class CompletionCore: for tab in self.core.get_tabs(tabs.MucTab): if tab.joined: serv_list.append( - '%s@%s' % (jid.user, safeJID(tab.name).host)) + '%s@%s' % (jid.user, tab.general_jid.server) + ) serv_list.extend(relevant_rooms) return Completion( the_input.new_completion, serv_list, 1, quotify=True) @@ -201,14 +215,13 @@ class CompletionCore: if len(args) == 1: args.append('') - jid = safeJID(args[1]) - - if jid.server and (jid.resource or jid.full.endswith('/')): + try: + jid = JID(args[1]) tab = self.core.tabs.by_name_and_class(jid.bare, tabs.MucTab) nicks = [tab.own_nick] if tab else [] default = os.environ.get('USER') if os.environ.get( 'USER') else 'poezio' - nick = config.get('default_nick') + nick = config.getstr('default_nick') if not nick: if default not in nicks: nicks.append(default) @@ -218,6 +231,8 @@ class CompletionCore: jids_list = ['%s/%s' % (jid.bare, nick) for nick in nicks] return Completion( the_input.new_completion, jids_list, 1, quotify=True) + except InvalidJID: + pass muc_list = [tab.name for tab in self.core.get_tabs(tabs.MucTab)] muc_list.sort() muc_list.append('*') @@ -305,33 +320,6 @@ class CompletionCore: comp = sorted(onlines) + sorted(offlines) return Completion(the_input.new_completion, comp, n, quotify=True) - def activity(self, the_input): - """Completion for /activity""" - n = the_input.get_argument_position(quoted=True) - args = common.shell_split(the_input.text) - if n == 1: - return Completion( - the_input.new_completion, - sorted(pep.ACTIVITIES.keys()), - n, - quotify=True) - elif n == 2: - if args[1] in pep.ACTIVITIES: - l = list(pep.ACTIVITIES[args[1]]) - l.remove('category') - l.sort() - return Completion(the_input.new_completion, l, n, quotify=True) - - def mood(self, the_input): - """Completion for /mood""" - n = the_input.get_argument_position(quoted=True) - if n == 1: - return Completion( - the_input.new_completion, - sorted(pep.MOODS.keys()), - 1, - quotify=True) - def last_activity(self, the_input): """ Completion for /last_activity <jid> @@ -444,14 +432,13 @@ class CompletionCore: return False if len(args) == 1: args.append('') - jid = safeJID(args[1]) - - if jid.server and (jid.resource or jid.full.endswith('/')): + try: + jid = JID(args[1]) tab = self.core.tabs.by_name_and_class(jid.bare, tabs.MucTab) nicks = [tab.own_nick] if tab else [] default = os.environ.get('USER') if os.environ.get( 'USER') else 'poezio' - nick = config.get('default_nick') + nick = config.getstr('default_nick') if not nick: if default not in nicks: nicks.append(default) @@ -461,6 +448,8 @@ class CompletionCore: jids_list = ['%s/%s' % (jid.bare, nick) for nick in nicks] return Completion( the_input.new_completion, jids_list, 1, quotify=True) + except InvalidJID: + pass muc_list = [tab.name for tab in self.core.get_tabs(tabs.MucTab)] muc_list.append('*') return Completion(the_input.new_completion, muc_list, 1, quotify=True) @@ -477,11 +466,11 @@ class CompletionCore: tabs.StaticConversationTab, tabs.DynamicConversationTab, ) - tabjid = [] # type: List[JID] + tabjid: List[str] = [] if isinstance(current_tab, chattabs): tabjid = [current_tab.jid.bare] - jids = roster.jids() + jids = [str(i) for i in roster.jids()] jids += tabjid return Completion( the_input.new_completion, jids, 1, '', quotify=False) |