]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Updated main translation file after adding strings
[friendica.git] / include / conversation.php
index 0d21f877ad7bf6b22dc2e8786e85104ef1a37c10..0051b09866f700f71eee9d2db4a7aaeffbcf9567 100644 (file)
@@ -33,10 +33,11 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
+use Friendica\Model\Post;
 use Friendica\Model\Profile;
 use Friendica\Model\Tag;
 use Friendica\Model\Verb;
-use Friendica\Object\Post;
+use Friendica\Object\Post as PostObject;
 use Friendica\Object\Thread;
 use Friendica\Protocol\Activity;
 use Friendica\Util\Crypto;
@@ -201,7 +202,7 @@ function localize_item(&$item)
                if ($activity->match($item['verb'], Activity::TAG)) {
                        $fields = ['author-id', 'author-link', 'author-name', 'author-network',
                                'verb', 'object-type', 'resource-id', 'body', 'plink'];
-                       $obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]);
+                       $obj = Post::selectFirst($fields, ['uri' => $item['parent-uri']]);
                        if (!DBA::isResult($obj)) {
                                return;
                        }
@@ -324,8 +325,7 @@ function conv_get_blocklist()
        $blocklist = [];
 
        foreach (explode(',', $str_blocked) as $entry) {
-               // The 4th parameter guarantees that there always will be a public contact entry
-               $cid = Contact::getIdForURL(trim($entry), 0, false, ['url' => trim($entry)]);
+               $cid = Contact::getIdForURL(trim($entry), 0, false);
                if (!empty($cid)) {
                        $blocklist[] = $cid;
                }
@@ -678,7 +678,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                                $item['pagedrop'] = $page_dropping;
 
                                if ($item['gravity'] == GRAVITY_PARENT) {
-                                       $item_object = new Post($item);
+                                       $item_object = new PostObject($item);
                                        $conv->addParent($item_object);
                                }
                        }
@@ -711,24 +711,24 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
  *
  * @param mixed   $thread_items Database statement with thread posts
  * @param boolean $pinned       Is the item pinned?
- * @param integer $causer       Contact ID of the resharer
+ * @param array   $activity     Contact data of the resharer
  *
  * @return array items with parents and comments
  */
