From a1c8efdfb2f28976aaa653e5fc1e695b943bb739 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 10 May 2020 00:10:46 +0200 Subject: Move /deny and /remove to global scope as well --- poezio/core/commands.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++ poezio/core/completions.py | 5 +++++ poezio/core/core.py | 19 ++++++++++++++++++ 3 files changed, 74 insertions(+) (limited to 'poezio/core') diff --git a/poezio/core/commands.py b/poezio/core/commands.py index 60bcc7b0..6bf1d338 100644 --- a/poezio/core/commands.py +++ b/poezio/core/commands.py @@ -585,6 +585,56 @@ class CommandCore: roster.modified() self.core.information('%s was added to the roster' % jid, 'Roster') + @deny_anonymous + @command_args_parser.quoted(0, 1) + def deny(self, args): + """ + /deny [jid] + Denies a JID from our roster + """ + jid = None + if not args: + tab = self.core.tabs.current_tab + if isinstance(tab, tabs.RosterInfoTab): + item = tab.roster_win.selected_row + if isinstance(item, Contact): + jid = item.bare_jid + else: + jid = safeJID(args[0]).bare + if jid not in [jid for jid in roster.jids()]: + jid = None + if jid is None: + self.core.information('No subscription to deny', 'Warning') + return + + contact = roster[jid] + if contact: + contact.unauthorize() + self.core.information('Subscription to %s was revoked' % jid, + 'Roster') + + @deny_anonymous + @command_args_parser.quoted(0, 1) + def remove(self, args): + """ + Remove the specified JID from the roster. i.e.: unsubscribe + from its presence, and cancel its subscription to our. + """ + jid = None + if args: + jid = safeJID(args[0]).bare + else: + tab = self.core.tabs.current_tab + if isinstance(tab, tabs.RosterInfoTab): + item = tab.roster_win.selected_row + if isinstance(item, Contact): + jid = item.bare_jid + if jid is None: + self.core.information('No roster item to remove', 'Error') + return + roster.remove(jid) + del roster[jid] + @command_args_parser.ignored def command_reconnect(self): """ diff --git a/poezio/core/completions.py b/poezio/core/completions.py index 544a7889..ada8d2b9 100644 --- a/poezio/core/completions.py +++ b/poezio/core/completions.py @@ -52,6 +52,11 @@ class CompletionCore: ) 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 diff --git a/poezio/core/core.py b/poezio/core/core.py index a0976c3c..06d56062 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -1784,6 +1784,25 @@ class Core: ' allow you to see his presence, and allow them to' ' see your presence.', shortdesc='Add a user to your roster.') + self.register_command( + 'deny', + self.command.deny, + usage='[jid]', + desc='Deny your presence to the provided JID (or the ' + 'selected contact in your roster), who is asking' + 'you to be in their roster.', + shortdesc='Deny a user your presence.', + completion=self.completion.roster_barejids) + self.register_command( + 'remove', + self.command.remove, + usage='[jid]', + desc='Remove the specified JID from your roster. This ' + 'will unsubscribe you from its presence, cancel ' + 'its subscription to yours, and remove the item ' + 'from your roster.', + shortdesc='Remove a user from your roster.', + completion=self.completion.remove) self.register_command( 'reconnect', self.command.command_reconnect, -- cgit v1.2.3