/**
* Fetch all comments from a query. Additionally set the newest resharer as thread owner.
*
- * @param $thread_items Database statement with thread posts
+ * @param array $thread_items Database statement with thread posts
+ * @param boolean $pinned Is the item pinned?
+ *
* @return array items with parents and comments
*/
-function conversation_fetch_comments($thread_items) {
+function conversation_fetch_comments($thread_items, $pinned) {
$comments = [];
$parentlines = [];
$lineno = 0;
$parentlines[] = $lineno;
}
+ if ($row['gravity'] == GRAVITY_PARENT) {
+ $row['pinned'] = $pinned;
+ }
+
$comments[] = $row;
$lineno++;
}
$thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity']), $condition, $params);
- $comments = conversation_fetch_comments($thread_items);
+ $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false);
if (count($comments) != 0) {
$items = array_merge($items, $comments);
*
* @param integer $uid User ID
* @param array $selected Array of selected fields, empty for all
+ * @param array $condition Array of fields for condition
+ * @param array $params Array of several parameters
*
* @return boolean|object
* @throws \Exception
*/
- public static function selectPinned(int $uid, array $selected = [])
+ public static function selectPinned(int $uid, array $selected = [], array $condition = [], $params = [])
{
$useritems = DBA::select('user-item', ['iid'], ['uid' => $uid, 'pinned' => true]);
if (!DBA::isResult($useritems)) {
}
DBA::close($useritems);
- return self::selectThreadForUser($uid, $selected, ['iid' => $pinned]);
+ if (empty($pinned)) {
+ return [];
+ }
+
+ if (empty($condition) || !is_array($condition)) {
+ $condition = ['iid' => $pinned];
+ } else {
+ reset($condition);
+ $first_key = key($condition);
+ if (!is_int($first_key)) {
+ $condition['iid'] = $pinned;
+ } else {
+ $values_string = substr(str_repeat("?, ", count($pinned)), 0, -2);
+ $condition[0] = '(' . $condition[0] . ") AND `iid` IN (" . $values_string . ")";
+ $condition = array_merge($condition, $pinned);
+ }
+ }
+
+ return self::selectThreadForUser($uid, $selected, $condition, $params);
}
/**
$items = DBA::toArray($items_stmt);
if ($pager->getStart() == 0 && !empty($a->profile['profile_uid'])) {
- $pinned_items = Item::selectPinned($a->profile['profile_uid'], ['uri']);
+ $pinned_items = Item::selectPinned($a->profile['profile_uid'], ['uri', 'pinned'], ['true' . $sql_extra]);
$pinned = Item::inArray($pinned_items);
$items = array_merge($items, $pinned);
}
if (DBA::isResult($parent)) {
$origin = $parent['origin'];
}
+ } elseif ($item['pinned']) {
+ $pinned = L10n::t('pinned item');
}
if ($origin && ($item['id'] != $item['parent']) && ($item['network'] == Protocol::ACTIVITYPUB)) {
if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
if ($origin) {
- if ($item['pinned']) {
- $pinned = L10n::t('pinned item');
- }
-
$ispinned = ($item['pinned'] ? 'pinned' : 'unpinned');
$pin = [