use NEC to handle agent-removed events
This commit is contained in:
		
							parent
							
								
									f5b38c8253
								
							
						
					
					
						commit
						09f16c5872
					
				
					 4 changed files with 35 additions and 20 deletions
				
			
		| 
						 | 
				
			
			@ -645,7 +645,8 @@ class ConnectionVcard:
 | 
			
		|||
                    self.dispatch('MYVCARD', {'jid': frm})
 | 
			
		||||
        elif self.awaiting_answers[id_][0] == AGENT_REMOVED:
 | 
			
		||||
            jid = self.awaiting_answers[id_][1]
 | 
			
		||||
            self.dispatch('AGENT_REMOVED', jid)
 | 
			
		||||
            gajim.nec.push_incoming_event(AgentRemovedEvent(None, conn=self,
 | 
			
		||||
                agent=jid))
 | 
			
		||||
        elif self.awaiting_answers[id_][0] == METACONTACTS_ARRIVED:
 | 
			
		||||
            if not self.connection:
 | 
			
		||||
                return
 | 
			
		||||
| 
						 | 
				
			
			@ -1149,6 +1150,8 @@ ConnectionJingle, ConnectionIBBytestream):
 | 
			
		|||
            self._nec_message_received)
 | 
			
		||||
        gajim.ged.register_event_handler('decrypted-message-received', ged.CORE,
 | 
			
		||||
            self._nec_decrypted_message_received)
 | 
			
		||||
        gajim.ged.register_event_handler('agent-removed', ged.CORE,
 | 
			
		||||
            self._nec_agent_removed)
 | 
			
		||||
 | 
			
		||||
    def build_http_auth_answer(self, iq_obj, answer):
 | 
			
		||||
        if not self.connection or self.connected < 2:
 | 
			
		||||
| 
						 | 
				
			
			@ -1896,6 +1899,18 @@ ConnectionJingle, ConnectionIBBytestream):
 | 
			
		|||
        'dont_ack_subscription'):
 | 
			
		||||
            self.ack_unsubscribed(obj.jid)
 | 
			
		||||
 | 
			
		||||
    def _nec_agent_removed(self, obj):
 | 
			
		||||
        if obj.conn.name != self.name:
 | 
			
		||||
            return
 | 
			
		||||
        for jid in obj.jid_list:
 | 
			
		||||
            log.debug('Removing contact %s due to unregistered transport %s' % \
 | 
			
		||||
                (jid, agent))
 | 
			
		||||
            self.unsubscribe(jid)
 | 
			
		||||
            # Transport contacts can't have 2 resources
 | 
			
		||||
            if jid in gajim.to_be_removed[self.name]:
 | 
			
		||||
                # This way we'll really remove it
 | 
			
		||||
                gajim.to_be_removed[self.name].remove(jid)
 | 
			
		||||
 | 
			
		||||
    def _StanzaArrivedCB(self, con, obj):
 | 
			
		||||
        self.last_io = gajim.idlequeue.current_time()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1292,3 +1292,14 @@ class StanzaReceivedEvent(nec.NetworkIncomingEvent):
 | 
			
		|||
class StanzaSentEvent(nec.NetworkIncomingEvent):
 | 
			
		||||
    name = 'stanza-sent'
 | 
			
		||||
    base_network_events = []
 | 
			
		||||
 | 
			
		||||
class AgentRemovedEvent(nec.NetworkIncomingEvent):
 | 
			
		||||
    name = 'agent-removed'
 | 
			
		||||
    base_network_events = []
 | 
			
		||||
 | 
			
		||||
    def generate(self):
 | 
			
		||||
        self.jid_list = []
 | 
			
		||||
        for jid in gajim.contacts.get_jid_list(self.conn.name):
 | 
			
		||||
            if jid.endswith('@' + self.agent):
 | 
			
		||||
                self.jid_list.append(jid)
 | 
			
		||||
        return True
 | 
			
		||||
| 
						 | 
				
			
			@ -545,22 +545,6 @@ class Interface:
 | 
			
		|||
            notify.popup(event_type, obj.jid, account, 'unsubscribed', path,
 | 
			
		||||
                event_type, obj.jid)
 | 
			
		||||
 | 
			
		||||
    def handle_event_agent_removed(self, account, agent):
 | 
			
		||||
        # remove transport's contacts from treeview
 | 
			
		||||
        jid_list = gajim.contacts.get_jid_list(account)
 | 
			
		||||
        for jid in jid_list:
 | 
			
		||||
            if jid.endswith('@' + agent):
 | 
			
		||||
                c = gajim.contacts.get_first_contact_from_jid(account, jid)
 | 
			
		||||
                gajim.log.debug(
 | 
			
		||||
                        'Removing contact %s due to unregistered transport %s'\
 | 
			
		||||
                        % (jid, agent))
 | 
			
		||||
                gajim.connections[account].unsubscribe(c.jid)
 | 
			
		||||
                # Transport contacts can't have 2 resources
 | 
			
		||||
                if c.jid in gajim.to_be_removed[account]:
 | 
			
		||||
                    # This way we'll really remove it
 | 
			
		||||
                    gajim.to_be_removed[account].remove(c.jid)
 | 
			
		||||
                self.roster.remove_contact(c.jid, account, backend=True)
 | 
			
		||||
 | 
			
		||||
    def handle_event_register_agent_info(self, account, array):
 | 
			
		||||
        # ('REGISTER_AGENT_INFO', account, (agent, infos, is_form))
 | 
			
		||||
        # info in a dataform if is_form is True
 | 
			
		||||
| 
						 | 
				
			
			@ -1764,7 +1748,6 @@ class Interface:
 | 
			
		|||
            'DB_ERROR': [self.handle_event_db_error],
 | 
			
		||||
            'INFORMATION': [self.handle_event_information],
 | 
			
		||||
            'MSGERROR': [self.handle_event_msgerror],
 | 
			
		||||
            'AGENT_REMOVED': [self.handle_event_agent_removed],
 | 
			
		||||
            'REGISTER_AGENT_INFO': [self.handle_event_register_agent_info],
 | 
			
		||||
            'AGENT_INFO_ITEMS': [self.handle_event_agent_info_items],
 | 
			
		||||
            'MYVCARD': [self.handle_event_myvcard],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2498,6 +2498,10 @@ class RosterWindow:
 | 
			
		|||
    def _nec_connection_type(self, obj):
 | 
			
		||||
        self.draw_account(obj.conn.name)
 | 
			
		||||
 | 
			
		||||
    def _nec_agent_removed(self, obj):
 | 
			
		||||
        for jid in obj.jid_list:
 | 
			
		||||
            self.remove_contact(jid, obj.conn.name, backend=True)
 | 
			
		||||
 | 
			
		||||
################################################################################
 | 
			
		||||
### Menu and GUI callbacks
 | 
			
		||||
### FIXME: order callbacks in itself...
 | 
			
		||||
| 
						 | 
				
			
			@ -6234,3 +6238,5 @@ class RosterWindow:
 | 
			
		|||
            self._nec_our_show)
 | 
			
		||||
        gajim.ged.register_event_handler('connection-type', ged.GUI1,
 | 
			
		||||
            self._nec_connection_type)
 | 
			
		||||
        gajim.ged.register_event_handler('agent-removed', ged.GUI1,
 | 
			
		||||
            self._nec_agent_removed)
 | 
			
		||||
		Loading…
	
	Add table
		
		Reference in a new issue