]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Merge branch 'swat0' into 0.9.x
[quix0rs-gnu-social.git] / classes / Notice.php
index 20c9c951815cf685cfdd1d50d3d0b877ce1ca99b..14477b1b53a2c17122e2baafe7891c304eb678e7 100644 (file)
@@ -121,16 +121,19 @@ class Notice extends Memcached_DataObject
             $deleted->insert();
         }
 
-        // Clear related records
+        if (Event::handle('NoticeDeleteRelated', array($this))) {
 
-        $this->clearReplies();
-        $this->clearRepeats();
-        $this->clearFaves();
-        $this->clearTags();
-        $this->clearGroupInboxes();
+            // Clear related records
 
-        // NOTE: we don't clear inboxes
-        // NOTE: we don't clear queue items
+            $this->clearReplies();
+            $this->clearRepeats();
+            $this->clearFaves();
+            $this->clearTags();
+            $this->clearGroupInboxes();
+
+            // NOTE: we don't clear inboxes
+            // NOTE: we don't clear queue items
+        }
 
         $result = parent::delete();
 
@@ -245,6 +248,8 @@ class Notice extends Memcached_DataObject
         if (!empty($options)) {
             $options = $options + $defaults;
             extract($options);
+        } else {
+            extract($defaults);
         }
 
         if (!isset($is_local)) {
@@ -485,7 +490,7 @@ class Notice extends Memcached_DataObject
     function saveKnownUrls($urls)
     {
         // @fixme validation?
-        foreach ($urls as $url) {
+        foreach (array_unique($urls) as $url) {
             File::processNew($url, $this->id);
         }
     }
@@ -893,7 +898,7 @@ class Notice extends Memcached_DataObject
         }
 
         $groups = array();
-        foreach ($group_ids as $id) {
+        foreach (array_unique($group_ids) as $id) {
             $group = User_group::staticGet('id', $id);
             if ($group) {
                 common_log(LOG_ERR, "Local delivery to group id $id, $group->nickname");
@@ -1014,24 +1019,31 @@ class Notice extends Memcached_DataObject
         if (empty($uris)) {
             return;
         }
+
         $sender = Profile::staticGet($this->profile_id);
 
-        foreach ($uris as $uri) {
+        foreach (array_unique($uris) as $uri) {
 
-            $user = User::staticGet('uri', $uri);
+            $profile = Profile::fromURI($uri);
 
-            if (!empty($user)) {
-                if ($user->hasBlocked($sender)) {
-                    continue;
-                }
+            if (empty($profile)) {
+                common_log(LOG_WARNING, "Unable to determine profile for URI '$uri'");
+                continue;
+            }
 
-                $reply = new Reply();
+            if ($profile->hasBlocked($sender)) {
+                common_log(LOG_INFO, "Not saving reply to profile {$profile->id} ($uri) from sender {$sender->id} because of a block.");
+                continue;
+            }
 
-                $reply->notice_id  = $this->id;
-                $reply->profile_id = $user->id;
+            $reply = new Reply();
 
-                $id = $reply->insert();
-            }
+            $reply->notice_id  = $this->id;
+            $reply->profile_id = $profile->id;
+
+            common_log(LOG_INFO, __METHOD__ . ": saving reply: notice $this->id to profile $profile->id");
+
+            $id = $reply->insert();
         }
 
         return;
@@ -1454,6 +1466,8 @@ class Notice extends Memcached_DataObject
             foreach ($replyProfiles as $profile) {
                 $xs->element('link', array('rel' => 'ostatus:attention',
                                            'href' => $profile->getUri()));
+                $xs->element('link', array('rel' => 'mentioned',
+                                           'href' => $profile->getUri()));
             }
             Event::handle('EndActivityAttentionProfiles', array(&$this, &$xs, $replyProfiles));
         }
@@ -1464,6 +1478,8 @@ class Notice extends Memcached_DataObject
             foreach ($groups as $group) {
                 $xs->element('link', array('rel' => 'ostatus:attention',
                                            'href' => $group->permalink()));
+                $xs->element('link', array('rel' => 'mentioned',
+                                           'href' => $group->permalink()));
             }
             Event::handle('EndActivityAttentionGroups', array(&$this, &$xs, $groups));
         }