parent
							
								
									f22fa200ea
								
							
						
					
					
						commit
						2446c7e3ed
					
				
					 4 changed files with 41 additions and 23 deletions
				
			
		|  | @ -1842,6 +1842,13 @@ class Connection(CommonConnection, ConnectionHandlers): | ||||||
|         self.awaiting_answers[id_] = (PRIVACY_ARRIVED, ) |         self.awaiting_answers[id_] = (PRIVACY_ARRIVED, ) | ||||||
|         self.connection.send(iq) |         self.connection.send(iq) | ||||||
| 
 | 
 | ||||||
|  |     def _request_blocking(self): | ||||||
|  |         if not app.account_is_connected(self.name) or not self.connection: | ||||||
|  |             return | ||||||
|  |         iq = nbxmpp.Iq('get', xmlns=None) | ||||||
|  |         iq.setQuery('blocklist').setNamespace(nbxmpp.NS_BLOCKING) | ||||||
|  |         self.connection.send(iq) | ||||||
|  | 
 | ||||||
|     def _continue_connection_request_privacy(self): |     def _continue_connection_request_privacy(self): | ||||||
|         if self.privacy_rules_supported: |         if self.privacy_rules_supported: | ||||||
|             if not self.privacy_rules_requested: |             if not self.privacy_rules_requested: | ||||||
|  | @ -1861,13 +1868,7 @@ class Connection(CommonConnection, ConnectionHandlers): | ||||||
|                     'invisibility.') % self.name)) |                     'invisibility.') % self.name)) | ||||||
|                 return |                 return | ||||||
|             if self.blocking_supported: |             if self.blocking_supported: | ||||||
|                 iq = nbxmpp.Iq('get', xmlns='') |                 self._request_blocking() | ||||||
|                 query = iq.setQuery(name='blocklist') |  | ||||||
|                 query.setNamespace(nbxmpp.NS_BLOCKING) |  | ||||||
|                 id2_ = self.connection.getAnID() |  | ||||||
|                 iq.setID(id2_) |  | ||||||
|                 self.awaiting_answers[id2_] = (BLOCKING_ARRIVED, ) |  | ||||||
|                 self.connection.send(iq) |  | ||||||
|             # Ask metacontacts before roster |             # Ask metacontacts before roster | ||||||
|             self.get_metacontacts() |             self.get_metacontacts() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -69,7 +69,6 @@ METACONTACTS_ARRIVED = 'metacontacts_arrived' | ||||||
| ROSTER_ARRIVED = 'roster_arrived' | ROSTER_ARRIVED = 'roster_arrived' | ||||||
| DELIMITER_ARRIVED = 'delimiter_arrived' | DELIMITER_ARRIVED = 'delimiter_arrived' | ||||||
| PRIVACY_ARRIVED = 'privacy_arrived' | PRIVACY_ARRIVED = 'privacy_arrived' | ||||||
| BLOCKING_ARRIVED = 'blocking_arrived' |  | ||||||
| PEP_CONFIG = 'pep_config' | PEP_CONFIG = 'pep_config' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -1463,15 +1462,6 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream): | ||||||
|                 # connection process, we don't take the risk |                 # connection process, we don't take the risk | ||||||
|                 self.privacy_rules_supported = False |                 self.privacy_rules_supported = False | ||||||
|                 self._continue_connection_request_privacy() |                 self._continue_connection_request_privacy() | ||||||
|         elif self.awaiting_answers[id_][0] == BLOCKING_ARRIVED: |  | ||||||
|             del self.awaiting_answers[id_] |  | ||||||
|             if iq_obj.getType() == 'result': |  | ||||||
|                 list_node = iq_obj.getTag('blocklist') |  | ||||||
|                 if not list_node: |  | ||||||
|                     return |  | ||||||
|                 self.blocked_contacts = [] |  | ||||||
|                 for i in list_node.iterTags('item'): |  | ||||||
|                     self.blocked_contacts.append(i.getAttr('jid')) |  | ||||||
|         elif self.awaiting_answers[id_][0] == PEP_CONFIG: |         elif self.awaiting_answers[id_][0] == PEP_CONFIG: | ||||||
|             del self.awaiting_answers[id_] |             del self.awaiting_answers[id_] | ||||||
|             if iq_obj.getType() == 'error': |             if iq_obj.getType() == 'error': | ||||||
|  | @ -2097,11 +2087,19 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream): | ||||||
|         self.connection.send(reply) |         self.connection.send(reply) | ||||||
|         raise nbxmpp.NodeProcessed |         raise nbxmpp.NodeProcessed | ||||||
| 
 | 
 | ||||||
|  |     def _BlockingResultCB(self, con, iq_obj): | ||||||
|  |         log.debug('_BlockingResultCB') | ||||||
|  |         app.nec.push_incoming_event( | ||||||
|  |             BlockingEvent(None, conn=self, stanza=iq_obj)) | ||||||
|  |         raise nbxmpp.NodeProcessed | ||||||
|  | 
 | ||||||
