Commit e99740bf authored by Saul Ibarra's avatar Saul Ibarra

Fixed losing contact icons

parent 714c82fb
...@@ -319,8 +319,12 @@ class PresenceSubscriptionHandler(object): ...@@ -319,8 +319,12 @@ class PresenceSubscriptionHandler(object):
response = urllib2.urlopen(req) response = urllib2.urlopen(req)
content = response.read() content = response.read()
info = response.info() info = response.info()
except (ConnectionLost, urllib2.HTTPError, urllib2.URLError): except urllib2.HTTPError, e:
return None, None if e.code == 404:
return NoIcon, None
return SameIcon, None
except (ConnectionLost, urllib2.URLError):
return SameIcon, None
content_type = info.getheader('content-type') content_type = info.getheader('content-type')
etag = info.getheader('etag') etag = info.getheader('etag')
if etag.startswith('W/'): if etag.startswith('W/'):
...@@ -331,7 +335,7 @@ class PresenceSubscriptionHandler(object): ...@@ -331,7 +335,7 @@ class PresenceSubscriptionHandler(object):
pres_content = prescontent.PresenceContentDocument.parse(content) pres_content = prescontent.PresenceContentDocument.parse(content)
content = base64.decodestring(pres_content.data.value) content = base64.decodestring(pres_content.data.value)
except Exception: except Exception:
return None, None return SameIcon, None
return content, etag return content, etag
@run_in_green_thread @run_in_green_thread
...@@ -355,7 +359,10 @@ class PresenceSubscriptionHandler(object): ...@@ -355,7 +359,10 @@ class PresenceSubscriptionHandler(object):
for contact, pidf_list in contact_pidf_map.iteritems(): for contact, pidf_list in contact_pidf_map.iteritems():
if not pidf_list: if not pidf_list:
state = note = icon_descriptor = icon_data = None state = None
note = None
icon_descriptor = None
icon_data = UnknownIcon
else: else:
services = list(chain(*(list(pidf_doc.services) for pidf_doc in pidf_list))) services = list(chain(*(list(pidf_doc.services) for pidf_doc in pidf_list)))
services.sort(key=lambda obj: obj.timestamp.value if obj.timestamp else epoch, reverse=True) services.sort(key=lambda obj: obj.timestamp.value if obj.timestamp else epoch, reverse=True)
...@@ -377,10 +384,10 @@ class PresenceSubscriptionHandler(object): ...@@ -377,10 +384,10 @@ class PresenceSubscriptionHandler(object):
else: else:
# New icon, client uses fast path mechanism # New icon, client uses fast path mechanism
icon_data, etag = self._download_icon(icon, None) icon_data, etag = self._download_icon(icon, None)
icon_descriptor = IconDescriptor(icon, icon_hash) if icon_data else None icon_descriptor = IconDescriptor(icon, icon_hash) if icon_data not in (NoIcon, SameIcon, UnknownIcon) else None
else: else:
icon_data, etag = self._download_icon(icon, contact.icon.etag if contact.icon else None) icon_data, etag = self._download_icon(icon, contact.icon.etag if contact.icon else None)
icon_descriptor = IconDescriptor(icon, etag) if icon_data else None icon_descriptor = IconDescriptor(icon, etag) if icon_data not in (NoIcon, SameIcon, UnknownIcon) else None
elif icon == unknown_icon: elif icon == unknown_icon:
icon_data = UnknownIcon icon_data = UnknownIcon
icon_descriptor = None icon_descriptor = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment