]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
a hook for showing the default local nav
[quix0rs-gnu-social.git] / classes / Notice.php
index edd1b02cffe8a71d58e8697c33dd932561adfaf2..a4f530c44facfe768ed9aec178a5a749d8249448 100644 (file)
@@ -342,6 +342,14 @@ class Notice extends Memcached_DataObject
         $notice->uri = $uri;
         $notice->url = $url;
 
+        // Get the groups here so we can figure out replies and such
+
+        if (!isset($groups)) {
+            $groups = self::groupsFromText($notice->content, $profile);
+        }
+
+        $reply = null;
+
         // Handle repeat case
 
         if (isset($repeat_of)) {
@@ -379,18 +387,35 @@ class Notice extends Memcached_DataObject
 
             $notice->repeat_of = $repeat_of;
         } else {
-            $notice->reply_to = self::getReplyTo($reply_to, $profile_id, $source, $final);
-        }
+            $reply = self::getReplyTo($reply_to, $profile_id, $source, $final);
+
+            if (!empty($reply)) {
+
+                if (!$reply->inScope($profile)) {
+                    // TRANS: Client error displayed when trying to reply to a notice a the target has no access to.
+                    // TRANS: %1$s is a user nickname, %2$d is a notice ID (number).
+                    throw new ClientException(sprintf(_('%1$s has no access to notice %2$d.'),
+                                                      $profile->nickname, $reply->id), 403);
+                }
+
+                $notice->reply_to     = $reply->id;
+                $notice->conversation = $reply->conversation;
+
+                // If the original is private to a group, and notice has no group specified,
+                // make it to the same group(s)
 
-        if (!empty($notice->reply_to)) {
-            $reply = Notice::staticGet('id', $notice->reply_to);
-            if (!$reply->inScope($profile)) {
-                // TRANS: Client error displayed when trying to reply to a notice a the target has no access to.
-                // TRANS: %1$s is a user nickname, %2$d is a notice ID (number).
-                throw new ClientException(sprintf(_('%1$s has no access to notice %2$d.'),
-                                                  $profile->nickname, $reply->id), 403);
+                if (empty($groups) && ($reply->scope | Notice::GROUP_SCOPE)) {
+                    $groups = array();
+                    $replyGroups = $reply->getGroups();
+                    foreach ($replyGroups as $group) {
+                        if ($profile->isMember($group)) {
+                            $groups[] = $group->id;
+                        }
+                    }
+                }
+
+                // Scope set below
             }
-            $notice->conversation = $reply->conversation;
         }
 
         if (!empty($lat) && !empty($lon)) {
@@ -416,7 +441,11 @@ class Notice extends Memcached_DataObject
         }
 
         if (is_null($scope)) { // 0 is a valid value
-            $notice->scope = common_config('notice', 'defaultscope');
+            if (!empty($reply)) {
+                $notice->scope = $reply->scope;
+            } else {
+                $notice->scope = common_config('notice', 'defaultscope');
+            }
         } else {
             $notice->scope = $scope;
         }
@@ -435,10 +464,6 @@ class Notice extends Memcached_DataObject
 
         // Force the scope for private groups
 
-        if (!isset($groups)) {
-            $groups = self::groupsFromText($notice->content, $profile);
-        }
-
         foreach ($groups as $groupId) {
             $group = User_group::staticGet('id', $groupId);
             if (!empty($group)) {
@@ -1529,7 +1554,7 @@ class Notice extends Memcached_DataObject
         if (!empty($reply_to)) {
             $reply_notice = Notice::staticGet('id', $reply_to);
             if (!empty($reply_notice)) {
-                return $reply_to;
+                return $reply_notice;
             }
         }
 
@@ -1568,8 +1593,10 @@ class Notice extends Memcached_DataObject
         $last = $recipient->getCurrentNotice();
 
         if (!empty($last)) {
-            return $last->id;
+            return $last;
         }
+
+        return null;
     }
 
     static function maxContent()