]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'master' of gitorious.org:statusnet/mainline into testing
authorBrion Vibber <brion@pobox.com>
Tue, 20 Apr 2010 11:52:18 +0000 (13:52 +0200)
committerBrion Vibber <brion@pobox.com>
Tue, 20 Apr 2010 11:52:18 +0000 (13:52 +0200)
classes/Notice.php
doc-src/sms
lib/distribqueuehandler.php
lib/mail.php
lib/util.php
scripts/commandline.inc

index 0d8525637586b26a2bc7f02ea09582c80de9660b..5c75ec520f7f4ad67a1bf14c7e8619bb0216fbcd 100644 (file)
@@ -980,8 +980,7 @@ class Notice extends Memcached_DataObject
      * messages, we won't deliver to any remote targets as that's the
      * source service's responsibility.
      *
-     * @fixme Unlike saveReplies() there's no mail notification here.
-     *        Move that to distrib queue handler?
+     * Mail notifications etc will be handled later.
      *
      * @param array of unique identifier URIs for recipients
      */
@@ -1020,8 +1019,7 @@ class Notice extends Memcached_DataObject
      * and save reply records indicating that this message needs to be
      * delivered to those users.
      *
-     * Side effect: local recipients get e-mail notifications here.
-     * @fixme move mail notifications to distrib?
+     * Mail notifications to local profiles will be sent later.
      *
      * @return array of integer profile IDs
      */
@@ -1081,17 +1079,14 @@ class Notice extends Memcached_DataObject
 
         $recipientIds = array_keys($replied);
 
-        foreach ($recipientIds as $recipientId) {
-            $user = User::staticGet('id', $recipientId);
-            if (!empty($user)) {
-                self::blow('reply:stream:%d', $reply->profile_id);
-                mail_notify_attn($user, $this);
-            }
-        }
-
         return $recipientIds;
     }
 
+    /**
+     * Pull the complete list of @-reply targets for this notice.
+     *
+     * @return array of integer profile ids
+     */
     function getReplies()
     {
         // XXX: cache me
@@ -1114,6 +1109,31 @@ class Notice extends Memcached_DataObject
         return $ids;
     }
 
