Move roster methods into Roster module
This commit is contained in:
		
							parent
							
								
									f601ca0d7b
								
							
						
					
					
						commit
						22b3388554
					
				
					 4 changed files with 31 additions and 24 deletions
				
			
		| 
						 | 
				
			
			@ -355,17 +355,6 @@ class CommonConnection:
 | 
			
		|||
                                    additional_data=obj.additional_data,
 | 
			
		||||
                                    stanza_id=obj.stanza_id)
 | 
			
		||||
 | 
			
		||||
    def update_contact(self, jid, name, groups):
 | 
			
		||||
        if self.connection:
 | 
			
		||||
            self.getRoster().set_item(jid=jid, name=name, groups=groups)
 | 
			
		||||
 | 
			
		||||
    def update_contacts(self, contacts):
 | 
			
		||||
        """
 | 
			
		||||
        Update multiple roster items
 | 
			
		||||
        """
 | 
			
		||||
        if self.connection:
 | 
			
		||||
            self.getRoster().set_item_multi(contacts)
 | 
			
		||||
 | 
			
		||||
    def new_account(self, name, config, sync=False):
 | 
			
		||||
        """
 | 
			
		||||
        To be implemented by derived classes
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -270,6 +270,17 @@ class Roster(BaseModule):
 | 
			
		|||
        """
 | 
			
		||||
        return self._get_item_data(jid, 'name')
 | 
			
		||||
 | 
			
		||||
    def update_contact(self, jid, name, groups):
 | 
			
		||||
        if app.account_is_connected(self._account):
 | 
			
		||||
            self.set_item(jid=jid, name=name, groups=groups)
 | 
			
		||||
 | 
			
		||||
    def update_contacts(self, contacts):
 | 
			
		||||
        """
 | 
			
		||||
        Update multiple roster items
 | 
			
		||||
        """
 | 
			
		||||
        if app.account_is_connected(self._account):
 | 
			
		||||
            self.set_item_multi(contacts)
 | 
			
		||||
 | 
			
		||||
    def set_item(self, jid, name=None, groups=None):
 | 
			
		||||
        """
 | 
			
		||||
        Rename contact 'jid' and sets the groups list that it now belongs to
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -97,8 +97,9 @@ class EditGroupsDialog:
 | 
			
		|||
        self.dialog.show_all()
 | 
			
		||||
        if self.changes_made:
 | 
			
		||||
            for (contact, account) in self.list_:
 | 
			
		||||
                app.connections[account].update_contact(contact.jid,
 | 
			
		||||
                    contact.name, contact.groups)
 | 
			
		||||
                con = app.connections[account]
 | 
			
		||||
                con.get_module('Roster').update_contact(
 | 
			
		||||
                    contact.jid, contact.name, contact.groups)
 | 
			
		||||
 | 
			
		||||
    def on_edit_groups_dialog_response(self, widget, response_id):
 | 
			
		||||
        if response_id == Gtk.ResponseType.CLOSE:
 | 
			
		||||
| 
						 | 
				
			
			@ -1066,8 +1067,9 @@ class RosterItemExchangeWindow:
 | 
			
		|||
                        groups = []
 | 
			
		||||
                    for u in app.contacts.get_contact(self.account, jid):
 | 
			
		||||
                        u.name = model[iter_][2]
 | 
			
		||||
                    app.connections[self.account].update_contact(jid,
 | 
			
		||||
                            model[iter_][2], groups)
 | 
			
		||||
                    con = app.connections[self.account]
 | 
			
		||||
                    con.get_module('Roster').update_contact(
 | 
			
		||||
                        jid, model[iter_][2], groups)
 | 
			
		||||
                    self.draw_contact(jid, self.account)
 | 
			
		||||
                    # Update opened chat
 | 
			
		||||
                    ctrl = app.interface.msg_win_mgr.get_control(jid, self.account)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -898,7 +898,8 @@ class RosterWindow:
 | 
			
		|||
                changed_contacts.append({'jid': jid, 'name': contact.name,
 | 
			
		||||
                    'groups':contact.groups})
 | 
			
		||||
 | 
			
		||||
            app.connections[acc].update_contacts(changed_contacts)
 | 
			
		||||
            app.connections[acc].get_module('Roster').update_contacts(
 | 
			
		||||
                changed_contacts)
 | 
			
		||||
 | 
			
		||||
            for c in changed_contacts:
 | 
			
		||||
                self.add_contact(c['jid'], acc)
 | 
			
		||||
| 
						 | 
				
			
			@ -929,8 +930,9 @@ class RosterWindow:
 | 
			
		|||
                    # we might be dropped from meta to group
 | 
			
		||||
                    contact.groups.append(group)
 | 
			
		||||
            if update:
 | 
			
		||||
                app.connections[account].update_contact(jid, contact.name,
 | 
			
		||||
                        contact.groups)
 | 
			
		||||
                con = app.connections[account]
 | 
			
		||||
                con.get_module('Roster').update_contact(
 | 
			
		||||
                    jid, contact.name, contact.groups)
 | 
			
		||||
 | 
			
		||||
        self.add_contact(jid, account)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -957,8 +959,9 @@ class RosterWindow:
 | 
			
		|||
                    # Needed when we remove from "General" or "Observers"
 | 
			
		||||
                    contact.groups.remove(group)
 | 
			
		||||
            if update:
 | 
			
		||||
                app.connections[account].update_contact(jid, contact.name,
 | 
			
		||||
                        contact.groups)
 | 
			
		||||
                con = app.connections[account]
 | 
			
		||||
                con.get_module('Roster').update_contact(
 | 
			
		||||
                    jid, contact.name, contact.groups)
 | 
			
		||||
        self.add_contact(jid, account)
 | 
			
		||||
 | 
			
		||||
        # Also redraw old groups
 | 
			
		||||
| 
						 | 
				
			
			@ -2890,8 +2893,9 @@ class RosterWindow:
 | 
			
		|||
                contacts = app.contacts.get_contacts(account, jid)
 | 
			
		||||
                for contact in contacts:
 | 
			
		||||
                    contact.name = new_text
 | 
			
		||||
                app.connections[account].update_contact(jid, new_text, \
 | 
			
		||||
                    contacts[0].groups)
 | 
			
		||||
                con = app.connections[account]
 | 
			
		||||
                con.get_module('Roster').update_contact(
 | 
			
		||||
                    jid, new_text, contacts[0].groups)
 | 
			
		||||
                self.draw_contact(jid, account)
 | 
			
		||||
                # Update opened chats
 | 
			
		||||
                for ctrl in app.interface.msg_win_mgr.get_controls(jid,
 | 
			
		||||
| 
						 | 
				
			
			@ -4075,8 +4079,9 @@ class RosterWindow:
 | 
			
		|||
                _contact.groups = c_dest.groups[:]
 | 
			
		||||
                app.contacts.add_metacontact(account_dest, c_dest.jid,
 | 
			
		||||
                    _account, _contact.jid, contacts)
 | 
			
		||||
                app.connections[account_source].update_contact(_contact.jid,
 | 
			
		||||
                    _contact.name, _contact.groups)
 | 
			
		||||
                con = app.connections[account_source]
 | 
			
		||||
                con.get_module('Roster').update_contact(
 | 
			
		||||
                    _contact.jid, _contact.name, _contact.groups)
 | 
			
		||||
 | 
			
		||||
            # Re-add all and update GUI
 | 
			
		||||
            new_family = app.contacts.get_metacontacts_family(account_source,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue