Commit dd55845a authored by Madhur Garg's avatar Madhur Garg

Corrects the functionality of /add and /accept commands in all the tabs. Fixes #3395

Corrects the functionality of /add command in all tabs. Fixes #3395

Removed trailing whitespaces

Corrected general way of writing code.

Corrects the functionality of /add and /accept commands in all tabs. Fixes #3395
parent b5cca868
......@@ -23,6 +23,8 @@ from poezio.bookmarks import Bookmark
from poezio.common import safeJID
from poezio.config import config, DEFAULT_CONFIG, options as config_opts
from poezio import multiuserchat as muc
from poezio.contact import Contact
from poezio import windows
from poezio.plugin import PluginConfig
from poezio.roster import roster
from poezio.theming import dump_tuple, get_theme
......@@ -508,7 +510,43 @@ class CommandCore:
self.core.bookmarks.save(self.core.xmpp, callback=cb)
else:
self.core.information('No bookmark to remove', 'Info')
@command_args_parser.quoted(0, 1)
def command_accept(self, args):
"""
Accept a JID. Authorize it AND subscribe to it
"""
if not args:
tab = self.core.tabs.current_tab
RosterInfoTab = tabs.RosterInfoTab
if not isinstance(tab, RosterInfoTab):
return self.core.information('No JID specified', 'Error')
else:
item = tab.selected_row
if isinstance(item, Contact):
jid = item.bare_jid
else:
return self.core.information('No subscription to accept', 'Warning')
else:
jid = safeJID(args[0]).bare
nodepart = safeJID(jid).user
jid = safeJID(jid)
# crappy transports putting resources inside the node part
if '\\2f' in nodepart:
jid.user = nodepart.split('\\2f')[0]
contact = roster[jid]
if contact is None:
return self.core.information('No subscription to accept', 'Warning')
contact.pending_in = False
roster.modified()
self.core.xmpp.send_presence(pto=jid, ptype='subscribed')
self.core.xmpp.client_roster.send_last_presence()
if contact.subscription in ('from',
'none') and not contact.pending_out:
self.core.xmpp.send_presence(
pto=jid, ptype='subscribe', pnick=self.core.own_nick)
self.core.information('%s is now authorized' % jid, 'Roster')
@command_args_parser.quoted(1)
def command_add(self, args):
"""
......@@ -516,17 +554,17 @@ class CommandCore:
accept the reverse subscription
"""
if args is None:
jid = self.core.tabs.current_tab.name
if jid is 'Roster' or 'muc' in jid:
self.core.information('No JID specified', 'Error')
return
else:
tab = self.core.tabs.current_tab
ConversationTab = tabs.ConversationTab
if isinstance(tab, ConversationTab):
jid = tab.general_jid
if jid in roster and roster[jid].subscription in ('to', 'both'):
return self.core.information('Already subscribed.', 'Roster')
roster.add(jid)
roster.modified()
self.core.information('%s was added to the roster' % jid, 'Roster')
return
return self.core.information('%s was added to the roster' % jid, 'Roster')
else:
return self.core.information('No JID specified', 'Error')
jid = safeJID(safeJID(args[0]).bare)
if not str(jid):
self.core.information(
......
......@@ -1758,6 +1758,13 @@ class Core:
"currently using in this room (instead of default_nick).",
shortdesc="Bookmark a room online.",
completion=self.completion.bookmark)
self.register_command(
'accept',
self.command.command_accept,
usage='[jid]',
desc='Allow the provided JID (or the selected contact '
'in your roster), to see your presence.',
shortdesc='Allow a user your presence.',)
self.register_command(
'add',
self.command.command_add,
......@@ -1765,7 +1772,7 @@ class Core:
desc='Add the specified JID to your roster, ask them to'
' allow you to see his presence, and allow them to'
' see your presence.',
shortdesc='Add a user to your roster.')
shortdesc='Add a user to your roster.')
self.register_command(
'reconnect',
self.command.command_reconnect,
......
......@@ -91,14 +91,6 @@ class RosterInfoTab(Tab):
'you to be in their roster.',
shortdesc='Deny a user your presence.',
completion=self.completion_deny)
self.register_command(
'accept',
self.command_accept,
usage='[jid]',
desc='Allow the provided JID (or the selected contact '
'in your roster), to see your presence.',
shortdesc='Allow a user your presence.',
completion=self.completion_deny)
self.register_command(
'name',
self.command_name,
......@@ -1030,40 +1022,6 @@ class RosterInfoTab(Tab):
if contact.pending_in)
return Completion(the_input.new_completion, jids, 1, '', quotify=False)
@deny_anonymous
@command_args_parser.quoted(0, 1)
def command_accept(self, args):
"""
Accept a JID from in roster. Authorize it AND subscribe to it
"""
if not args:
item = self.roster_win.selected_row
if isinstance(item, Contact):
jid = item.bare_jid
else:
self.core.information('No subscription to accept', 'Warning')
return
else:
jid = safeJID(args[0]).bare
nodepart = safeJID(jid).user
jid = safeJID(jid)
# crappy transports putting resources inside the node part
if '\\2f' in nodepart:
jid.user = nodepart.split('\\2f')[0]
contact = roster[jid]
if contact is None:
return
contact.pending_in = False
roster.modified()
self.core.xmpp.send_presence(pto=jid, ptype='subscribed')
self.core.xmpp.client_roster.send_last_presence()
if contact.subscription in ('from',
'none') and not contact.pending_out:
self.core.xmpp.send_presence(
pto=jid, ptype='subscribe', pnick=self.core.own_nick)
self.core.information('%s is now authorized' % jid, 'Roster')
def refresh(self):
if self.need_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