use RosterReceivedEvent object to handle load_roster_from_db.
This commit is contained in:
		
							parent
							
								
									58f26f3bfe
								
							
						
					
					
						commit
						435b6832cf
					
				
					 5 changed files with 53 additions and 52 deletions
				
			
		|  | @ -2322,8 +2322,6 @@ class Connection(CommonConnection, ConnectionHandlers): | |||
|         self.connection.SendAndCallForResponse(iq, _on_response) | ||||
| 
 | ||||
|     def load_roster_from_db(self): | ||||
|         roster = gajim.logger.get_roster(gajim.get_jid_from_account(self.name)) | ||||
|         self.dispatch('ROSTER', roster) | ||||
| 
 | ||||
|         gajim.nec.push_incoming_event(RosterReceivedEvent(None, conn=self)) | ||||
| 
 | ||||
| # END Connection | ||||
|  |  | |||
|  | @ -1984,25 +1984,26 @@ ConnectionJingle, ConnectionIBBytestream): | |||
|             if send_first_presence: | ||||
|                 self._send_first_presence(signed) | ||||
| 
 | ||||
|         for jid in obj.roster: | ||||
|             if jid != our_jid and gajim.jid_is_transport(jid) and \ | ||||
|             not gajim.get_transport_name_from_jid(jid): | ||||
|                 # we can't determine which iconset to use | ||||
|                 self.discoverInfo(jid) | ||||
| 
 | ||||
|         gajim.logger.replace_roster(self.name, obj.version, obj.roster) | ||||
|         if obj.received_from_server: | ||||
|             for contact in gajim.contacts.iter_contacts(self.name): | ||||
|                 if not contact.is_groupchat() and contact.jid not in obj.roster\ | ||||
|                 and contact.jid != our_jid: | ||||
|                     gajim.nec.push_incoming_event(RosterInfoEvent(None, | ||||
|                         conn=self, jid=contact.jid, nickname=None, sub=None, | ||||
|                         ask=None, groups=())) | ||||
|             for jid, info in obj.roster.items(): | ||||
|             for jid in obj.roster: | ||||
|                 if jid != our_jid and gajim.jid_is_transport(jid) and \ | ||||
|                 not gajim.get_transport_name_from_jid(jid): | ||||
|                     # we can't determine which iconset to use | ||||
|                     self.discoverInfo(jid) | ||||
| 
 | ||||
|             gajim.logger.replace_roster(self.name, obj.version, obj.roster) | ||||
| 
 | ||||
|         for contact in gajim.contacts.iter_contacts(self.name): | ||||
|             if not contact.is_groupchat() and contact.jid not in obj.roster\ | ||||
|             and contact.jid != our_jid: | ||||
|                 gajim.nec.push_incoming_event(RosterInfoEvent(None, | ||||
|                     conn=self, jid=jid, nickname=info['name'], | ||||
|                     sub=info['subscription'], ask=info['ask'], | ||||
|                     groups=info['groups'])) | ||||
|                     conn=self, jid=contact.jid, nickname=None, sub=None, | ||||
|                     ask=None, groups=())) | ||||
|         for jid, info in obj.roster.items(): | ||||
|             gajim.nec.push_incoming_event(RosterInfoEvent(None, | ||||
|                 conn=self, jid=jid, nickname=info['name'], | ||||
|                 sub=info['subscription'], ask=info['ask'], | ||||
|                 groups=info['groups'])) | ||||
| 
 | ||||
|     def _send_first_presence(self, signed=''): | ||||
|         show = self.continue_connect_info[0] | ||||
|  |  | |||
|  | @ -307,27 +307,39 @@ class RosterReceivedEvent(nec.NetworkIncomingEvent): | |||
|     base_network_events = [] | ||||
| 
 | ||||
|     def generate(self): | ||||
|         self.version = self.xmpp_roster.version | ||||
|         self.received_from_server = self.xmpp_roster.received_from_server | ||||
|         self.roster = {} | ||||
|         raw_roster = self.xmpp_roster.getRaw() | ||||
|         our_jid = gajim.get_jid_from_account(self.conn.name) | ||||
|         if hasattr(self, 'xmpp_roster'): | ||||
|             self.version = self.xmpp_roster.version | ||||
|             self.received_from_server = self.xmpp_roster.received_from_server | ||||
|             self.roster = {} | ||||
|             raw_roster = self.xmpp_roster.getRaw() | ||||
|             our_jid = gajim.get_jid_from_account(self.conn.name) | ||||
| 
 | ||||
