]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/jabber.php
replies from people you're not subscribed to over Jabber
[quix0rs-gnu-social.git] / lib / jabber.php
index bd04edc63e8344aa29cad80e23e95e1dd22ab571..b0dc24bd0dfdab0a5f775dbcdfd2d7dc5ac0cba1 100644 (file)
@@ -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;
 }