summaryrefslogtreecommitdiff
path: root/src/tabs.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/tabs.py')
-rw-r--r--src/tabs.py123
1 files changed, 59 insertions, 64 deletions
diff --git a/src/tabs.py b/src/tabs.py
index 4b39ccc8..df5a9b90 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -633,7 +633,7 @@ class MucTab(ChatTab):
compare_users = lambda x: x.last_talked
userlist = [user.nick for user in sorted(self.users, key=compare_users, reverse=True)\
if user.nick != self.own_nick]
- contact_list = [contact.bare_jid for contact in roster.get_contacts()]
+ contact_list = [jid for jid in roster.jids()]
userlist.extend(contact_list)
return the_input.auto_completion(userlist, '', quotify=False)
@@ -1788,35 +1788,33 @@ class RosterInfoTab(Tab):
"""
if not arg:
item = self.roster_win.selected_row
- if isinstance(item, Contact) and item.ask == 'asked':
+ if isinstance(item, Contact):
jid = item.bare_jid
else:
self.core.information('No subscription to deny')
return
else:
jid = JID(arg).bare
- if not jid in [contact.bare_jid for contact in roster.get_contacts()]:
+ if not jid in [jid for jid in roster.jids()]:
self.core.information('No subscription to deny')
return
- self.core.xmpp.sendPresence(pto=jid, ptype='unsubscribed')
- try:
- if self.core.xmpp.update_roster(jid, subscription='remove'):
- roster.remove_contact(jid)
- except Exception as e:
- import traceback
- log.debug(_('Traceback when removing %s from the roster:\n' % jid)+traceback.format_exc())
+ contact = roster[jid]
+ if contact:
+ contact.unauthorize()
def command_add(self, args):
"""
Add the specified JID to the roster, and set automatically
accept the reverse subscription
"""
- jid = JID(args.strip()).bare
+ jid = JID(JID(args.strip()).bare)
if not jid:
self.core.information(_('No JID specified'), 'Error')
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, arg):
"""
@@ -1828,15 +1826,15 @@ class RosterInfoTab(Tab):
jid = JID(args[0]).bare
name = args[1] if len(args) == 2 else ''
- contact = roster.get_contact_by_jid(jid)
- if not contact:
+ contact = roster[jid]
+ if contact is None:
self.core.information(_('No such JID in roster'), 'Error')
return
groups = set(contact.groups)
subscription = contact.subscription
- if self.core.xmpp.update_roster(jid, name=name, groups=groups, subscription=subscription):
- contact.name = name
+ if not self.core.xmpp.update_roster(jid, name=name, groups=groups, subscription=subscription):
+ self.core.information('The name could not be set.', 'Error')
def command_groupadd(self, args):
"""
@@ -1848,8 +1846,8 @@ class RosterInfoTab(Tab):
jid = JID(args[0]).bare
group = args[1]
- contact = roster.get_contact_by_jid(jid)
- if not contact:
+ contact = roster[jid]
+ if contact is None:
self.core.information(_('No such JID in roster'), 'Error')
return
@@ -1867,7 +1865,7 @@ class RosterInfoTab(Tab):
name = contact.name
subscription = contact.subscription
if self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription):
- roster.edit_groups_of_contact(contact, new_groups)
+ roster.update_contact_groups(jid)
def command_groupmove(self, arg):
"""
@@ -1880,7 +1878,7 @@ class RosterInfoTab(Tab):
group_from = args[1]
group_to = args[2]
- contact = roster.get_contact_by_jid(jid)
+ contact = roster[jid.bare]
if not contact:
self.core.information(_('No such JID in roster'), 'Error')
return
@@ -1925,8 +1923,8 @@ class RosterInfoTab(Tab):
jid = JID(args[0]).bare
group = args[1]
- contact = roster.get_contact_by_jid(jid)
- if not contact:
+ contact = roster[jid]
+ if contact is None:
self.core.information(_('No such JID in roster'), 'Error')
return
@@ -1943,7 +1941,7 @@ class RosterInfoTab(Tab):
name = contact.name
subscription = contact.subscription
if self.core.xmpp.update_roster(jid, name=name, groups=new_groups, subscription=subscription):
- roster.edit_groups_of_contact(contact, new_groups)
+ roster.update_contact_groups(jid)
def command_remove(self, args):
"""
@@ -1959,13 +1957,7 @@ class RosterInfoTab(Tab):
else:
self.core.information('No roster item to remove')
return
- self.core.xmpp.sendPresence(pto=jid, ptype='unavailable')
- 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
+ del roster[jid]
def command_import(self, arg):
"""
@@ -2020,7 +2012,7 @@ class RosterInfoTab(Tab):
"""
From with any JID presence in the roster
"""
- jids = [contact.bare_jid for contact in roster.get_contacts()]
+ jids = [jid for jid in roster.jids()]
return the_input.auto_completion(jids, '')
def completion_name(self, the_input):
@@ -2030,7 +2022,7 @@ class RosterInfoTab(Tab):
n += 1
if n == 2:
- jids = [contact.bare_jid for contact in roster.get_contacts()]
+ jids = [jid for jid in roster.jids()]
return the_input.auto_completion(jids, '')
return False
@@ -2041,10 +2033,10 @@ class RosterInfoTab(Tab):
n += 1
if n == 2:
- jids = [contact.bare_jid for contact in roster.get_contacts()]
+ jids = [jid for jid in roster.jids()]
return the_input.auto_completion(jids, '')
elif n == 3:
- groups = [group.name for group in roster.get_groups() if group.name != 'none']
+ groups = [group for group in roster.groups if group != 'none']
return the_input.auto_completion(groups, '')
return False
@@ -2056,10 +2048,10 @@ class RosterInfoTab(Tab):
n += 1
if n == 2:
- jids = [contact.bare_jid for contact in roster.get_contacts()]
+ jids = [jid for jid in roster.jids()]
return the_input.auto_completion(jids, '')
elif n == 3:
- contact = roster.get_contact_by_jid(args[1])
+ contact = roster[args[1]]
if not contact:
return False
groups = list(contact.groups)
@@ -2067,7 +2059,7 @@ class RosterInfoTab(Tab):
groups.remove('none')
return the_input.auto_completion(groups, '')
elif n == 4:
- groups = [group.name for group in roster.get_groups() if group.name != 'none']
+ groups = [group for group in roster.groups]
return the_input.auto_completion(groups, '')
return False
@@ -2079,11 +2071,11 @@ class RosterInfoTab(Tab):
n += 1
if n == 2:
- jids = [contact.bare_jid for contact in roster.get_contacts()]
+ jids = [jid for jid in roster.jids()]
return the_input.auto_completion(jids, '')
elif n == 3:
- contact = roster.get_contact_by_jid(args[1])
- if not contact:
+ contact = roster[args[1]]
+ if contact is None:
return False
groups = list(contact.groups)
try:
@@ -2098,8 +2090,8 @@ class RosterInfoTab(Tab):
Complete the first argument from the list of the
contact with ask=='subscribe'
"""
- jids = [contact.bare_jid for contact in roster.get_contacts()\
- if contact.ask == 'asked']
+ jids = [str(contact.bare_jid) for contact in roster.contacts.values()\
+ if contact.pending_in]
return the_input.auto_completion(jids, '', quotify=False)
def command_accept(self, arg):
@@ -2108,20 +2100,20 @@ class RosterInfoTab(Tab):
"""
if not arg:
item = self.roster_win.selected_row
- if isinstance(item, Contact) and item.ask == 'asked':
+ if isinstance(item, Contact):
jid = item.bare_jid
else:
self.core.information('No subscription to accept')
return
else:
jid = JID(arg).bare
- self.core.xmpp.sendPresence(pto=jid, ptype='subscribed')
- self.core.xmpp.sendPresence(pto=jid, ptype='')
- contact = roster.get_contact_by_jid(jid)
- if not contact:
+ contact = roster[jid]
+ if contact is None:
return
- if contact.subscription in ('to', 'none'):
- self.core.xmpp.sendPresence(pto=jid, ptype='subscribe')
+ 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')
def refresh(self):
if self.need_resize:
@@ -2275,8 +2267,8 @@ class RosterInfoTab(Tab):
msg = 'Contact: %s (%s)\n%s connected resource%s\nCurrent status: %s' % (
cont.bare_jid,
res.presence if res else 'unavailable',
- cont.get_nb_resources(),
- '' if cont.get_nb_resources() == 1 else 's',
+ len(cont),
+ '' if len(cont) == 1 else 's',
res.status if res else '',)
elif isinstance(selected_row, Resource):
res = selected_row
@@ -2328,18 +2320,18 @@ class RosterInfoTab(Tab):
return True
def set_roster_filter_slow(self, txt):
- roster._contact_filter = (jid_and_name_match_slow, txt)
+ roster.jids_filter = (jid_and_name_match_slow, txt)
self.roster_win.refresh(roster)
return False
def set_roster_filter(self, txt):
- roster._contact_filter = (jid_and_name_match, txt)
+ roster.contact_filter = (jid_and_name_match, txt)
self.roster_win.refresh(roster)
return False
def on_search_terminate(self, txt):
curses.curs_set(0)
- roster._contact_filter = None
+ roster.contact_filter = None
self.reset_help_message()
return False
@@ -2419,10 +2411,10 @@ class ConversationTab(ChatTab):
self.input.refresh()
def command_info(self, arg):
- contact = roster.get_contact_by_jid(self.get_name())
+ contact = roster[self.get_name()]
jid = JID(self.get_name())
if jid.resource:
- resource = contact.get_resource_by_fulljid(jid.full)
+ resource = contact[jid.full]
else:
resource = contact.get_highest_priority_resource()
if resource:
@@ -2485,14 +2477,15 @@ class ConversationTab(ChatTab):
self.resize()
log.debug(' TAB Refresh: %s',self.__class__.__name__)
self.text_win.refresh()
- self.upper_bar.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()))
- self.info_header.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()), self.text_win, self.chatstate, ConversationTab.additional_informations)
+ self.upper_bar.refresh(self.get_name(), roster[self.get_name()])
+ self.info_header.refresh(self.get_name(), roster[self.get_name()], self.text_win, self.chatstate, ConversationTab.additional_informations)
self.info_win.refresh()
self.refresh_tab_win()
self.input.refresh()
def refresh_info_header(self):
- self.info_header.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()), self.text_win, self.chatstate, ConversationTab.additional_informations)
+ self.info_header.refresh(self.get_name(), roster[self.get_name()] or JID(self.get_name()).user,
+ self.text_win, self.chatstate, ConversationTab.additional_informations)
self.input.refresh()
def get_name(self):
@@ -2500,7 +2493,7 @@ class ConversationTab(ChatTab):
def get_nick(self):
jid = JID(self.name)
- contact = roster.get_contact_by_jid(jid.bare)
+ contact = roster[jid.bare]
if contact:
return contact.name or jid.user
else:
@@ -2516,11 +2509,11 @@ class ConversationTab(ChatTab):
return False
def on_lose_focus(self):
- contact = roster.get_contact_by_jid(self.get_name())
+ contact = roster[self.get_name()]
jid = JID(self.get_name())
if contact:
if jid.resource:
- resource = contact.get_resource_by_fulljid(jid.full)
+ resource = contact[jid.full]
else:
resource = contact.get_highest_priority_resource()
else:
@@ -2533,11 +2526,11 @@ class ConversationTab(ChatTab):
self.send_chat_state('inactive')
def on_gain_focus(self):
- contact = roster.get_contact_by_jid(self.get_name())
+ contact = roster[self.get_name()]
jid = JID(self.get_name())
if contact:
if jid.resource:
- resource = contact.get_resource_by_fulljid(jid.full)
+ resource = contact[jid.full]
else:
resource = contact.get_highest_priority_resource()
else:
@@ -2954,6 +2947,8 @@ def jid_and_name_match(contact, txt):
return True
if txt in JID(contact.bare_jid).user:
return True
+ if txt in contact.name:
+ return True
return False
def jid_and_name_match_slow(contact, txt):