/** @var Activity $activity */
$activity = BaseObject::getClass(Activity::class);
- if ($activity->isHidden($item['verb'])) {
+ if (empty($item['verb']) || $activity->isHidden($item['verb'])) {
return false;
}
/**
* 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);
/** @var Activity $activity */
$activity = BaseObject::getClass(Activity::class);
- if ($activity->match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
+ if (!empty($item['verb']) && $activity->match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
$author = ['uid' => 0, 'id' => $item['author-id'],
'network' => $item['author-network'], 'url' => $item['author-link']];
$url = Contact::magicLinkByContact($author);
}
}
- if (stristr($order, 'received')) {
+ if (stristr($order, 'pinned_received')) {
+ usort($parents, 'sort_thr_pinned_received');
+ } elseif (stristr($order, 'received')) {
usort($parents, 'sort_thr_received');
} elseif (stristr($order, 'commented')) {
usort($parents, 'sort_thr_commented');
$parents[$i]['children'] = sort_item_children($parents[$i]['children']);
}
- if (PConfig::get(local_user(), 'system', 'smart_threading', 0)) {
+ if (!PConfig::get(local_user(), 'system', 'no_smart_threading', 0)) {
foreach ($parents as $i => $parent) {
$parents[$i] = smart_flatten_conversation($parent);
}
return $parents;
}
+/**
+ * @brief usort() callback to sort item arrays by pinned and the received key
+ *
+ * @param array $a
+ * @param array $b
+ * @return int
+ */
+function sort_thr_pinned_received(array $a, array $b)
+{
+ if ($b['pinned'] && !$a['pinned']) {
+ return 1;
+ } elseif (!$b['pinned'] && $a['pinned']) {
+ return -1;
+ }
+
+ return strcmp($b['received'], $a['received']);
+}
+
/**
* @brief usort() callback to sort item arrays by the received key
*