]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Introduced common_location_shared() to check if location sharing is always,
[quix0rs-gnu-social.git] / classes / Notice.php
index 6781918be4ae410e2b654466673ff0bbee31f859..cc00cd1dd6ac5432b9036c28c404664339b9503d 100644 (file)
@@ -330,7 +330,7 @@ class Notice extends Managed_DataObject
      * Record the given set of hash tags in the db for this notice.
      * Given tag strings will be normalized and checked for dupes.
      */
-    function saveKnownTags($hashtags)
+    function saveKnownTags(array $hashtags)
     {
         //turn each into their canonical tag
         //this is needed to remove dupes before saving e.g. #hash.tag = #hashtag
@@ -974,8 +974,6 @@ class Notice extends Managed_DataObject
         // reasonably handle notifications themselves.
         if (ActivityUtils::compareVerbs($stored->verb, array(ActivityVerb::POST))) {
 
-            $stored->saveAttentions($act->context->attention);
-
             if (!empty($tags)) {
                 $stored->saveKnownTags($tags);
             } else {
@@ -984,7 +982,7 @@ class Notice extends Managed_DataObject
 
             // Note: groups may save tags, so must be run after tags are saved
             // to avoid errors on duplicates.
-            // Note: groups should always be set.
+            $stored->saveAttentions($act->context->attention);
 
             if (!empty($urls)) {
                 $stored->saveKnownUrls($urls);
@@ -1153,7 +1151,7 @@ class Notice extends Managed_DataObject
      *
      * @return void
      */
-    function saveKnownUrls($urls)
+    function saveKnownUrls(array $urls)
     {
         if (common_config('attachments', 'process_links')) {
             // @fixme validation?
@@ -1581,14 +1579,27 @@ class Notice extends Managed_DataObject
                 continue;
             }
 
-            $this->saveAttention($target);
+            try {
+                $this->saveAttention($target);
+            } catch (AlreadyFulfilledException $e) {
+                common_debug('Attention already exists: '.var_export($e->getMessage(),true));
+            } catch (Exception $e) {
+                common_log(LOG_ERR, "Could not save notice id=={$this->getID()} attention for profile id=={$target->getID()}: {$e->getMessage()}");
+            }
         }
     }
 
+    /**
+     * Saves an attention for a profile (user or group) which means
+     * it shows up in their home feed and such.
+     */
     function saveAttention(Profile $target, $reason=null)
     {
         if ($target->isGroup()) {
-            // FIXME: Make sure we check that users are in the groups they send to!
+            // FIXME: Make sure we check (for both local and remote) users are in the groups they send to!
+
+            // legacy notification method, will still be in use for quite a while I think
+            $this->addToGroupInbox($target->getGroup());
         } else {
             if ($target->hasBlocked($this->getProfile())) {
                 common_log(LOG_INFO, "Not saving reply to profile {$target->id} ($uri) from sender {$sender->id} because of a block.");
@@ -1597,17 +1608,11 @@ class Notice extends Managed_DataObject
         }
 
         if ($target->isLocal()) {
-            // is local user
-            $this->saveReply($target->getID());   // since we still have the Reply table which some apparently use!
+            // legacy notification method, will still be in use for quite a while I think
+            $this->saveReply($target->getID());
         }
 
-        try {
-            $att = Attention::saveNew($this, $target, $reason);
-        } catch (AlreadyFulfilledException $e) {
-            common_debug('Could not save Attention: '.$e->getMessage());
-        } catch (Exception $e) {
-            common_log(LOG_ERR, 'Could not save Attention: '.$e->getMessage());
-        }
+        $att = Attention::saveNew($this, $target, $reason);
 
         self::blow('reply:stream:%d', $target->getID());
         return true;
@@ -1758,7 +1763,7 @@ class Notice extends Managed_DataObject
         return $this->_replies[$this->getID()];
     }
 
-    function _setReplies($replies)
+    function _setReplies(array $replies)
     {
         $this->_replies[$this->getID()] = $replies;
     }
@@ -1853,7 +1858,7 @@ class Notice extends Managed_DataObject
                }
 
                $groups = User_group::multiGet('id', $ids);
-               $this->_groups[$this->id] = $groups->fetchAll();
+               $this->_setGroups($groups->fetchAll());
                return $this->_groups[$this->id];
     }
 
@@ -1954,19 +1959,11 @@ class Notice extends Managed_DataObject
                 }
             }
 
