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,25 +1984,26 @@ ConnectionJingle, ConnectionIBBytestream):
|
||||||
if send_first_presence:
|
if send_first_presence:
|
||||||
self._send_first_presence(signed)
|
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:
|
if obj.received_from_server:
|
||||||
for contact in gajim.contacts.iter_contacts(self.name):
|
for jid in obj.roster:
|
||||||
if not contact.is_groupchat() and contact.jid not in obj.roster\
|
if jid != our_jid and gajim.jid_is_transport(jid) and \
|
||||||
and contact.jid != our_jid:
|
not gajim.get_transport_name_from_jid(jid):
|
||||||
gajim.nec.push_incoming_event(RosterInfoEvent(None,
|
# we can't determine which iconset to use
|
||||||
conn=self, jid=contact.jid, nickname=None, sub=None,
|
self.discoverInfo(jid)
|
||||||
ask=None, groups=()))
|
|
||||||
for jid, info in obj.roster.items():
|
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,
|
gajim.nec.push_incoming_event(RosterInfoEvent(None,
|
||||||
conn=self, jid=jid, nickname=info['name'],
|
conn=self, jid=contact.jid, nickname=None, sub=None,
|
||||||
sub=info['subscription'], ask=info['ask'],
|
ask=None, groups=()))
|
||||||
groups=info['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=''):
|
def _send_first_presence(self, signed=''):
|
||||||
show = self.continue_connect_info[0]
|
show = self.continue_connect_info[0]
|
||||||
|
|
|
@ -307,27 +307,39 @@ class RosterReceivedEvent(nec.NetworkIncomingEvent):
|
||||||
base_network_events = []
|
base_network_events = []
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
self.version = self.xmpp_roster.version
|
if hasattr(self, 'xmpp_roster'):
|
||||||
self.received_from_server = self.xmpp_roster.received_from_server
|
self.version = self.xmpp_roster.version
|
||||||
self.roster = {}
|
self.received_from_server = self.xmpp_roster.received_from_server
|
||||||
raw_roster = self.xmpp_roster.getRaw()
|
self.roster = {}
|
||||||
our_jid = gajim.get_jid_from_account(self.conn.name)
|
raw_roster = self.xmpp_roster.getRaw()
|
||||||
|
our_jid = gajim.get_jid_from_account(self.conn.name)
|
||||||
|
|
||||||
for jid in raw_roster:
|
for jid in raw_roster:
|
||||||
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 '
|
||||||
else:
|
'will not be added to your roster. Use roster '
|
||||||
infos = raw_roster[jid]
|
'management tools such as '
|
||||||
if jid != our_jid and (not infos['subscription'] or \
|
'http://jru.jabberstudio.org/ to remove it') % jid
|
||||||
infos['subscription'] == 'none') and (not infos['ask'] or \
|
else:
|
||||||
infos['ask'] == 'none') and not infos['name'] and \
|
infos = raw_roster[jid]
|
||||||
not infos['groups']:
|
if jid != our_jid and (not infos['subscription'] or \
|
||||||
# remove this useless item, it won't be shown in roster anyway
|
infos['subscription'] == 'none') and (not infos['ask'] or \
|
||||||
self.conn.connection.getRoster().delItem(jid)
|
infos['ask'] == 'none') and not infos['name'] and \
|
||||||
elif jid != our_jid: # don't add our jid
|
not infos['groups']:
|
||||||
self.roster[j] = raw_roster[jid]
|
# 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
|
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