Update commmand_add, command_remove, command_accept, and command_deny

This commit is contained in:
mathieui 2012-04-27 22:41:16 +02:00
parent 7c8fe132eb
commit f71e2a9cb1

View file

@ -1776,35 +1776,30 @@ class RosterInfoTab(Tab):
args = args.split() args = args.split()
if not args: if not args:
item = self.roster_win.selected_row item = self.roster_win.selected_row
if isinstance(item, Contact) and item.ask == 'asked': if isinstance(item, Contact):
jid = item.bare_jid jid = item.bare_jid
else: else:
self.core.information('No subscription to deny') self.core.information('No subscription to deny')
return return
else: else:
jid = JID(args[0]).bare jid = JID(args[0]).bare
if not jid in [contact.bare_jid for contact in roster.get_contacts()]:
self.core.information('No subscription to deny')
return
self.core.xmpp.sendPresence(pto=jid, ptype='unsubscribed') contact = roster[jid]
try: if contact:
if self.core.xmpp.update_roster(jid, subscription='remove'): contact.unauthorize()
roster.remove_contact(jid)
except Exception as e:
import traceback
log.debug(_('Traceback when removing %s from the roster:\n' % jid)+traceback.format_exc())
def command_add(self, args): def command_add(self, args):
""" """
Add the specified JID to the roster, and set automatically Add the specified JID to the roster, and set automatically
accept the reverse subscription accept the reverse subscription
""" """
jid = JID(args.strip()).bare jid = JID(JID(args.strip()).bare)
if not jid: if not jid:
self.core.information(_('No JID specified'), 'Error') self.core.information(_('No JID specified'), 'Error')
return return
self.core.xmpp.sendPresence(pto=jid, ptype='subscribe') if jid in roster and roster[jid].subscription in ('to', 'both'):
return self.core.information('Already subscribed.', 'Roster')
roster.add(jid)
def command_name(self, args): def command_name(self, args):
""" """
@ -1901,13 +1896,7 @@ class RosterInfoTab(Tab):
else: else:
self.core.information('No roster item to remove') self.core.information('No roster item to remove')
return return
self.core.xmpp.sendPresence(pto=jid, ptype='unavailable') del roster[jid]
self.core.xmpp.sendPresence(pto=jid, ptype='unsubscribe')
self.core.xmpp.sendPresence(pto=jid, ptype='unsubscribed')
try:
self.core.xmpp.del_roster_item(jid=jid)
except:
pass
def command_import(self, arg): def command_import(self, arg):
""" """
@ -2028,20 +2017,20 @@ class RosterInfoTab(Tab):
args = args.split() args = args.split()
if not args: if not args:
item = self.roster_win.selected_row item = self.roster_win.selected_row
if isinstance(item, Contact) and item.ask == 'asked': if isinstance(item, Contact):
jid = item.bare_jid jid = item.bare_jid
else: else:
self.core.information('No subscription to accept') self.core.information('No subscription to accept')
return return
else: else:
jid = args[0] jid = JID(args[0]).bare
self.core.xmpp.sendPresence(pto=jid, ptype='subscribed') contact = roster[jid]
self.core.xmpp.sendPresence(pto=jid, ptype='') if contact is None:
contact = roster.get_contact_by_jid(jid)
if not contact:
return return
if contact.subscription in ('to', 'none'): self.core.xmpp.send_presence(pto=jid, ptype='subscribed')
self.core.xmpp.sendPresence(pto=jid, ptype='subscribe') 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')
def refresh(self): def refresh(self):
if self.need_resize: if self.need_resize: