mirror of
https://github.com/friendica/friendica
synced 2025-04-25 07:10:11 +00:00
Pinned posts now work for visitors in the intended way
This commit is contained in:
parent
2200996d44
commit
fc94cad5f2
4 changed files with 34 additions and 10 deletions
|
@ -148,11 +148,13 @@ class Item extends BaseObject
|
|||
*
|
||||
* @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)) {
|
||||
|
@ -165,7 +167,25 @@ class Item extends BaseObject
|
|||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -350,7 +350,7 @@ class Profile extends BaseModule
|
|||
$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);
|
||||
}
|
||||
|
|
|
@ -193,6 +193,8 @@ class Post extends BaseObject
|
|||
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)) {
|
||||
|
@ -288,10 +290,6 @@ class Post extends BaseObject
|
|||
|
||||
if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
|
||||
if ($origin) {
|
||||
if ($item['pinned']) {
|
||||
$pinned = L10n::t('pinned item');
|
||||
}
|
||||
|
||||
$ispinned = ($item['pinned'] ? 'pinned' : 'unpinned');
|
||||
|
||||
$pin = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue