diff --git a/database.sql b/database.sql index e80c5cda2..86207a122 100644 --- a/database.sql +++ b/database.sql @@ -1282,7 +1282,8 @@ CREATE TABLE IF NOT EXISTS `user-item` ( `hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide an item from the user', `ignored` boolean COMMENT 'Ignore this thread if set', `pinned` boolean COMMENT 'The item is pinned on the profile page', - PRIMARY KEY(`uid`,`iid`) + PRIMARY KEY(`uid`,`iid`), + INDEX `uid_pinned` (`uid`,`pinned`) ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific item data'; -- diff --git a/src/Model/Item.php b/src/Model/Item.php index 882aa6444..98b058215 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -116,7 +116,7 @@ class Item extends BaseObject /** * Set the pinned state of an item - * + * * @param integer $iid Item ID * @param integer $uid User ID * @param boolean $pinned Pinned state @@ -128,10 +128,10 @@ class Item extends BaseObject /** * Get the pinned state - * + * * @param integer $iid Item ID * @param integer $uid User ID - * + * * @return boolean pinned state */ public static function getPinned(int $iid, int $uid) @@ -143,6 +143,22 @@ class Item extends BaseObject return (bool)$useritem['pinned']; } + public static function selectPinned(int $uid, array $selected = []) + { + $useritems = DBA::select('user-item', ['iid'], ['uid' => $uid, 'pinned' => true]); + if (!DBA::isResult($useritems)) { + return $useritems; + } + + $pinned = []; + while ($useritem = self::fetch($useritems)) { + $pinned[] = $useritem['iid']; + } + DBA::close($useritems); + + return self::selectThreadForUser($uid, $selected, ['iid' => $pinned]); + } + /** * @brief returns an activity index from an activity string * diff --git a/src/Module/Profile.php b/src/Module/Profile.php index 69db45acf..ac345fad2 100644 --- a/src/Module/Profile.php +++ b/src/Module/Profile.php @@ -177,7 +177,7 @@ class Profile extends BaseModule } if (!$update) { - $tab = Strings::escapeTags(trim($_GET['tab'] ?? '')); + $tab = Strings::escapeTags(trim($_GET['tab'] ?? '')); $o .= ProfileModel::getTabs($a, $tab, $is_owner, $a->profile['nickname']); @@ -349,6 +349,12 @@ class Profile extends BaseModule $items = DBA::toArray($items_stmt); + if ($pager->getStart() == 0) { + $pinned_items = Item::selectPinned($a->profile['profile_uid'], ['uri']); + $pinned = Item::inArray($pinned_items); + $items = array_merge($items, $pinned); + } + $o .= conversation($a, $items, $pager, 'profile', $update, false, 'received', $a->profile['profile_uid']); if (!$update) { diff --git a/src/Object/Post.php b/src/Object/Post.php index f3c607ee6..f9119ee03 100644 --- a/src/Object/Post.php +++ b/src/Object/Post.php @@ -140,6 +140,7 @@ class Post extends BaseObject $sparkle = ''; $buttons = ''; $dropping = false; + $pinned = ''; $pin = false; $star = false; $ignore = false; @@ -287,6 +288,10 @@ 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 = [ @@ -424,6 +429,7 @@ class Post extends BaseObject 'edpost' => $edpost, 'ispinned' => $ispinned, 'pin' => $pin, + 'pinned' => $pinned, 'isstarred' => $isstarred, 'star' => $star, 'ignore' => $ignore, diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 65e0b26a6..7f4cd7128 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -1388,7 +1388,8 @@ return [ "pinned" => ["type" => "boolean", "comment" => "The item is pinned on the profile page"] ], "indexes" => [ - "PRIMARY" => ["uid", "iid"] + "PRIMARY" => ["uid", "iid"], + "uid_pinned" => ["uid", "pinned"] ] ], "worker-ipc" => [ diff --git a/view/templates/wall_thread.tpl b/view/templates/wall_thread.tpl index 001bdaebb..0816400d5 100644 --- a/view/templates/wall_thread.tpl +++ b/view/templates/wall_thread.tpl @@ -50,7 +50,7 @@