|     def _nec_blocking(self, obj): |     def _nec_blocking(self, obj): | ||||||
|         if obj.conn.name != self.name: |         if obj.conn.name != self.name: | ||||||
|             return |             return | ||||||
|         if obj.unblock_all: |         if obj.unblock_all: | ||||||
|             self.blocked_contacts = [] |             self.blocked_contacts = [] | ||||||
|  |         elif obj.blocklist: | ||||||
|  |             self.blocked_contacts = obj.blocklist | ||||||
|         else: |         else: | ||||||
|             for jid in obj.blocked_jids: |             for jid in obj.blocked_jids: | ||||||
|                 if jid not in self.blocked_contacts: |                 if jid not in self.blocked_contacts: | ||||||
|  | @ -2202,3 +2200,5 @@ ConnectionHandlersBase, ConnectionJingle, ConnectionIBBytestream): | ||||||
|             nbxmpp.NS_PUBKEY_PUBKEY) |             nbxmpp.NS_PUBKEY_PUBKEY) | ||||||
|         con.RegisterHandler('iq', self._BlockingSetCB, 'set', |         con.RegisterHandler('iq', self._BlockingSetCB, 'set', | ||||||
|             nbxmpp.NS_BLOCKING) |             nbxmpp.NS_BLOCKING) | ||||||
|  |         con.RegisterHandler('iq', self._BlockingResultCB, 'result', | ||||||
|  |             nbxmpp.NS_BLOCKING) | ||||||
|  |  | ||||||
|  | @ -2787,20 +2787,37 @@ class BlockingEvent(nec.NetworkIncomingEvent): | ||||||
|     base_network_events = [] |     base_network_events = [] | ||||||
| 
 | 
 | ||||||
|     def init(self): |     def init(self): | ||||||
|  |         self.blocklist = [] | ||||||
|         self.blocked_jids = [] |         self.blocked_jids = [] | ||||||
|         self.unblocked_jids = [] |         self.unblocked_jids = [] | ||||||
|         self.unblock_all = False |         self.unblock_all = False | ||||||
| 
 | 
 | ||||||
|     def generate(self): |     def generate(self): | ||||||
|  |         block_list = self.stanza.getTag( | ||||||
|  |             'blocklist', namespace=nbxmpp.NS_BLOCKING) | ||||||
|  |         if block_list is not None: | ||||||
|  |             for item in block_list.getTags('item'): | ||||||
|  |                 self.blocklist.append(item.getAttr('jid')) | ||||||
|  |             app.log('blocking').info( | ||||||
|  |                 'Blocklist Received: %s', self.blocklist) | ||||||
|  |             return True | ||||||
|  | 
 | ||||||
|         block_tag = self.stanza.getTag('block', namespace=nbxmpp.NS_BLOCKING) |         block_tag = self.stanza.getTag('block', namespace=nbxmpp.NS_BLOCKING) | ||||||
|         if block_tag: |         if block_tag is not None: | ||||||
|             for item in block_tag.getTags('item'): |             for item in block_tag.getTags('item'): | ||||||
|                 self.blocked_jids.append(item.getAttr('jid')) |                 self.blocked_jids.append(item.getAttr('jid')) | ||||||
|         unblock_tag = self.stanza.getTag('unblock', |             app.log('blocking').info( | ||||||
|             namespace=nbxmpp.NS_BLOCKING) |                 'Blocking Push - blocked JIDs: %s', self.blocked_jids) | ||||||
|         if unblock_tag: | 
 | ||||||
|             if not unblock_tag.getTags('item'): # unblock all |         unblock_tag = self.stanza.getTag( | ||||||
|  |             'unblock', namespace=nbxmpp.NS_BLOCKING) | ||||||
|  |         if unblock_tag is not None: | ||||||
|  |             if not unblock_tag.getTags('item'): | ||||||
|                 self.unblock_all = True |                 self.unblock_all = True | ||||||
|  |                 app.log('blocking').info('Blocking Push - unblocked all') | ||||||
|  |                 return True | ||||||
|             for item in unblock_tag.getTags('item'): |             for item in unblock_tag.getTags('item'): | ||||||
|                 self.unblocked_jids.append(item.getAttr('jid')) |                 self.unblocked_jids.append(item.getAttr('jid')) | ||||||
|  |             app.log('blocking').info( | ||||||
|  |                 'Blocking Push - unblocked JIDs: %s', self.unblocked_jids) | ||||||
|         return True |         return True | ||||||
|  |  | ||||||
|  | @ -2844,7 +2844,7 @@ class RosterWindow: | ||||||
|             on_response_ok = (remove, list_)) |             on_response_ok = (remove, list_)) | ||||||
| 
 | 
 | ||||||
|     def _nec_blocking(self, obj): |     def _nec_blocking(self, obj): | ||||||
|         if obj.unblock_all: |         if obj.unblock_all or obj.blocklist: | ||||||
|             jids = app.contacts.get_jid_list(obj.conn.name) |             jids = app.contacts.get_jid_list(obj.conn.name) | ||||||
|             self._idle_draw_jids_of_account(jids, obj.conn.name) |             self._idle_draw_jids_of_account(jids, obj.conn.name) | ||||||
|         else: |         else: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue