Merge pull request #7823 from annando/pin

We can now pin posts
This commit is contained in:
Hypolite Petovan 2019-11-07 15:10:03 -05:00 committed by GitHub
commit b8f2252a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 166 additions and 15 deletions

View File

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2019.09-rc (Dalmatian Bellflower)
-- DB_UPDATE_VERSION 1322
-- Friendica 2019.12-dev (Dalmatian Bellflower)
-- DB_UPDATE_VERSION 1324
-- ------------------------------------------
@ -1281,7 +1281,9 @@ CREATE TABLE IF NOT EXISTS `user-item` (
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
`hidden` boolean NOT NULL DEFAULT '0' COMMENT 'Marker to hide an item from the user',
`ignored` boolean COMMENT 'Ignore this thread if set',
PRIMARY KEY(`uid`,`iid`)
`pinned` boolean COMMENT 'The item is pinned on the profile page',
PRIMARY KEY(`uid`,`iid`),
INDEX `uid_pinned` (`uid`,`pinned`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific item data';
--

View File

@ -1451,7 +1451,9 @@ function conv_sort(array $item_list, $order)
}
}
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');
@ -1488,6 +1490,24 @@ function conv_sort(array $item_list, $order)
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
*

View File

@ -58,7 +58,7 @@ class Item extends BaseObject
'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'owner-network',
'contact-id', 'contact-uid', 'contact-link', 'contact-name', 'contact-avatar',
'writable', 'self', 'cid', 'alias',
'writable', 'self', 'cid', 'alias', 'pinned',
'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
'event-summary', 'event-desc', 'event-location', 'event-type',
'event-nofinish', 'event-adjust', 'event-ignore', 'event-id',
@ -114,6 +114,60 @@ class Item extends BaseObject
return self::$legacy_mode;
}
/**
* Set the pinned state of an item
*
* @param integer $iid Item ID
* @param integer $uid User ID
* @param boolean $pinned Pinned state
*/
public static function setPinned(int $iid, int $uid, bool $pinned)
{
DBA::update('user-item', ['pinned' => $pinned], ['iid' => $iid, 'uid' => $uid], true);
}
/**
* 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)
{
$useritem = DBA::selectFirst('user-item', ['pinned'], ['iid' => $iid, 'uid' => $uid]);
if (!DBA::isResult($useritem)) {
return false;
}
return (bool)$useritem['pinned'];
}
/**
* @brief Select pinned rows from the item table for a given user
*
* @param integer $uid User ID
* @param array $selected Array of selected fields, empty for all
*
* @return boolean|object
* @throws \Exception
*/
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
*
@ -585,7 +639,7 @@ class Item extends BaseObject
'iaid' => 'internal-iaid'];
if ($usermode) {
$fields['user-item'] = ['ignored' => 'internal-user-ignored'];
$fields['user-item'] = ['pinned', 'ignored' => 'internal-user-ignored'];
}
$fields['item-activity'] = ['activity', 'activity' => 'internal-activity'];

View File