+    /**
+     * Send e-mail notifications to local @-reply targets.
+     *
+     * Replies must already have been saved; this is expected to be run
+     * from the distrib queue handler.
+     */
+    function sendReplyNotifications()
+    {
+        // Don't send reply notifications for repeats
+
+        if (!empty($this->repeat_of)) {
+            return array();
+        }
+
+        $recipientIds = $this->getReplies();
+
+        foreach ($recipientIds as $recipientId) {
+            $user = User::staticGet('id', $recipientId);
+            if (!empty($user)) {
+                self::blow('reply:stream:%d', $recipientId);
+                mail_notify_attn($user, $this);
+            }
+        }
+    }
+
     /**
      * Pull list of groups this notice needs to be delivered to,
      * as previously recorded by saveGroups() or saveKnownGroups().
index 1a3064318fa7f6ce42dbd8814e08617a01505ea7..6cdccc6e97443f1ff2a59d21f7ac08ea210b1fbd 100644 (file)
@@ -1,4 +1,4 @@
-You can post messages to %%site.name%% using many kinds of cell
+You can post messages to %%site.name%% using many kinds of cell
 phones that support SMS messaging. This site does not support SMS
 directly; rather, it uses your carrier's email gateway to send and
 receive messages.
index d2be7a92c72488d846374bb27413f103490fd34d..8f4b72d5c37e3128cb782aabea4475d0d1d88a14 100644 (file)
@@ -49,25 +49,34 @@ class DistribQueueHandler
     }
 
     /**
-     * Here's the meat of your queue handler -- you're handed a Notice
-     * object, which you may do as you will with.
+     * Handle distribution of a notice after we've saved it:
+     * @li add to local recipient inboxes
+     * @li send email notifications to local @-reply targets
+     * @li run final EndNoticeSave plugin events
+     * @li put any remaining post-processing into the queues
      *
      * If this function indicates failure, a warning will be logged
      * and the item is placed back in the queue to be re-run.
      *
+     * @fixme addToInboxes is known to fail sometimes with large recipient sets
+     *
      * @param Notice $notice
      * @return boolean true on success, false on failure
      */
     function handle($notice)
     {
-        // XXX: do we need to change this for remote users?
-
         try {
             $notice->addToInboxes();
         } catch (Exception $e) {
             $this->logit($notice, $e);
         }
 
+        try {
+            $notice->sendReplyNotifications();
+        } catch (Exception $e) {
+            $this->logit($notice, $e);
+        }
+
         try {
             Event::handle('EndNoticeSave', array($notice));
             // Enqueue for other handlers
index c38d9f2f504b3b79e923a2c2100a74a2083feff3..5fc584e28aa8636d99b099fa3c7949f5c9c5ef30 100644 (file)
@@ -636,7 +636,7 @@ function mail_notify_attn($user, $notice)
 
     $bestname = $sender->getBestName();
 
-    common_init_locale($user->language);
+    common_switch_locale($user->language);
 
     if ($notice->hasConversation()) {
         $conversationUrl = common_local_url('conversation',
@@ -679,7 +679,7 @@ function mail_notify_attn($user, $notice)
 
     $headers = _mail_prepare_headers('mention', $user->nickname, $sender->nickname);
 
-    common_init_locale();
+    common_switch_locale();
     mail_to_user($user, $subject, $body, $headers);
 }
 
index 6905df839a3f6a3ba84306053420a6dbf317350d..c0013bb3da4db96627e0e7723bf1ac0e8007e7e4 100644 (file)
@@ -41,11 +41,13 @@ function common_init_locale($language=null)
     }
     putenv('LANGUAGE='.$language);
     putenv('LANG='.$language);
-    return setlocale(LC_ALL, $language . ".utf8",
+    $ok =  setlocale(LC_ALL, $language . ".utf8",
                      $language . ".UTF8",
                      $language . ".utf-8",
                      $language . ".UTF-8",
                      $language);
+
+    return $ok;
 }
 
 function common_init_language()
@@ -89,6 +91,32 @@ function common_init_language()
         $locale_set = common_init_locale($language);
     }
 
+    common_init_gettext();
+}
+
+/**
+ * @access private
+ */
+function common_init_gettext()
+{
+    setlocale(LC_CTYPE, 'C');
+    // So we do not have to make people install the gettext locales
+    $path = common_config('site','locale_path');
+    bindtextdomain("statusnet", $path);
+    bind_textdomain_codeset("statusnet", "UTF-8");
+    textdomain("statusnet");
+}
+
+/**
+ * Switch locale during runtime, and poke gettext until it cries uncle.
+ * Otherwise, sometimes it doesn't actually switch away from the old language.
+ *
+ * @param string $language code for locale ('en', 'fr', 'pt_BR' etc)
+ */
+function common_switch_locale($language=null)
+{
+    common_init_locale($language);
+
     setlocale(LC_CTYPE, 'C');
     // So we do not have to make people install the gettext locales
     $path = common_config('site','locale_path');
@@ -97,6 +125,7 @@ function common_init_language()
     textdomain("statusnet");
 }
 
+
 function common_timezone()
 {
     if (common_logged_in()) {
index 9029bb19db4e7df9879d73fccbb4b792124c8599..a475e11d01abba19ba7fb9ba8126f00f312388c7 100644 (file)
@@ -123,6 +123,10 @@ require_once INSTALLDIR . '/lib/common.php';
 
 set_error_handler('common_error_handler');
 
+// Set up the language infrastructure so we can localize anything that
+// needs to be sent out to users, such as mail notifications.
+common_init_language();
+
 function _make_matches($opt, $alt)
 {
     $matches = array();