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)
|
self.connection.SendAndCallForResponse(iq, _on_response)
|
||||||
|
|
||||||
def load_roster_from_db(self):
|
def load_roster_from_db(self):
|
||||||
roster = gajim.logger.get_roster(gajim.get_jid_from_account(self.name))
|
gajim.nec.push_incoming_event(RosterReceivedEvent(None, conn=self))
|
||||||
self.dispatch('ROSTER', roster)
|
|
||||||
|
|
||||||
|
|
||||||
# END Connection
|
# END Connection
|
||||||
|
|
|
@ -1984,6 +1984,7 @@ ConnectionJingle, ConnectionIBBytestream):
|
||||||
if send_first_presence:
|
if send_first_presence:
|
||||||
self._send_first_presence(signed)
|
self._send_first_presence(signed)
|
||||||
|
|
||||||
|
if obj.received_from_server:
|
||||||
for jid in obj.roster:
|
for jid in obj.roster:
|
||||||
if jid != our_jid and gajim.jid_is_transport(jid) and \
|
if jid != our_jid and gajim.jid_is_transport(jid) and \
|
||||||
not gajim.get_transport_name_from_jid(jid):
|
not gajim.get_transport_name_from_jid(jid):
|
||||||
|
@ -1991,7 +1992,7 @@ ConnectionJingle, ConnectionIBBytestream):
|
||||||
self.discoverInfo(jid)
|
self.discoverInfo(jid)
|
||||||
|
|
||||||
gajim.logger.replace_roster(self.name, obj.version, obj.roster)
|
gajim.logger.replace_roster(self.name, obj.version, obj.roster)
|
||||||
if obj.received_from_server:
|
|
||||||
for contact in gajim.contacts.iter_contacts(self.name):
|
for contact in gajim.contacts.iter_contacts(self.name):
|
||||||
if not contact.is_groupchat() and contact.jid not in obj.roster\
|
if not contact.is_groupchat() and contact.jid not in obj.roster\
|
||||||
and contact.jid != our_jid:
|
and contact.jid != our_jid:
|
||||||
|
|
|
@ -307,6 +307,7 @@ class RosterReceivedEvent(nec.NetworkIncomingEvent):
|
||||||
base_network_events = []
|
base_network_events = []
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
|
if hasattr(self, 'xmpp_roster'):
|
||||||
self.version = self.xmpp_roster.version
|
self.version = self.xmpp_roster.version
|
||||||
self.received_from_server = self.xmpp_roster.received_from_server
|
self.received_from_server = self.xmpp_roster.received_from_server
|
||||||
self.roster = {}
|
self.roster = {}
|
||||||
|
@ -317,17 +318,28 @@ class RosterReceivedEvent(nec.NetworkIncomingEvent):
|
||||||
try:
|
try:
|
||||||
j = helpers.parse_jid(jid)
|
j = helpers.parse_jid(jid)
|
||||||
except Exception:
|
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:
|
else:
|
||||||
infos = raw_roster[jid]
|
infos = raw_roster[jid]
|
||||||
if jid != our_jid and (not infos['subscription'] or \
|
if jid != our_jid and (not infos['subscription'] or \
|
||||||
infos['subscription'] == 'none') and (not infos['ask'] or \
|
infos['subscription'] == 'none') and (not infos['ask'] or \
|
||||||
infos['ask'] == 'none') and not infos['name'] and \
|
infos['ask'] == 'none') and not infos['name'] and \
|
||||||
not infos['groups']:
|
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)
|
self.conn.connection.getRoster().delItem(jid)
|
||||||
elif jid != our_jid: # don't add our jid
|
elif jid != our_jid: # don't add our jid
|
||||||
self.roster[j] = raw_roster[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
|
return True
|
||||||
|
|
||||||
class RosterSetReceivedEvent(nec.NetworkIncomingEvent):
|
class RosterSetReceivedEvent(nec.NetworkIncomingEvent):
|
||||||
|
|
|
@ -70,7 +70,8 @@ class CommonResolver():
|
||||||
return
|
return
|
||||||
if self.resolved_hosts.has_key(host+type):
|
if self.resolved_hosts.has_key(host+type):
|
||||||
# host is already resolved, return cached values
|
# 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])
|
on_ready(host, self.resolved_hosts[host+type])
|
||||||
return
|
return
|
||||||
if self.handlers.has_key(host+type):
|
if self.handlers.has_key(host+type):
|
||||||
|
|
|
@ -102,16 +102,6 @@ class Interface:
|
||||||
### Methods handling events from connection
|
### 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):
|
def handle_event_warning(self, unused, data):
|
||||||
#('WARNING', account, (title_text, section_text))
|
#('WARNING', account, (title_text, section_text))
|
||||||
dialogs.WarningDialog(data[0], data[1])
|
dialogs.WarningDialog(data[0], data[1])
|
||||||
|
@ -1856,7 +1846,6 @@ class Interface:
|
||||||
|
|
||||||
def create_core_handlers_list(self):
|
def create_core_handlers_list(self):
|
||||||
self.handlers = {
|
self.handlers = {
|
||||||
'ROSTER': [self.handle_event_roster],
|
|
||||||
'WARNING': [self.handle_event_warning],
|
'WARNING': [self.handle_event_warning],
|
||||||
'ERROR': [self.handle_event_error],
|
'ERROR': [self.handle_event_error],
|
||||||
'DB_ERROR': [self.handle_event_db_error],
|
'DB_ERROR': [self.handle_event_db_error],
|
||||||
|
|
Loading…
Reference in New Issue