@ -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,7 +349,13 @@ class Profile extends BaseModule
$items = DBA::toArray($items_stmt);
$o .= conversation($a, $items, $pager, 'profile', $update, false, 'received', $a->profile['profile_uid']);
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, 'pinned_received', $a->profile['profile_uid']);
if (!$update) {
$o .= $pager->renderMinimal(count($items));

View File

@ -140,8 +140,11 @@ class Post extends BaseObject
$sparkle = '';
$buttons = '';
$dropping = false;
$pinned = '';
$pin = false;
$star = false;
$ignore = false;
$ispinned = "unpinned";
$isstarred = "unstarred";
$indent = '';
$shiny = '';
@ -284,6 +287,23 @@ 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 = [
'do' => L10n::t('pin'),
'undo' => L10n::t('unpin'),
'toggle' => L10n::t('toggle pin status'),
'classdo' => $item['pinned'] ? 'hidden' : '',
'classundo' => $item['pinned'] ? '' : 'hidden',
'pinned' => L10n::t('pinned'),
];
}
$isstarred = (($item['starred']) ? "starred" : "unstarred");
$star = [
@ -407,6 +427,9 @@ class Post extends BaseObject
'owner_name' => $owner_name_e,
'plink' => Item::getPlink($item),
'edpost' => $edpost,
'ispinned' => $ispinned,
'pin' => $pin,
'pinned' => $pinned,
'isstarred' => $isstarred,
'star' => $star,
'ignore' => $ignore,

View File

@ -34,7 +34,7 @@
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1323);
define('DB_UPDATE_VERSION', 1324);
}
return [
@ -1384,10 +1384,12 @@ return [
"iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"],
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["user" => "uid"], "comment" => "User id"],
"hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marker to hide an item from the user"],
"ignored" => ["type" => "boolean", "comment" => "Ignore this thread if set"]
"ignored" => ["type" => "boolean", "comment" => "Ignore this thread if set"],
"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" => [

View File

@ -179,8 +179,9 @@ return [
'/{type}/{customize}/{name}' => [Module\Photo::class, [R::GET]],
],
'/pretheme' => [Module\ThemeDetails::class, [R::GET]],
'/probe' => [Module\Debug\Probe::class, [R::GET]],
'/pinned/{item:\d+}' => [Module\Pinned::class, [R::GET]],
'/pretheme' => [Module\ThemeDetails::class, [R::GET]],
'/probe' => [Module\Debug\Probe::class, [R::GET]],
'/profile' => [
'/{nickname}' => [Module\Profile::class, [R::GET]],

View File

@ -626,6 +626,25 @@ function dostar(ident) {
});
}
function dopin(ident) {
ident = ident.toString();
$('#like-rotator-' + ident).show();
$.get('pinned/' + ident, function(data) {
if (data.match(/1/)) {
$('#pinned-' + ident).addClass('pinned');
$('#pinned-' + ident).removeClass('unpinned');
$('#pin-' + ident).addClass('hidden');
$('#unpin-' + ident).removeClass('hidden');
} else {
$('#pinned-' + ident).addClass('unpinned');
$('#pinned-' + ident).removeClass('pinned');
$('#pin-' + ident).removeClass('hidden');
$('#unpin-' + ident).addClass('hidden');
}
$('#like-rotator-' + ident).hide();
});
}
function doignore(ident) {
ident = ident.toString();
$('#like-rotator-' + ident).show();

View File

@ -50,7 +50,7 @@
</div>
<div class="wall-item-author">
<a href="{{$item.profile_url}}" target="redir" title="{{$item.linktitle}}" class="wall-item-name-link"><span class="wall-item-name{{$item.sparkle}}" id="wall-item-name-{{$item.id}}" >{{$item.name}}</span></a>{{if $item.owner_url}} {{$item.to}} <a href="{{$item.owner_url}}" target="redir" title="{{$item.olinktitle}}" class="wall-item-name-link"><span class="wall-item-name{{$item.osparkle}}" id="wall-item-ownername-{{$item.id}}">{{$item.owner_name}}</span></a> {{$item.vwall}}{{/if}}<br />
<div class="wall-item-ago" id="wall-item-ago-{{$item.id}}" title="{{$item.localtime}}"><time class="dt-published" datetime="{{$item.localtime}}">{{$item.ago}}</time></div>
<div class="wall-item-ago" id="wall-item-ago-{{$item.id}}" title="{{$item.localtime}}"><time class="dt-published" datetime="{{$item.localtime}}">{{$item.ago}}</time><span class="pinned">{{$item.pinned}}</span></div>
</div>
<div class="wall-item-content" id="wall-item-content-{{$item.id}}" >
<div class="wall-item-title p-name" id="wall-item-title-{{$item.id}}">{{$item.title}}</div>
@ -90,6 +90,9 @@
<a class="editpost icon pencil" href="{{$item.edpost.0}}" title="{{$item.edpost.1}}"></a>
{{/if}}
{{if $item.pin}}
<a href="#" id="pinned-{{$item.id}}" onclick="dopin({{$item.id}}); return false;" class="pin-item icon {{$item.ispinned}}" title="{{$item.pin.toggle}}"></a>
{{/if}}
{{if $item.star}}
<a href="#" id="starred-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>
{{/if}}

View File

@ -118,6 +118,13 @@ as the value of $top_child_total (this is done at the end of this file)
</li>
{{/if}}
{{if $item.pin}}
<li role="menuitem">
<button type="button" id="pin-{{$item.id}}" onclick="dopin({{$item.id}});" class="btn-link {{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="fa fa-check-square-o" aria-hidden="true"></i>&nbsp;{{$item.pin.do}}</button>
<button type="button" id="unpin-{{$item.id}}" onclick="dopin({{$item.id}});" class="btn-link {{$item.pin.classundo}}" title="{{$item.pin.undo}}"><i class="fa fa-check-square" aria-hidden="true"></i>&nbsp;{{$item.pin.undo}}</button>
</li>
{{/if}}
{{if $item.star}}
<li role="menuitem">
<button type="button" id="star-{{$item.id}}" onclick="dostar({{$item.id}});" class="btn-link {{$item.star.classdo}}" title="{{$item.star.do}}"><i class="fa fa-star-o" aria-hidden="true"></i>&nbsp;{{$item.star.do}}</button>
@ -229,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}}
<span class="pinned">{{$item.pinned}}</span>
</small>
</div>

