From ed58af25a56fdf35f964e0f45ec1c82102c55e83 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 7 Nov 2019 06:53:18 +0000 Subject: [PATCH] show pinned items --- database.sql | 3 ++- src/Model/Item.php | 22 ++++++++++++++++--- src/Module/Profile.php | 8 ++++++- src/Object/Post.php | 6 +++++ static/dbstructure.config.php | 3 ++- view/templates/wall_thread.tpl | 2 +- view/theme/frio/templates/wall_thread.tpl | 1 + view/theme/quattro/templates/wall_thread.tpl | 1 + view/theme/smoothly/templates/wall_thread.tpl | 2 +- view/theme/vier/templates/wall_thread.tpl | 1 + 10 files changed, 41 insertions(+), 8 deletions(-) diff --git a/database.sql b/database.sql index e80c5cda22..86207a1221 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 882aa6444b..98b058215d 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 69db45acf1..ac345fad24 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 f3c607ee64..f9119ee032 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 65e0b26a6a..7f4cd71286 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 001bdaebb4..0816400d52 100644 --- a/view/templates/wall_thread.tpl +++ b/view/templates/wall_thread.tpl @@ -50,7 +50,7 @@
{{$item.name}}{{if $item.owner_url}} {{$item.to}} {{$item.owner_name}} {{$item.vwall}}{{/if}}
-
+
{{$item.pinned}}
{{$item.title}}
diff --git a/view/theme/frio/templates/wall_thread.tpl b/view/theme/frio/templates/wall_thread.tpl index cffe1087bd..31f13ea379 100644 --- a/view/theme/frio/templates/wall_thread.tpl +++ b/view/theme/frio/templates/wall_thread.tpl @@ -236,6 +236,7 @@ as the value of $top_child_total (this is done at the end of this file) {{if $item.owner_self}} {{include file="sub/delivery_count.tpl" delivery=$item.delivery}} {{/if}} + {{$item.pinned}}
diff --git a/view/theme/quattro/templates/wall_thread.tpl b/view/theme/quattro/templates/wall_thread.tpl index c3d6500021..77d63f6e5d 100644 --- a/view/theme/quattro/templates/wall_thread.tpl +++ b/view/theme/quattro/templates/wall_thread.tpl @@ -88,6 +88,7 @@ class="wall-item-name-link">{{$item.name}} + {{$item.pinned}} {{if $item.owner_url}}
{{$item.to}} {{$item.owner_name}} {{$item.vwall}} {{/if}} diff --git a/view/theme/smoothly/templates/wall_thread.tpl b/view/theme/smoothly/templates/wall_thread.tpl index 7b56c9130f..b372fbefbc 100644 --- a/view/theme/smoothly/templates/wall_thread.tpl +++ b/view/theme/smoothly/templates/wall_thread.tpl @@ -54,7 +54,7 @@ {{$item.name}}
-
+
{{$item.pinned}}
diff --git a/view/theme/vier/templates/wall_thread.tpl b/view/theme/vier/templates/wall_thread.tpl index 1d432ea453..c27ec33cdc 100644 --- a/view/theme/vier/templates/wall_thread.tpl +++ b/view/theme/vier/templates/wall_thread.tpl @@ -60,6 +60,7 @@ {{if $item.owner_self}} {{include file="sub/delivery_count.tpl" delivery=$item.delivery}} {{/if}} + {{$item.pinned}} {{if $item.lock}}{{$item.lock}}{{/if}}