Commit 82d5b407 authored by Saul Ibarra's avatar Saul Ibarra

Added support for Bonjour presence

parent 08e26d33
...@@ -86,6 +86,7 @@ class AccountExtension(SettingsObjectExtension): ...@@ -86,6 +86,7 @@ class AccountExtension(SettingsObjectExtension):
class BonjourAccountExtension(SettingsObjectExtension): class BonjourAccountExtension(SettingsObjectExtension):
msrp = BonjourMSRPSettingsExtension msrp = BonjourMSRPSettingsExtension
presence = PresenceSettingsExtension
rtp = RTPSettingsExtension rtp = RTPSettingsExtension
sip = BonjourSIPSettings sip = BonjourSIPSettings
sounds = SoundSettings sounds = SoundSettings
......
...@@ -24,6 +24,7 @@ from zope.interface import implements ...@@ -24,6 +24,7 @@ from zope.interface import implements
from sipsimple import addressbook from sipsimple import addressbook
from sipsimple.account import AccountManager, BonjourAccount from sipsimple.account import AccountManager, BonjourAccount
from sipsimple.account.bonjour import BonjourPresenceState
from sipsimple.account.xcap import Icon, OfflineStatus from sipsimple.account.xcap import Icon, OfflineStatus
from sipsimple.configuration.settings import SIPSimpleSettings from sipsimple.configuration.settings import SIPSimpleSettings
from sipsimple.payloads import caps, cipid, pidf, prescontent, rpid from sipsimple.payloads import caps, cipid, pidf, prescontent, rpid
...@@ -67,15 +68,14 @@ class PresencePublicationHandler(object): ...@@ -67,15 +68,14 @@ class PresencePublicationHandler(object):
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')
def publish(self, account=None): def publish(self, accounts):
if not account: bonjour_account = BonjourAccount()
account_manager = AccountManager()
bonjour_account = BonjourAccount()
accounts = [account for account in account_manager.get_accounts() if account is not bonjour_account and account.enabled and account.presence.enabled]
else:
accounts = [account]
for account in accounts: for account in accounts:
account.presence_state = self.build_pidf(account) if account is not bonjour_account:
account.presence_state = self.build_pidf(account)
else:
blink_settings = BlinkSettings()
account.presence_state = BonjourPresenceState(blink_settings.presence.current_state.state, blink_settings.presence.current_state.note)
def build_pidf(self, account): def build_pidf(self, account):
blink_settings = BlinkSettings() blink_settings = BlinkSettings()
...@@ -190,33 +190,35 @@ class PresencePublicationHandler(object): ...@@ -190,33 +190,35 @@ class PresencePublicationHandler(object):
def _NH_CFGSettingsObjectDidChange(self, notification): def _NH_CFGSettingsObjectDidChange(self, notification):
if notification.sender is BlinkSettings(): if notification.sender is BlinkSettings():
account_manager = AccountManager()
if set(['presence.icon', 'presence.offline_note']).intersection(notification.data.modified): if set(['presence.icon', 'presence.offline_note']).intersection(notification.data.modified):
# TODO: use a transaction here as well? -Dan # TODO: use a transaction here as well? -Dan
accounts = [account for account in AccountManager().get_accounts() if hasattr(account, 'xcap') and account.enabled and account.xcap.enabled and account.xcap.discovered] accounts = [account for account in account_manager.get_accounts() if hasattr(account, 'xcap') and account.enabled and account.xcap.enabled and account.xcap.discovered]
if 'presence.offline_note' in notification.data.modified: if 'presence.offline_note' in notification.data.modified:
self.set_xcap_offline_note(accounts) self.set_xcap_offline_note(accounts)
if 'presence.icon' in notification.data.modified: if 'presence.icon' in notification.data.modified:
self.set_xcap_icon(accounts) self.set_xcap_icon(accounts)
if 'presence.current_state' in notification.data.modified: if 'presence.current_state' in notification.data.modified:
self.publish() accounts = [account for account in account_manager.get_accounts() if account.enabled and account.presence.enabled]
self.publish(accounts)
else: else:
account = notification.sender account = notification.sender
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(['presence.enabled', 'display_name', 'xcap.enabled', 'xcap.xcap_root']).intersection(notification.data.modified) and account.presence.enabled: if set(['presence.enabled', 'display_name', 'xcap.enabled', 'xcap.xcap_root']).intersection(notification.data.modified) and account.presence.enabled:
self.publish(account) self.publish([account])
def _NH_SIPAccountWillActivate(self, notification): def _NH_SIPAccountWillActivate(self, notification):
if notification.sender is not BonjourAccount(): account = notification.sender
account = notification.sender notification.center.add_observer(self, sender=account, name='CFGSettingsObjectDidChange')
notification.center.add_observer(self, sender=account, name='CFGSettingsObjectDidChange') if account is not BonjourAccount():
notification.center.add_observer(self, sender=account, name='SIPAccountGotSelfPresenceState') notification.center.add_observer(self, sender=account, name='SIPAccountGotSelfPresenceState')
account.icon = None account.icon = None
def _NH_SIPAccountWillDeactivate(self, notification): def _NH_SIPAccountWillDeactivate(self, notification):
if notification.sender is not BonjourAccount(): account = notification.sender
account = notification.sender notification.center.remove_observer(self, sender=account, name='CFGSettingsObjectDidChange')
notification.center.remove_observer(self, sender=account, name='CFGSettingsObjectDidChange') if account is not BonjourAccount():
notification.center.remove_observer(self, sender=account, name='SIPAccountGotSelfPresenceState') notification.center.remove_observer(self, sender=account, name='SIPAccountGotSelfPresenceState')
account.icon = None account.icon = None
...@@ -278,7 +280,7 @@ class PresencePublicationHandler(object): ...@@ -278,7 +280,7 @@ class PresencePublicationHandler(object):
self._save_icon(status_icon.data, icon_hash) self._save_icon(status_icon.data, icon_hash)
if icon_desc != account.icon: if icon_desc != account.icon:
account.icon = icon_desc account.icon = icon_desc
self.publish(account) self.publish([account])
else: else:
# TODO: remove local icon? # TODO: remove local icon?
pass pass
......
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