-function conversation_fetch_comments($thread_items, $pinned, $causer) {
+function conversation_fetch_comments($thread_items, bool $pinned, array $activity) {
        $comments = [];
 
-       while ($row = Item::fetch($thread_items)) {
-               if (!empty($causer)) {
+       while ($row = Post::fetch($thread_items)) {
+               if (!empty($activity)) {
                        if (($row['gravity'] == GRAVITY_PARENT)) {
                                $row['post-type'] = Item::PT_ANNOUNCEMENT;
-                               $row['causer-id'] = $causer;
-                               $contact = Contact::getById($causer, ['url', 'name', 'thumb']);
+                               $row = array_merge($row, $activity);
+                               $contact = Contact::getById($activity['causer-id'], ['url', 'name', 'thumb']);
                                $row['causer-link'] = $contact['url'];
                                $row['causer-avatar'] = $contact['thumb'];
                                $row['causer-name'] = $contact['name'];
                        } elseif (($row['gravity'] == GRAVITY_ACTIVITY) && ($row['verb'] == Activity::ANNOUNCE) &&
-                               ($row['author-id'] == $causer)) {
+                               ($row['author-id'] == $activity['causer-id'])) {
                                continue;
                        }
                }
@@ -763,7 +763,7 @@ function conversation_fetch_comments($thread_items, $pinned, $causer) {
                                }
 
                                if (($row['gravity'] == GRAVITY_PARENT) && !empty($row['causer-id'])) {
-                                       $row['reshared'] = DI::l10n()->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkbyId($row['causer-id'])) .'">' . htmlentities($name) . '</a>');
+                                       $row['reshared'] = DI::l10n()->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkById($row['causer-id'])) .'">' . htmlentities($name) . '</a>');
                                }
                                $row['direction'] = ['direction' => 3, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Reshared') : DI::l10n()->t('Reshared by %s', $name))];
                                break;
@@ -827,15 +827,22 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
 
        foreach ($parents AS $parent) {
                if (!empty($parent['thr-parent-id']) && !empty($parent['gravity']) && ($parent['gravity'] == GRAVITY_ACTIVITY)) {
-                       $condition = ["`item`.`parent-uri-id` = ? AND `item`.`uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
+                       $condition = ["`parent-uri-id` = ? AND `uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
                                $parent['thr-parent-id'], $uid, Verb::getID(Activity::FOLLOW)];
-                       $causer = $parent['author-id'] ?? 0;
+                       if (!empty($parent['author-id'])) {
+                               $activity = ['causer-id' => $parent['author-id']];
+                               foreach (['commented', 'received', 'created'] as $orderfields) {
+                                       if (!empty($parent[$orderfields])) {
+                                               $activity[$orderfields] = $parent[$orderfields];        
+                                       }       
+                               }
+                       }
                } else {
-                       $condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
+                       $condition = ["`parent-uri` = ? AND `uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
                                $parent['uri'], $uid, Verb::getID(Activity::FOLLOW)];
-                       $causer = 0;
+                       $activity = [];
                }
-               $items = conversation_fetch_items($parent, $items, $condition, $block_authors, $params, $causer);
+               $items = conversation_fetch_items($parent, $items, $condition, $block_authors, $params, $activity);
        }
 
        foreach ($items as $index => $item) {
@@ -857,17 +864,17 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
  * @param array   $condition     SQL condition
  * @param boolean $block_authors Don't show posts from contacts that are hidden (used on the community page)
  * @param array   $params        SQL parameters
- * @param integer $causer        Contact ID of the resharer
+ * @param array   $activity      Contact data of the resharer
  * @return array
  */
-function conversation_fetch_items(array $parent, array $items, array $condition, bool $block_authors, array $params, int $causer) {
+function conversation_fetch_items(array $parent, array $items, array $condition, bool $block_authors, array $params, array $activity) {
        if ($block_authors) {
-               $condition[0] .= " AND NOT `author`.`hidden`";
+               $condition[0] .= " AND NOT `author-hidden`";
        }
 
-       $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity', 'post-type']), $condition, $params);
+       $thread_items = Post::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['pinned', 'contact-uid', 'gravity', 'post-type']), $condition, $params);
 
-       $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false, $causer);
+       $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false, $activity);
 
        if (count($comments) != 0) {
                $items = array_merge($items, $comments);
@@ -1034,13 +1041,8 @@ function builtin_activity_puller(array $activity, array &$conv_responses)
                                $activity['thr-parent'] = $activity['parent-uri'];
                        }
 
-                       // only list each unique author once
-                       if (in_array($link, $conv_responses[$mode][$activity['thr-parent']]['links'])) {
-                               continue;
-                       }
-
                        // Skip when the causer of the parent is the same than the author of the announce
-                       if (($verb == Activity::ANNOUNCE) && Item::exists(['uri' => $activity['thr-parent'],
+                       if (($verb == Activity::ANNOUNCE) && Post::exists(['uri' => $activity['thr-parent'],
                                'uid' => $activity['uid'], 'causer-id' => $activity['author-id'], 'gravity' => GRAVITY_PARENT])) {
                                continue;
                        }
@@ -1050,6 +1052,9 @@ function builtin_activity_puller(array $activity, array &$conv_responses)
                                        'links' => [],
                                        'self' => 0,
                                ];
+                       } elseif (in_array($link, $conv_responses[$mode][$activity['thr-parent']]['links'])) {
+                               // only list each unique author once
+                               continue;
                        }
 
                        if (public_contact() == $activity['author-id']) {
@@ -1173,7 +1178,8 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
                '$term'      => DI::l10n()->t('Tag term:'),
                '$fileas'    => DI::l10n()->t('Save to Folder:'),
                '$whereareu' => DI::l10n()->t('Where are you right now?'),
-               '$delitems'  => DI::l10n()->t("Delete item\x28s\x29?")
+               '$delitems'  => DI::l10n()->t("Delete item\x28s\x29?"),
+               '$is_mobile' => DI::mode()->isMobile(),
        ]);
 
        $jotplugins = '';