-            $reply_ids = $this->getReplies();
-
-            foreach ($reply_ids as $id) {
-                $rprofile = Profile::getKV('id', $id);
-                if ($rprofile instanceof Profile) {
-                    $ctx->attention[$rprofile->getUri()] = ActivityObject::PERSON;
-                }
-            }
-
-            $groups = $this->getGroups();
-
-            foreach ($groups as $group) {
-                $ctx->attention[$group->getUri()] = ActivityObject::GROUP;
+            // This covers the legacy getReplies and getGroups too which get their data
+            // from entries stored via Notice::saveNew (which we want to move away from)...
+            foreach ($this->getAttentionProfiles() as $target) {
+                // User and group profiles which get the attention of this notice
+                $ctx->attention[$target->getUri()] = $target->getObjectType();
             }
 
             switch ($this->scope) {
@@ -2733,7 +2730,7 @@ class Notice extends Managed_DataObject
      *
      * @return boolean whether the profile is in the notice's scope
      */
-    function inScope($profile)
+    function inScope(Profile $profile=null)
     {
         if (is_null($profile)) {
             $keypart = sprintf('notice:in-scope-for:%d:null', $this->id);
@@ -2756,7 +2753,7 @@ class Notice extends Managed_DataObject
         return ($result == 1) ? true : false;
     }
 
-    protected function _inScope($profile)
+    protected function _inScope(Profile $profile=null)
     {
         $scope = is_null($this->scope) ? self::defaultScope() : $this->getScope();
 
@@ -2821,7 +2818,7 @@ class Notice extends Managed_DataObject
         return !$this->isHiddenSpam($profile);
     }
 
-    function isHiddenSpam($profile) {
+    function isHiddenSpam(Profile $profile=null) {
 
         // Hide posts by silenced users from everyone but moderators.
 
@@ -2906,7 +2903,7 @@ class Notice extends Managed_DataObject
        return $scope;
     }
 
-       static function fillProfiles($notices)
+       static function fillProfiles(array $notices)
        {
                $map = self::getProfiles($notices);
                foreach ($notices as $entry=>$notice) {
@@ -2923,7 +2920,7 @@ class Notice extends Managed_DataObject
                return array_values($map);
        }
 
-       static function getProfiles(&$notices)
+       static function getProfiles(array &$notices)
        {
                $ids = array();
                foreach ($notices as $notice) {
@@ -2933,7 +2930,7 @@ class Notice extends Managed_DataObject
                return Profile::pivotGet('id', $ids);
        }
 
-       static function fillGroups(&$notices)
+       static function fillGroups(array &$notices)
        {
         $ids = self::_idsOf($notices);
         $gis = Group_inbox::listGet('notice_id', $ids);
@@ -2968,7 +2965,7 @@ class Notice extends Managed_DataObject
                return array_keys($ids);
     }
 
-    static function fillAttachments(&$notices)
+    static function fillAttachments(array &$notices)
     {
         $ids = self::_idsOf($notices);
         $f2pMap = File_to_post::listGet('post_id', $ids);
@@ -2992,7 +2989,7 @@ class Notice extends Managed_DataObject
                }
     }
 
-    static function fillReplies(&$notices)
+    static function fillReplies(array &$notices)
     {
         $ids = self::_idsOf($notices);
         $replyMap = Reply::listGet('notice_id', $ids);