diff options
author | Evan Prodromou <evan@controlezvous.ca> | 2008-06-23 21:42:41 -0400 |
---|---|---|
committer | Evan Prodromou <evan@controlezvous.ca> | 2008-06-23 21:42:41 -0400 |
commit | a8a2f40696daf5dbb290fd16ce998beb6a219aaf (patch) | |
tree | 2a37c2bf750bbdc58e3100c9d651d4d275f49bfa | |
parent | d1e55b3777fe5c988c6ec605987d5c616cbdbc06 (diff) |
broadcast notices to jabber
darcs-hash:20080624014241-34904-39ace8e82e50e5f50c5980b5fb3256184a7c9050.gz
-rw-r--r-- | actions/imsettings.php | 1 | ||||
-rw-r--r-- | lib/jabber.php | 29 | ||||
-rw-r--r-- | lib/util.php | 3 |
3 files changed, 32 insertions, 1 deletions
diff --git a/actions/imsettings.php b/actions/imsettings.php index 2fa74514a..0496aaacd 100644 --- a/actions/imsettings.php +++ b/actions/imsettings.php @@ -20,6 +20,7 @@ if (!defined('LACONICA')) { exit(1); } require_once(INSTALLDIR.'/lib/settingsaction.php'); +require_once(INSTALLDIR.'/lib/jabber.php'); class ImsettingsAction extends SettingsAction { diff --git a/lib/jabber.php b/lib/jabber.php index 262fbcbb9..bf0d7cf31 100644 --- a/lib/jabber.php +++ b/lib/jabber.php @@ -19,6 +19,8 @@ if (!defined('LACONICA')) { exit(1); } +require_once('xmpp.php'); + function jabber_valid_base_jid($jid) { # Cheap but effective return Validate::email($jid); @@ -96,4 +98,31 @@ function jabber_confirm_address($code, $nickname, $address) { jabber_send_message($address, $body); } + +function jabber_broadcast_notice($notice) { + # First, get users subscribed to this profile + # XXX: use a join here rather than looping through results + $profile = Profile::staticGet($notice->profile_id); + if (!$profile) { + common_log(LOG_WARNING, 'Refusing to broadcast notice with ' . + 'unknown profile ' . common_log_objstring($notice), + __FILE__); + return false; + } + $sub = new Subscription(); + $sub->subscribed = $notice->profile_id; + if ($sub->find()) { + $msg = jabber_format_notice($profile, $notice); + while ($sub->fetch()) { + $user = User::staticGet($sub->subscriber); + if ($user && $user->jabber) { + jabber_send_message($user->jabber, + $msg); + } + } + } +} +function jabber_format_notice(&$profile, &$notice) { + return = $profile->nickname . ': ' . $notice->content; +} diff --git a/lib/util.php b/lib/util.php index 7a9bed2c9..014577345 100644 --- a/lib/util.php +++ b/lib/util.php @@ -649,7 +649,8 @@ function common_broadcast_notice($notice, $remote=false) { require_once(INSTALLDIR.'/lib/omb.php'); omb_broadcast_remote_subscribers($notice); } - // XXX: broadcast notices to Jabber + require_once(INSTALLDIR.'/lib/jabber.php'); + jabber_broadcast_notice($notice); // XXX: broadcast notices to SMS // XXX: broadcast notices to other IM return true; |