quick frontend(contact_list): avoid crash when resource in cache has not priority

This commit is contained in:
Goffi 2016-10-02 13:46:29 +02:00
commit 95f77b1df1

View file

@ -501,7 +501,9 @@ class ProfileContactList(object):
resource_data[C.PRESENCE_STATUSES] = statuses
if entity.bare not in self._specials:
priority_resource = max(resources_data, key=lambda res: resources_data[res][C.PRESENCE_PRIORITY])
# we may have resources with no priority
# (when a cached value is added for a not connected resource)
priority_resource = max(resources_data, key=lambda res: resources_data[res].get(C.PRESENCE_PRIORITY, -2**32))
cache[C.CONTACT_MAIN_RESOURCE] = priority_resource
self.update([entity], C.UPDATE_MODIFY, self.profile)