Commit a1c8efdf authored by mathieui's avatar mathieui

Move /deny and /remove to global scope as well

parent e03fb0b3
...@@ -585,6 +585,56 @@ class CommandCore: ...@@ -585,6 +585,56 @@ class CommandCore:
roster.modified() roster.modified()
self.core.information('%s was added to the roster' % jid, 'Roster') 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 @command_args_parser.ignored
def command_reconnect(self): def command_reconnect(self):
""" """
......
...@@ -52,6 +52,11 @@ class CompletionCore: ...@@ -52,6 +52,11 @@ class CompletionCore:
) )
return Completion(the_input.new_completion, jids, 1, '', quotify=False) 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): def presence(self, the_input):
""" """
Completion of /presence Completion of /presence
......
...@@ -1784,6 +1784,25 @@ class Core: ...@@ -1784,6 +1784,25 @@ class Core:
' allow you to see his presence, and allow them to' ' allow you to see his presence, and allow them to'
' see your presence.', ' see your presence.',
shortdesc='Add a user to your roster.') 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( self.register_command(
'reconnect', 'reconnect',
self.command.command_reconnect, self.command.command_reconnect,
......
...@@ -72,15 +72,6 @@ class RosterInfoTab(Tab): ...@@ -72,15 +72,6 @@ class RosterInfoTab(Tab):
self.key_func["s"] = self.start_search self.key_func["s"] = self.start_search
self.key_func["S"] = self.start_search_slow self.key_func["S"] = self.start_search_slow
self.key_func["n"] = self.change_contact_name self.key_func["n"] = self.change_contact_name
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_deny)
self.register_command( self.register_command(
'name', 'name',
self.command_name, self.command_name,
...@@ -108,16 +99,6 @@ class RosterInfoTab(Tab): ...@@ -108,16 +99,6 @@ class RosterInfoTab(Tab):
desc='Remove the given JID from the given group.', desc='Remove the given JID from the given group.',
shortdesc='Remove a user from a group.', shortdesc='Remove a user from a group.',
completion=self.completion_groupremove) completion=self.completion_groupremove)
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( self.register_command(
'export', 'export',
self.command_export, self.command_export,
...@@ -559,31 +540,6 @@ class RosterInfoTab(Tab): ...@@ -559,31 +540,6 @@ class RosterInfoTab(Tab):
self.core.xmpp.plugin['xep_0077'].change_password( self.core.xmpp.plugin['xep_0077'].change_password(
args[0], callback=callback) args[0], callback=callback)
@deny_anonymous
@command_args_parser.quoted(0, 1)
def command_deny(self, args):
"""
/deny [jid]
Denies a JID from our roster
"""
if not args:
item = self.roster_win.selected_row
if isinstance(item, Contact):
jid = item.bare_jid
else:
self.core.information('No subscription to deny', 'Warning')
return
else:
jid = safeJID(args[0]).bare
if jid not in [jid for jid in roster.jids()]:
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 @deny_anonymous
@command_args_parser.quoted(1, 1) @command_args_parser.quoted(1, 1)
...@@ -779,25 +735,6 @@ class RosterInfoTab(Tab): ...@@ -779,25 +735,6 @@ class RosterInfoTab(Tab):
subscription=subscription, subscription=subscription,
callback=callback) callback=callback)
@deny_anonymous
@command_args_parser.quoted(0, 1)
def command_remove(self, args):
"""
Remove the specified JID from the roster. i.e.: unsubscribe
from its presence, and cancel its subscription to our.
"""
if args:
jid = safeJID(args[0]).bare
else:
item = self.roster_win.selected_row
if isinstance(item, Contact):
jid = item.bare_jid
else:
self.core.information('No roster item to remove', 'Error')
return
roster.remove(jid)
del roster[jid]
@deny_anonymous @deny_anonymous
@command_args_parser.quoted(0, 1) @command_args_parser.quoted(0, 1)
def command_import(self, args): def command_import(self, args):
...@@ -922,16 +859,6 @@ class RosterInfoTab(Tab): ...@@ -922,16 +859,6 @@ class RosterInfoTab(Tab):
the_input.new_completion, groups, n, '', quotify=True) the_input.new_completion, groups, n, '', quotify=True)
return False return False
def completion_deny(self, the_input):
"""
Complete the first argument from the list of the
contact with ask=='subscribe'
"""
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 refresh(self): def refresh(self):
if self.need_resize: if self.need_resize:
self.resize() self.resize()
......
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