use RosterReceivedEvent object to handle load_roster_from_db.
This commit is contained in:
parent
58f26f3bfe
commit
435b6832cf
|
@ -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,6 +1984,7 @@ ConnectionJingle, ConnectionIBBytestream):
|
|||
if send_first_presence:
|
||||
self._send_first_presence(signed)
|
||||
|
||||
if obj.received_from_server:
|
||||
for jid in obj.roster:
|
||||
if jid != our_jid and gajim.jid_is_transport(jid) and \
|
||||
not gajim.get_transport_name_from_jid(jid):
|
||||
|
@ -1991,7 +1992,7 @@ ConnectionJingle, ConnectionIBBytestream):
|
|||
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:
|
||||
|
|
|
@ -307,6 +307,7 @@ class RosterReceivedEvent(nec.NetworkIncomingEvent):
|
|||
base_network_events = []
|
||||
|
||||
def generate(self):
|
||||
if hasattr(self, 'xmpp_roster'):
|
||||
self.version = self.xmpp_roster.version
|
||||
self.received_from_server = self.xmpp_roster.received_from_server
|
||||
self.roster = {}
|
||||
|
@ -317,17 +318,28 @@ class RosterReceivedEvent(nec.NetworkIncomingEvent):
|
|||
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
|
||||
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
|
||||
# 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…
Reference in New Issue