Commit 0fd86e52 authored by Dan Pascu's avatar Dan Pascu

Store presence state using RuntimeSettings (fixes GUI presence state)

parent 8356bdbe
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
__all__ = ['ContactExtension', 'GroupExtension'] __all__ = ['ContactExtension', 'GroupExtension']
from sipsimple.addressbook import ContactExtension, GroupExtension, SharedSetting from sipsimple.addressbook import ContactExtension, GroupExtension, PresenceSettings, SharedSetting
from sipsimple.configuration import Setting from sipsimple.configuration import Setting, RuntimeSetting
from blink.configuration.datatypes import IconDescriptor from blink.configuration.datatypes import IconDescriptor
...@@ -14,7 +14,13 @@ from blink.configuration.datatypes import IconDescriptor ...@@ -14,7 +14,13 @@ from blink.configuration.datatypes import IconDescriptor
SharedSetting.set_namespace('ag-projects:blink') SharedSetting.set_namespace('ag-projects:blink')
class PresenceSettingsExtension(PresenceSettings):
state = RuntimeSetting(type=unicode, nillable=True, default=None)
note = RuntimeSetting(type=unicode, nillable=True, default=None)
class ContactExtension(ContactExtension): class ContactExtension(ContactExtension):
presence = PresenceSettingsExtension
icon = Setting(type=IconDescriptor, nillable=True, default=None) icon = Setting(type=IconDescriptor, nillable=True, default=None)
alternate_icon = Setting(type=IconDescriptor, nillable=True, default=None) alternate_icon = Setting(type=IconDescriptor, nillable=True, default=None)
preferred_media = SharedSetting(type=str, default='audio') preferred_media = SharedSetting(type=str, default='audio')
......
...@@ -793,8 +793,6 @@ class Contact(object): ...@@ -793,8 +793,6 @@ class Contact(object):
def __init__(self, contact, group): def __init__(self, contact, group):
self.settings = contact self.settings = contact
self.group = group self.group = group
self.state = None
self.note = None
notification_center = NotificationCenter() notification_center = NotificationCenter()
notification_center.add_observer(ObserverWeakrefProxy(self), sender=contact) notification_center.add_observer(ObserverWeakrefProxy(self), sender=contact)
...@@ -822,7 +820,7 @@ class Contact(object): ...@@ -822,7 +820,7 @@ class Contact(object):
return '%s(%r, %r)' % (self.__class__.__name__, self.settings, self.group) return '%s(%r, %r)' % (self.__class__.__name__, self.settings, self.group)
def __getstate__(self): def __getstate__(self):
return (self.settings.id, dict(group=self.group, state=self.state, note=self.note)) return (self.settings.id, dict(group=self.group))
def __setstate__(self, state): def __setstate__(self, state):
contact_id, state = state contact_id, state = state
...@@ -866,6 +864,14 @@ class Contact(object): ...@@ -866,6 +864,14 @@ class Contact(object):
except StopIteration: except StopIteration:
return u'' return u''
@property
def state(self):
return self.settings.presence.state
@property
def note(self):
return self.settings.presence.note
@property @property
def icon(self): def icon(self):
try: try:
...@@ -916,16 +922,6 @@ class Contact(object): ...@@ -916,16 +922,6 @@ class Contact(object):
self.__dict__.pop('pixmap', None) self.__dict__.pop('pixmap', None)
notification.center.post_notification('BlinkContactDidChange', sender=self) notification.center.post_notification('BlinkContactDidChange', sender=self)
def _NH_AddressbookContactGotPresenceUpdate(self, notification):
self.state = notification.data.state
self.note = notification.data.note
if notification.data.icon_data:
icon = IconManager().store_data(self.settings.id, notification.data.icon_data)
if icon:
self.settings.icon = notification.data.icon_descriptor
self.settings.save()
notification.center.post_notification('BlinkContactDidChange', sender=self)
class ContactDetail(object): class ContactDetail(object):
implements(IObserver) implements(IObserver)
...@@ -943,8 +939,6 @@ class ContactDetail(object): ...@@ -943,8 +939,6 @@ class ContactDetail(object):
def __init__(self, contact): def __init__(self, contact):
self.settings = contact self.settings = contact
self.state = None
self.note = None
notification_center = NotificationCenter() notification_center = NotificationCenter()
notification_center.add_observer(ObserverWeakrefProxy(self), sender=contact) notification_center.add_observer(ObserverWeakrefProxy(self), sender=contact)
...@@ -952,7 +946,7 @@ class ContactDetail(object): ...@@ -952,7 +946,7 @@ class ContactDetail(object):
return '%s(%r)' % (self.__class__.__name__, self.settings) return '%s(%r)' % (self.__class__.__name__, self.settings)
def __getstate__(self): def __getstate__(self):
return (self.settings.id, dict(state=self.state, note=self.note)) return (self.settings.id, {})
def __setstate__(self, state): def __setstate__(self, state):
contact_id, state = state contact_id, state = state
...@@ -996,6 +990,14 @@ class ContactDetail(object): ...@@ -996,6 +990,14 @@ class ContactDetail(object):
except StopIteration: except StopIteration:
return u'' return u''
@property
def state(self):
return self.settings.presence.state
@property
def note(self):
return self.settings.presence.note
@property @property
def icon(self): def icon(self):
try: try:
...@@ -1046,11 +1048,6 @@ class ContactDetail(object): ...@@ -1046,11 +1048,6 @@ class ContactDetail(object):
self.__dict__.pop('pixmap', None) self.__dict__.pop('pixmap', None)
notification.center.post_notification('BlinkContactDetailDidChange', sender=self) notification.center.post_notification('BlinkContactDetailDidChange', sender=self)
def _NH_AddressbookContactGotPresenceUpdate(self, notification):
self.state = notification.data.state
self.note = notification.data.note
notification.center.post_notification('BlinkContactDetailDidChange', sender=self)
class ContactURI(object): class ContactURI(object):
implements(IObserver) implements(IObserver)
...@@ -1066,8 +1063,6 @@ class ContactURI(object): ...@@ -1066,8 +1063,6 @@ class ContactURI(object):
self.contact = contact self.contact = contact
self.uri = uri self.uri = uri
self.default = default self.default = default
self.state = None
self.note = None
notification_center = NotificationCenter() notification_center = NotificationCenter()
notification_center.add_observer(ObserverWeakrefProxy(self), sender=contact) notification_center.add_observer(ObserverWeakrefProxy(self), sender=contact)
...@@ -1075,7 +1070,7 @@ class ContactURI(object): ...@@ -1075,7 +1070,7 @@ class ContactURI(object):
return '%s(%r, %r)' % (self.__class__.__name__, self.contact, self.uri) return '%s(%r, %r)' % (self.__class__.__name__, self.contact, self.uri)
def __getstate__(self): def __getstate__(self):
state_dict = dict(default=self.default, state=self.state, note=self.note) state_dict = dict(default=self.default)
if isinstance(self.contact, addressbook.Contact): if isinstance(self.contact, addressbook.Contact):
uri_id = self.uri.id uri_id = self.uri.id
else: else:
......
...@@ -364,7 +364,6 @@ class PresenceSubscriptionHandler(object): ...@@ -364,7 +364,6 @@ class PresenceSubscriptionHandler(object):
@run_in_green_thread @run_in_green_thread
def _process_presence_data(self, uris=None): def _process_presence_data(self, uris=None):
addressbook_manager = addressbook.AddressbookManager() addressbook_manager = addressbook.AddressbookManager()
notification_center = NotificationCenter()
current_pidf_map = {} current_pidf_map = {}
contact_pidf_map = {} contact_pidf_map = {}
...@@ -395,8 +394,9 @@ class PresenceSubscriptionHandler(object): ...@@ -395,8 +394,9 @@ class PresenceSubscriptionHandler(object):
note = unicode(next(iter(service.notes))) if service.notes else None note = unicode(next(iter(service.notes))) if service.notes else None
icon = unicode(service.icon) if service.icon else None icon = unicode(service.icon) if service.icon else None
# review this logic (add NotChanged, NoIcon, ... markers to better represent the icon data and icon descriptor) -Dan
icon_data = icon_descriptor = None icon_data = icon_descriptor = None
if icon and icon != unknown_icon and (not contact.icon or (contact.icon and not contact.icon.is_local)): if icon and icon != unknown_icon:
if 'blink-icon' in icon and contact.icon and icon == contact.icon.url: if 'blink-icon' in icon and contact.icon and icon == contact.icon.url:
# Fast path, icon hasn't changed # Fast path, icon hasn't changed
pass pass
...@@ -404,9 +404,16 @@ class PresenceSubscriptionHandler(object): ...@@ -404,9 +404,16 @@ class PresenceSubscriptionHandler(object):
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)
if icon_data: if icon_data:
icon_descriptor = IconDescriptor(icon, etag) icon_descriptor = IconDescriptor(icon, etag)
self._update_contact_presence_state(contact, state, note, icon_descriptor, icon_data)
data = NotificationData(state=state, note=note, icon_descriptor=icon_descriptor, icon_data=icon_data) @run_in_gui_thread
notification_center.post_notification('AddressbookContactGotPresenceUpdate', sender=contact, data=data) def _update_contact_presence_state(self, contact, state, note, icon_descriptor, icon_data):
contact.presence.state = state
contact.presence.note = note
if icon_data:
IconManager().store_data(contact.id, icon_data)
contact.icon = icon_descriptor
contact.save()
def handle_notification(self, notification): def handle_notification(self, notification):
handler = getattr(self, '_NH_%s' % notification.name, Null) handler = getattr(self, '_NH_%s' % notification.name, Null)
......
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