From 499afd8c22fa7b14c5d757f52b1e8e6a91bbaf30 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 15 Jul 2008 15:55:13 -0400 Subject: replies from people you're not subscribed to over Jabber darcs-hash:20080715195513-84dde-454419c971015be385d9c4c35f7acbee419031f9.gz --- lib/jabber.php | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'lib/jabber.php') diff --git a/lib/jabber.php b/lib/jabber.php index bd04edc63..b0dc24bd0 100644 --- a/lib/jabber.php +++ b/lib/jabber.php @@ -194,8 +194,6 @@ function jabber_special_presence($type, $to=NULL, $show=NULL, $status=NULL) { } 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 ' . @@ -203,23 +201,50 @@ function jabber_broadcast_notice($notice) { __FILE__); return false; } + $sent_to = array(); + # First, get users who this is a direct reply to + $reply = new Reply(); + $reply->notice_id = $notice->id; + if ($reply->find()) { + while ($reply->fetch()) { + $user = User::staticGet($reply->profile_id); + if ($user && $user->jabber && $user->jabbernotify && $user->jabberreplies) { + common_log(LOG_INFO, + 'Sending reply notice ' . $notice->id . ' to ' . $user->jabber, + __FILE__); + $success = jabber_send_notice($user->jabber, $notice); + if ($success) { + # Remember so we don't send twice + $sent_to[$user->id] = true; + } else { + # XXX: Not sure, but I think that's the right thing to do + return false; + } + } + } + } + # Now, get users subscribed to this profile + # XXX: use a join here rather than looping through results $sub = new Subscription(); $sub->subscribed = $notice->profile_id; + if ($sub->find()) { while ($sub->fetch()) { $user = User::staticGet($sub->subscriber); - if ($user && $user->jabber && $user->jabbernotify) { + if ($user && $user->jabber && $user->jabbernotify && !$sent_to[$user->id]) { common_log(LOG_INFO, 'Sending notice ' . $notice->id . ' to ' . $user->jabber, __FILE__); $success = jabber_send_notice($user->jabber, $notice); - if (!$success) { + if ($success) { + $sent_to[$user->id] = true; # XXX: Not sure, but I think that's the right thing to do return false; } } } } + return true; } -- cgit v1.2.3-54-g00ecf