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 command_add(self, args): """ Add the specified JID to the roster, and automatically accept the reverse subscription """ if args is None: 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() 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( 'The provided JID (%s) is not valid' % (args[0], ), 'Error') return 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')
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') 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 command_groupmove(self, args): """ Remove the specified JID from the first specified group and add it to the second one """ if args is None: return self.core.command.help('groupmove') jid = safeJID(args[0]).bare group_from = args[1] group_to = args[2] contact = roster[jid] if not contact: self.core.information('No such JID in roster', 'Error') return new_groups = set(contact.groups) if 'none' in new_groups: new_groups.remove('none') if group_to == 'none' or group_from == 'none': self.core.information('"none" is not a group.', 'Error') return if group_from not in new_groups: self.core.information('JID not in first group', 'Error') return if group_to in new_groups: self.core.information('JID already in second group', 'Error') return if group_to == group_from: self.core.information('The groups are the same.', 'Error') return roster.modified() new_groups.add(group_to) if 'none' in new_groups: new_groups.remove('none') new_groups.remove(group_from) name = contact.name subscription = contact.subscription def callback(iq): if iq: roster.update_contact_groups(contact) else: self.core.information('The group could not be set', 'Error') log.debug('Error in groupmove:\n%s', iq) self.core.xmpp.update_roster( jid, name=name, groups=new_groups, subscription=subscription, callback=callback)
def command_add(self): """ Add the current JID to the roster, and automatically accept the reverse subscription """ jid = self.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')
def toggle_offline_show(self): """ Show or hide offline contacts """ option = 'roster_show_offline' value = config.get(option) success = config.silent_set(option, str(not value)) roster.modified() if not success: self.core.information('Unable to write in the config file', 'Error') return True
def start_search(self): """ Start the search. The input should appear with a short instruction in it. """ curses.curs_set(1) self.input = windows.CommandInput("[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter) self.input.resize(1, self.width, self.height-1, 0) self.input.disable_history() roster.modified() self.refresh() return True
def command_groupadd(self, args): """ Add the specified JID to the specified group """ if args is None: return self.core.command.help('groupadd') if len(args) == 1: group = args[0] item = self.roster_win.selected_row if isinstance(item, Contact): jid = item.bare_jid elif isinstance(item, Resource): jid = item.jid else: return self.core.command.help('groupadd') else: jid = safeJID(args[0]).bare group = args[1] contact = roster[jid] if contact is None: self.core.information('No such JID in roster', 'Error') return new_groups = set(contact.groups) if group in new_groups: self.core.information('JID already in group', 'Error') return roster.modified() new_groups.add(group) try: new_groups.remove('none') except KeyError: pass name = contact.name subscription = contact.subscription def callback(iq): if iq: roster.update_contact_groups(jid) else: self.core.information('The group could not be set.', 'Error') log.debug('Error in groupadd:\n%s', iq) self.core.xmpp.update_roster( jid, name=name, groups=new_groups, subscription=subscription, callback=callback)
def start_search(self): """ Start the search. The input should appear with a short instruction in it. """ curses.curs_set(1) self.input = windows.CommandInput("[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter) self.input.resize(1, self.width, self.height - 1, 0) self.input.disable_history() roster.modified() self.refresh() return True
def command_add(self, args): """ Add the specified JID to the roster, and set automatically accept the reverse subscription """ if args is None: self.core.information('No JID specified', 'Error') return jid = safeJID(safeJID(args[0]).bare) if not str(jid): self.core.information('The provided JID (%s) is not valid' % (args[0],), 'Error') return 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')
def command_add(self, args): """ Add the specified JID to the roster, and automatically accept the reverse subscription """ if args is None: self.core.information('No JID specified', 'Error') return jid = safeJID(safeJID(args[0]).bare) if not str(jid): self.core.information( 'The provided JID (%s) is not valid' % (args[0], ), 'Error') return 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')
def command_groupremove(self, args): """ Remove the specified JID from the specified group """ if args is None: return self.core.command.help('groupremove') jid = safeJID(args[0]).bare group = args[1] contact = roster[jid] if contact is None: self.core.information('No such JID in roster', 'Error') return new_groups = set(contact.groups) try: new_groups.remove('none') except KeyError: pass if group not in new_groups: self.core.information('JID not in group', 'Error') return roster.modified() new_groups.remove(group) name = contact.name subscription = contact.subscription def callback(iq): if iq: roster.update_contact_groups(jid) else: self.core.information('The group could not be set') log.debug('Error in groupremove:\n%s', iq) self.core.xmpp.update_roster( jid, name=name, groups=new_groups, subscription=subscription, callback=callback)
def on_space(self): if isinstance(self.input, windows.Input): return selected_row = self.roster_win.get_selected_row() if isinstance(selected_row, RosterGroup): selected_row.toggle_folded() roster.modified() return True elif isinstance(selected_row, Contact): group = "none" found_group = False pos = self.roster_win.pos while not found_group and pos >= 0: row = self.roster_win.roster_cache[pos] pos -= 1 if isinstance(row, RosterGroup): found_group = True group = row.name selected_row.toggle_folded(group) roster.modified() return True return False
def on_search_terminate(self, txt): curses.curs_set(0) roster.contact_filter = None self.reset_help_message() roster.modified() return True
def set_roster_filter(self, txt): roster.contact_filter = (jid_and_name_match, txt) roster.modified() self.refresh() return False
def on_search_terminate(self, txt): curses.curs_set(0) roster.contact_filter = roster.DEFAULT_FILTER self.reset_help_message() roster.modified() return True