]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Post.php
Improved profile summary for notifications
[friendica.git] / src / Model / Post.php
index 7ac7a51d2d64fa886abbf5bf6f95a137fa529207..770ab083178f41b3ee8d3a14021bbb433581ca33 100644 (file)
@@ -226,6 +226,46 @@ class Post
                }
        }
 
+       /**
+        * Retrieve a single record from the post-user-view view and returns it in an associative array
+        * When the requested record is a reshare activity, the system fetches the reshared original post.
+        * Otherwise the function reacts similar to selectFirst
+        *
+        * @param array $fields
+        * @param array $condition
+        * @param array $params
+        * @param bool  $user_mode true = post-user-view, false = post-view
+        * @return bool|array
+        * @throws \Exception
+        * @see   DBA::select
+        */
+       public static function selectOriginal(array $fields = [], array $condition = [], array $params = [])
+       {
+               $original_fields = $fields;
+               $remove = [];
+               if (!empty($fields)) {
+                       foreach (['gravity', 'verb', 'thr-parent-id', 'uid'] as $field) {
+                               if (!in_array($field, $fields)) {
+                                       $fields[] = $field;
+                                       $remove[] = $field;
+                               }
+                       }
+               }
+               $result = self::selectFirst($fields, $condition, $params);
+               if (empty($result)) {
+                       return $result;
+               }
+
+               if (($result['gravity'] != Item::GRAVITY_ACTIVITY) || ($result['verb'] != Activity::ANNOUNCE)) {
+                       foreach ($remove as $field) {
+                               unset($result[$field]);
+                       }
+                       return $result;
+               }
+
+               return self::selectFirst($original_fields, ['uri-id' => $result['thr-parent-id'], 'uid' => [0, $result['uid']]], $params);
+       }
+
        /**
         * Retrieve a single record from the post-view view and returns it in an associative array
         *
@@ -412,13 +452,13 @@ class Post
                        AND NOT `author-blocked` AND NOT `owner-blocked`
                        AND (NOT `causer-blocked` OR `causer-id` = ? OR `causer-id` IS NULL) AND NOT `contact-blocked`
                        AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?)))
-                               OR `self` OR `gravity` != ? OR `contact-uid` = ?)
+                               OR `self` OR `contact-uid` = ?)
                        AND NOT `" . $view . "`.`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `uid` = ? AND `hidden`)
                        AND NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked` AND `cid` = `author-id`)
                        AND NOT `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `blocked` AND `cid` = `owner-id`)
-                       AND NOT (`gravity` = ? AND `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `author-id`))
-                       AND NOT (`gravity` = ? AND `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `owner-id`))",
-                               0, Contact::SHARING, Contact::FRIEND, Item::GRAVITY_PARENT, 0, $uid, $uid, $uid, Item::GRAVITY_PARENT, $uid, Item::GRAVITY_PARENT, $uid]);
+                       AND NOT `author-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `author-id`)
+                       AND NOT `owner-id` IN (SELECT `cid` FROM `user-contact` WHERE `uid` = ? AND `ignored` AND `cid` = `owner-id`)",
+                               0, Contact::SHARING, Contact::FRIEND, 0, $uid, $uid, $uid, $uid, $uid]);
 
                $select_string = implode(', ', array_map([DBA::class, 'quoteIdentifier'], $selected));
 
@@ -505,6 +545,46 @@ class Post
                }
        }
 
+       /**
+        * Retrieve a single record from the post-user-view view for a given user and returns it in an associative array
+        * When the requested record is a reshare activity, the system fetches the reshared original post.
+        * Otherwise the function reacts similar to selectFirstForUser
+        *
+        * @param integer $uid User ID
+        * @param array   $selected
+        * @param array   $condition
+        * @param array   $params
+        * @return bool|array
+        * @throws \Exception
+        * @see   DBA::select
+        */
+       public static function selectOriginalForUser(int $uid, array $selected = [], array $condition = [], array $params = [])
+       {
+               $original_selected = $selected;
+               $remove = [];
+               if (!empty($selected)) {
+                       foreach (['gravity', 'verb', 'thr-parent-id'] as $field) {
+                               if (!in_array($field, $selected)) {
+                                       $selected[] = $field;
+                                       $remove[]   = $field;
+                               }
+                       }
+               }
+               $result = self::selectFirstForUser($uid, $selected, $condition, $params);
+               if (empty($result)) {
+                       return $result;
+               }
+
+               if (($result['gravity'] != Item::GRAVITY_ACTIVITY) || ($result['verb'] != Activity::ANNOUNCE)) {
+                       foreach ($remove as $field) {
+                               unset($result[$field]);
+                       }
+                       return $result;
+               }
+
+               return self::selectFirstForUser($uid, $original_selected, ['uri-id' => $result['thr-parent-id'], 'uid' => [0, $uid]], $params);
+       }
+
        /**
         * Update existing post entries
         *