use NEC to handle roster receipt

This commit is contained in:
Yann Leboulanger 2010-08-29 20:22:20 +02:00
parent f66a7c458c
commit fea877e154
2 changed files with 56 additions and 36 deletions

View File

@ -1100,6 +1100,8 @@ ConnectionJingle, ConnectionIBBytestream):
gajim.ged.register_event_handler('private-storage-rosternotes-received', gajim.ged.register_event_handler('private-storage-rosternotes-received',
ged.CORE, self._nec_private_storate_rosternotes_received) ged.CORE, self._nec_private_storate_rosternotes_received)
gajim.nec.register_incoming_event(RosternotesReceivedEvent) gajim.nec.register_incoming_event(RosternotesReceivedEvent)
gajim.ged.register_event_handler('roster-received', ged.CORE,
self._nec_roster_received)
def build_http_auth_answer(self, iq_obj, answer): def build_http_auth_answer(self, iq_obj, answer):
if not self.connection or self.connected < 2: if not self.connection or self.connected < 2:
@ -2120,19 +2122,21 @@ ConnectionJingle, ConnectionIBBytestream):
def discover_ft_proxies(self): def discover_ft_proxies(self):
cfg_proxies = gajim.config.get_per('accounts', self.name, cfg_proxies = gajim.config.get_per('accounts', self.name,
'file_transfer_proxies') 'file_transfer_proxies')
our_jid = helpers.parse_jid(gajim.get_jid_from_account(self.name) + '/' +\ our_jid = helpers.parse_jid(gajim.get_jid_from_account(self.name) + \
self.server_resource) '/' + self.server_resource)
if cfg_proxies: if cfg_proxies:
proxies = [e.strip() for e in cfg_proxies.split(',')] proxies = [e.strip() for e in cfg_proxies.split(',')]
for proxy in proxies: for proxy in proxies:
gajim.proxy65_manager.resolve(proxy, self.connection, our_jid) gajim.proxy65_manager.resolve(proxy, self.connection, our_jid)
def _on_roster_set(self, roster): def _on_roster_set(self, roster):
roster_version = roster.version gajim.nec.push_incoming_event(RosterReceivedEvent(None, conn=self,
received_from_server = roster.received_from_server xmpp_roster=roster))
raw_roster = roster.getRaw()
roster = {} def _nec_roster_received(self, obj):
our_jid = helpers.parse_jid(gajim.get_jid_from_account(self.name)) if obj.conn.name != self.name:
return
our_jid = gajim.get_jid_from_account(self.name)
if self.connected > 1 and self.continue_connect_info: if self.connected > 1 and self.continue_connect_info:
msg = self.continue_connect_info[1] msg = self.continue_connect_info[1]
sign_msg = self.continue_connect_info[2] sign_msg = self.continue_connect_info[2]
@ -2148,37 +2152,25 @@ ConnectionJingle, ConnectionIBBytestream):
if send_first_presence: if send_first_presence:
self._send_first_presence(signed) self._send_first_presence(signed)
for jid in raw_roster: for jid in obj.roster:
try: if jid != our_jid and gajim.jid_is_transport(jid) and \
j = helpers.parse_jid(jid) not gajim.get_transport_name_from_jid(jid):
except Exception: # we can't determine which iconset to use
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 self.discoverInfo(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.connection.getRoster().delItem(jid)
elif jid != our_jid: # don't add our jid
roster[j] = raw_roster[jid]
if 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, roster_version, roster) gajim.logger.replace_roster(self.name, obj.version, obj.roster)
if received_from_server: 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 roster and \ if not contact.is_groupchat() and contact.jid not in obj.roster\
contact.jid != gajim.get_jid_from_account(self.name): and contact.jid != our_jid:
self.dispatch('ROSTER_INFO', (contact.jid, None, None, None, gajim.nec.push_incoming_event(RosterInfoEvent(None,
())) conn=self, jid=contact.jid, nickname=None, sub=None,
for jid in roster: ask=None, groups=()))
self.dispatch('ROSTER_INFO', (jid, roster[jid]['name'], for jid, info in obj.roster.items():
roster[jid]['subscription'], roster[jid]['ask'], gajim.nec.push_incoming_event(RosterInfoEvent(None,
roster[jid]['groups'])) 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]

View File

@ -275,6 +275,34 @@ class TimeRevisedRequestEvent(nec.NetworkIncomingEvent):
name = 'time-revised-request-received' name = 'time-revised-request-received'
base_network_events = [] base_network_events = []
class RosterReceivedEvent(nec.NetworkIncomingEvent):
name = 'roster-received'
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.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]
return True
class RosterSetReceivedEvent(nec.NetworkIncomingEvent): class RosterSetReceivedEvent(nec.NetworkIncomingEvent):
name = 'roster-set-received' name = 'roster-set-received'
base_network_events = [] base_network_events = []