View File

@ -88,11 +88,16 @@
class="wall-item-name-link"><span
class="wall-item-name{{$item.sparkle}}">{{$item.name}}</span></a>
<span class="wall-item-ago" title="{{$item.localtime}}"><time class="dt-published" datetime="{{$item.localtime}}">{{$item.ago}}</time></span>
<span class="pinned">{{$item.pinned}}</span>
{{if $item.owner_url}}<br/>{{$item.to}} <a href="{{$item.owner_url}}" target="redir" title="{{$item.olinktitle}}" class="wall-item-name-link"><span class="wall-item-name{{$item.osparkle}}" id="wall-item-ownername-{{$item.id}}">{{$item.owner_name}}</span></a> {{$item.vwall}}
{{/if}}
</div>
<div class="wall-item-actions-social">
{{if $item.pin}}
<a href="#" id="pin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;" class="{{$item.pin.classdo}}" title="{{$item.pin.do}}">{{$item.pin.do}}</a>
<a href="#" id="unpin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;" class="{{$item.pin.classundo}}" title="{{$item.pin.undo}}">{{$item.pin.undo}}</a>
{{/if}}
{{if $item.star}}
<a href="#" id="star-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="{{$item.star.classdo}}" title="{{$item.star.do}}">{{$item.star.do}}</a>
<a href="#" id="unstar-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}">{{$item.star.undo}}</a>

View File

@ -54,7 +54,7 @@
<span class="wall-item-name{{$item.sparkle}}" id="wall-item-name-{{$item.id}}" >{{$item.name}}</span>
</a>
<div class="wall-item-ago">&bull;</div>
<div class="wall-item-ago" id="wall-item-ago-{{$item.id}}" title="{{$item.localtime}}"><time class="dt-published" datetime="{{$item.localtime}}">{{$item.ago}}</time></div>
<div class="wall-item-ago" id="wall-item-ago-{{$item.id}}" title="{{$item.localtime}}"><time class="dt-published" datetime="{{$item.localtime}}">{{$item.ago}}</time><span class="pinned">{{$item.pinned}}</span></div>
</div>
<div>
@ -107,6 +107,9 @@
</div>
{{/if}}
{{if $item.pin}}
<a href="#" id="pinned-{{$item.id}}" onclick="dopin({{$item.id}}); return false;" class="pin-item icon {{$item.ispinned}}" title="{{$item.pin.toggle}}"></a>
{{/if}}
{{if $item.star}}
<a href="#" id="starred-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>
{{/if}}

View File

@ -60,6 +60,7 @@
{{if $item.owner_self}}
{{include file="sub/delivery_count.tpl" delivery=$item.delivery}}
{{/if}}
<span class="pinned">{{$item.pinned}}</span>
</span>
{{if $item.lock}}<span class="icon s10 lock fakelink" onclick="lockview(event,{{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}
<span class="wall-item-network" title="{{$item.app}}">
@ -122,6 +123,10 @@
{{/if}}
{{/if}}
{{if $item.pin}}
<a role="button" id="pin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;" class="{{$item.pin.classdo}}" title="{{$item.pin.do}}"><i class="icon-pin icon-large"><span class="sr-only">{{$item.pin.do}}</span></i></a>
<a role="button" id="unpin-{{$item.id}}" onclick="dopin({{$item.id}}); return false;" class="{{$item.pin.classundo}}" title="{{$item.pin.undo}}"><i class="icon-pin-empty icon-large"><span class="sr-only">{{$item.pin.undo}}</span></i></a>
{{/if}}
{{if $item.star}}
<a role="button" id="star-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="{{$item.star.classdo}}" title="{{$item.star.do}}"><i class="icon-star icon-large"><span class="sr-only">{{$item.star.do}}</span></i></a>
<a role="button" id="unstar-{{$item.id}}" onclick="dostar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="icon-star-empty icon-large"><span class="sr-only">{{$item.star.undo}}</span></i></a>