From c48caa85e12063c2df9913957dbd11af6b5e3ea6 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 20 Apr 2010 12:06:54 +0200 Subject: Fix email notifications for @-replies that come via OStatus. * Moved notification sending from Notice::saveReplies to distrib queue handler, so it'll pull from the reply set we've saved regardless of how we got it. * Set up gettext infrastructure for command-line scripts; gets localization mail notifications etc working from background queues. * Adjusted locale switching: common_switch_locale() works at runtime for bg scripts, forces a message catalog update --- classes/Notice.php | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index a8147e4c4..4cf12fc6f 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -959,8 +959,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 */ @@ -999,8 +998,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 */ @@ -1060,17 +1058,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 @@ -1093,6 +1088,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(). -- cgit v1.2.3-54-g00ecf