]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
broadcast notices to jabber
authorEvan Prodromou <evan@controlezvous.ca>
Tue, 24 Jun 2008 01:42:41 +0000 (21:42 -0400)
committerEvan Prodromou <evan@controlezvous.ca>
Tue, 24 Jun 2008 01:42:41 +0000 (21:42 -0400)
darcs-hash:20080624014241-34904-39ace8e82e50e5f50c5980b5fb3256184a7c9050.gz

actions/imsettings.php
lib/jabber.php
lib/util.php

index 2fa74514a25826a5096a186872affb1bbb8cf5a0..0496aaacd5fb6be74f533413edf4ccdccd435983 100644 (file)
@@ -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 {
 
index 262fbcbb907321dc5e81b316a4e3408dfc532f7d..bf0d7cf3166b9c88e9595dc0b54f1f5d64837514 100644 (file)
@@ -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;
+}
index 7a9bed2c91b70e74424c47dad13dcadbb79def81..01457734573d778d769fe86e0e6ff3f865de56a4 100644 (file)
@@ -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;