+ $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
+
+ if (DI::pConfig()->get($uid, 'system', 'infinite_scroll')) {
+ $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
+ $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
+ } else {
+ $o = '';
+ }
+
+ $condition1 = DBA::mergeConditions($condition, ["`$contact_field` = ?", $cid]);
+
+ $condition2 = DBA::mergeConditions($condition, [
+ "`author-id` = ? AND `gravity` = ? AND `vid` = ? AND `protocol` != ? AND `thr-parent-id` = `parent-uri-id`",
+ $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Conversation::PARCEL_DIASPORA
+ ]);
+
+ $sql1 = "SELECT `uri-id`, `received` FROM `post-thread-user-view` WHERE " . array_shift($condition1);
+ $sql2 = "SELECT `thr-parent-id` AS `uri-id`, `received` FROM `post-user-view` WHERE " . array_shift($condition2);
+
+ $union = array_merge($condition1, $condition2);
+ $sql = $sql1 . " UNION " . $sql2;
+
+ $sql .= " ORDER BY `received` DESC LIMIT ?, ?";
+ $union = array_merge($union, [$pager->getStart(), $pager->getItemsPerPage()]);
+ $items = Post::toArray(DBA::p($sql, $union));
+
+ if ($pager->getStart() == 0) {
+ $fields = ['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'received'];
+ $pinned = Post\Collection::selectToArrayForContact($cid, Post\Collection::FEATURED, $fields);
+ $items = array_merge($items, $pinned);
+ }
+
+ $o .= DI::conversation()->render($items, ConversationContent::MODE_CONTACTS, $update, false, 'pinned_received', $uid);
+