Commit b5c0d80f authored by Dan Pascu's avatar Dan Pascu

Fixed some of the presence logic

parent 10f43be7
...@@ -49,8 +49,8 @@ class PresencePublicationHandler(object): ...@@ -49,8 +49,8 @@ class PresencePublicationHandler(object):
notification_center = NotificationCenter() notification_center = NotificationCenter()
notification_center.add_observer(self, name='SIPAccountWillActivate') notification_center.add_observer(self, name='SIPAccountWillActivate')
notification_center.add_observer(self, name='SIPAccountWillDeactivate') notification_center.add_observer(self, name='SIPAccountWillDeactivate')
notification_center.add_observer(self, name='SIPAccountDidDiscoverXCAPSupport')
notification_center.add_observer(self, name='SystemDidWakeUpFromSleep') notification_center.add_observer(self, name='SystemDidWakeUpFromSleep')
notification_center.add_observer(self, name='XCAPManagerDidDiscoverServerCapabilities')
notification_center.add_observer(self, name='XCAPManagerDidReloadData') notification_center.add_observer(self, name='XCAPManagerDidReloadData')
notification_center.add_observer(self, sender=BlinkSettings(), name='CFGSettingsObjectDidChange') notification_center.add_observer(self, sender=BlinkSettings(), name='CFGSettingsObjectDidChange')
try: try:
...@@ -62,8 +62,8 @@ class PresencePublicationHandler(object): ...@@ -62,8 +62,8 @@ class PresencePublicationHandler(object):
notification_center = NotificationCenter() notification_center = NotificationCenter()
notification_center.remove_observer(self, name='SIPAccountWillActivate') notification_center.remove_observer(self, name='SIPAccountWillActivate')
notification_center.remove_observer(self, name='SIPAccountWillDeactivate') notification_center.remove_observer(self, name='SIPAccountWillDeactivate')
notification_center.remove_observer(self, name='SIPAccountDidDiscoverXCAPSupport')
notification_center.remove_observer(self, name='SystemDidWakeUpFromSleep') notification_center.remove_observer(self, name='SystemDidWakeUpFromSleep')
notification_center.remove_observer(self, name='XCAPManagerDidDiscoverServerCapabilities')
notification_center.remove_observer(self, name='XCAPManagerDidReloadData') notification_center.remove_observer(self, name='XCAPManagerDidReloadData')
notification_center.remove_observer(self, sender=BlinkSettings(), name='CFGSettingsObjectDidChange') notification_center.remove_observer(self, sender=BlinkSettings(), name='CFGSettingsObjectDidChange')
...@@ -161,7 +161,7 @@ class PresencePublicationHandler(object): ...@@ -161,7 +161,7 @@ class PresencePublicationHandler(object):
blink_settings = BlinkSettings() blink_settings = BlinkSettings()
if not account: if not account:
account_manager = AccountManager() account_manager = AccountManager()
accounts = [account for account in account_manager.get_accounts() if hasattr(account, 'xcap') and account.xcap.discovered] accounts = [account for account in account_manager.get_accounts() if hasattr(account, 'xcap') and account.xcap.enabled and account.xcap.discovered]
else: else:
accounts = [account] accounts = [account]
for account in accounts: for account in accounts:
...@@ -172,7 +172,7 @@ class PresencePublicationHandler(object): ...@@ -172,7 +172,7 @@ class PresencePublicationHandler(object):
blink_settings = BlinkSettings() blink_settings = BlinkSettings()
if not account: if not account:
account_manager = AccountManager() account_manager = AccountManager()
accounts = [account for account in account_manager.get_accounts() if hasattr(account, 'xcap') and account.xcap.discovered] accounts = [account for account in account_manager.get_accounts() if hasattr(account, 'xcap') and account.xcap.enabled and account.xcap.discovered]
else: else:
accounts = [account] accounts = [account]
try: try:
...@@ -209,18 +209,9 @@ class PresencePublicationHandler(object): ...@@ -209,18 +209,9 @@ class PresencePublicationHandler(object):
self.publish() self.publish()
else: else:
account = notification.sender account = notification.sender
if 'presence.enabled' in notification.data.modified:
if account.presence.enabled:
self.publish(account)
# The account itself will unpublish when presence is disabled
return
if set(['xcap.enabled', 'xcap.xcap_root']).intersection(notification.data.modified): if set(['xcap.enabled', 'xcap.xcap_root']).intersection(notification.data.modified):
account.icon = None account.icon = None
if set(['display_name', 'xcap.enabled', 'xcap.discovered']).intersection(notification.data.modified): if set(['presence.enabled', 'display_name', 'xcap.enabled', 'xcap.xcap_root']).intersection(notification.data.modified) and account.presence.enabled:
if 'xcap.discovered' in notification.data.modified and account.xcap.enabled and account.xcap.discovered:
with account.xcap_manager.transaction():
self.set_xcap_offline_note(account)
self.set_xcap_icon(account)
self.publish(account) self.publish(account)
def _NH_SIPAccountWillActivate(self, notification): def _NH_SIPAccountWillActivate(self, notification):
...@@ -264,10 +255,11 @@ class PresencePublicationHandler(object): ...@@ -264,10 +255,11 @@ class PresencePublicationHandler(object):
blink_settings.presence.state_history = [new_state] + [state for state in blink_settings.presence.state_history if state!=new_state] blink_settings.presence.state_history = [new_state] + [state for state in blink_settings.presence.state_history if state!=new_state]
blink_settings.save() blink_settings.save()
def _NH_XCAPManagerDidDiscoverServerCapabilities(self, notification): def _NH_SIPAccountDidDiscoverXCAPSupport(self, notification):
account = notification.sender.account account = notification.sender
if account.enabled and account.presence.enabled: with account.xcap_manager.transaction():
self.publish(account) self.set_xcap_offline_note(account)
self.set_xcap_icon(account)
def _NH_XCAPManagerDidReloadData(self, notification): def _NH_XCAPManagerDidReloadData(self, notification):
account = notification.sender.account account = notification.sender.account
......
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