|         for jid in raw_roster: | ||||
|             try: | ||||
|                 j = helpers.parse_jid(jid) | ||||
|             except Exception: | ||||
|                 print >> sys.stderr, _('JID %s is not RFC compliant. It will not be added to your roster. Use roster management tools such as http://jru.jabberstudio.org/ to remove it') % jid | ||||
|             else: | ||||
|                 infos = raw_roster[jid] | ||||
|                 if jid != our_jid and (not infos['subscription'] or \ | ||||
|                 infos['subscription'] == 'none') and (not infos['ask'] or \ | ||||
|                 infos['ask'] == 'none') and not infos['name'] and \ | ||||
|                 not infos['groups']: | ||||
|                     # remove this useless item, it won't be shown in roster anyway | ||||
|                     self.conn.connection.getRoster().delItem(jid) | ||||
|                 elif jid != our_jid: # don't add our jid | ||||
|                     self.roster[j] = raw_roster[jid] | ||||
|             for jid in raw_roster: | ||||
|                 try: | ||||
|                     j = helpers.parse_jid(jid) | ||||
|                 except Exception: | ||||
|                     print >> sys.stderr, _('JID %s is not RFC compliant. It ' | ||||
|                         'will not be added to your roster. Use roster ' | ||||
|                         'management tools such as ' | ||||
|                         'http://jru.jabberstudio.org/ to remove it') % jid | ||||
|                 else: | ||||
|                     infos = raw_roster[jid] | ||||
|                     if jid != our_jid and (not infos['subscription'] or \ | ||||
|                     infos['subscription'] == 'none') and (not infos['ask'] or \ | ||||
|                     infos['ask'] == 'none') and not infos['name'] and \ | ||||
|                     not infos['groups']: | ||||
|                         # remove this useless item, it won't be shown in roster | ||||
|                         # anyway | ||||
|                         self.conn.connection.getRoster().delItem(jid) | ||||
|                     elif jid != our_jid: # don't add our jid | ||||
|                         self.roster[j] = raw_roster[jid] | ||||
|         else: | ||||
|             # Roster comes from DB | ||||
|             self.received_from_server = False | ||||
|             self.version = gajim.config.get_per('accounts', self.conn.name, | ||||
|                 'roster_version') | ||||
|             self.roster = gajim.logger.get_roster(gajim.get_jid_from_account( | ||||
|                 self.conn.name)) | ||||
|         return True | ||||
| 
 | ||||
| class RosterSetReceivedEvent(nec.NetworkIncomingEvent): | ||||
|  |  | |||
|  | @ -70,7 +70,8 @@ class CommonResolver(): | |||
|             return | ||||
|         if self.resolved_hosts.has_key(host+type): | ||||
|             # host is already resolved, return cached values | ||||
|             log.debug('%s already resolved: %s') | ||||
|             log.debug('%s already resolved: %s' % (host, | ||||
|                 self.resolved_hosts[host+type])) | ||||
|             on_ready(host, self.resolved_hosts[host+type]) | ||||
|             return | ||||
|         if self.handlers.has_key(host+type): | ||||
|  |  | |||
|  | @ -102,16 +102,6 @@ class Interface: | |||
| ### Methods handling events from connection | ||||
| ################################################################################ | ||||
| 
 | ||||
|     def handle_event_roster(self, account, data): | ||||
|         #('ROSTER', account, array) | ||||
|         # FIXME: Those methods depend to highly on each other | ||||
|         # and the order in which they are called | ||||
|         self.roster.fill_contacts_and_groups_dicts(data, account) | ||||
|         self.roster.add_account_contacts(account) | ||||
|         self.roster.fire_up_unread_messages_events(account) | ||||
|         if self.remote_ctrl: | ||||
|             self.remote_ctrl.raise_signal('Roster', (account, data)) | ||||
| 
 | ||||
|     def handle_event_warning(self, unused, data): | ||||
|         #('WARNING', account, (title_text, section_text)) | ||||
|         dialogs.WarningDialog(data[0], data[1]) | ||||
|  | @ -1856,7 +1846,6 @@ class Interface: | |||
| 
 | ||||
|     def create_core_handlers_list(self): | ||||
|         self.handlers = { | ||||
|             'ROSTER': [self.handle_event_roster], | ||||
|             'WARNING': [self.handle_event_warning], | ||||
|             'ERROR': [self.handle_event_error], | ||||
|             'DB_ERROR': [self.handle_event_db_error], | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue