Merge pull request #9891 from MrPetovan/task/9782-item-star

Move GET starred/{id} to POST item/{id}/star
This commit is contained in:
Michael Vogel 2021-01-31 22:42:57 +01:00 committed by GitHub
commit ee6699e641
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 64 additions and 43 deletions

View file

@ -19,33 +19,38 @@
* *
*/ */
namespace Friendica\Module; namespace Friendica\Module\Item;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Post; use Friendica\Model\Post;
use Friendica\Network\HTTPException;
/** /**
* Toggle starred items * Toggle starred items
*/ */
class Starred extends BaseModule class Star extends BaseModule
{ {
public static function rawContent(array $parameters = []) public static function rawContent(array $parameters = [])
{ {
if (!local_user()) { $l10n = DI::l10n();
throw new \Friendica\Network\HTTPException\ForbiddenException();
if (!Session::isAuthenticated()) {
throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
} }
if (empty($parameters['item'])) { if (empty($parameters['id'])) {
throw new \Friendica\Network\HTTPException\BadRequestException(); throw new HTTPException\BadRequestException();
} }
$itemId = intval($parameters['item']); $itemId = intval($parameters['id']);
$item = Post::selectFirstForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $itemId]); $item = Post::selectFirstForUser(local_user(), ['starred'], ['uid' => local_user(), 'id' => $itemId]);
if (empty($item)) { if (empty($item)) {
throw new \Friendica\Network\HTTPException\NotFoundException(); throw new HTTPException\NotFoundException();
} }
$starred = !(bool)$item['starred']; $starred = !(bool)$item['starred'];
@ -53,14 +58,25 @@ class Starred extends BaseModule
Item::update(['starred' => $starred], ['id' => $itemId]); Item::update(['starred' => $starred], ['id' => $itemId]);
// See if we've been passed a return path to redirect to // See if we've been passed a return path to redirect to
$returnPath = $_REQUEST['return'] ?? ''; $return_path = $_REQUEST['return'] ?? '';
if (!empty($returnPath)) { if (!empty($return_path)) {
$rand = '_=' . time() . (strpos($returnPath, '?') ? '&' : '?') . 'rand'; $rand = '_=' . time();
DI::baseUrl()->redirect($returnPath . $rand); if (strpos($return_path, '?')) {
$rand = "&$rand";
} else {
$rand = "?$rand";
}
DI::baseUrl()->redirect($return_path . $rand);
} }
// the json doesn't really matter, it will either be 0 or 1 $return = [
echo json_encode((int)$starred); 'status' => 'ok',
exit(); 'item_id' => $itemId,
'verb' => 'star',
'state' => (int)$starred,
];
System::jsonExit($return);
} }
} }

View file

@ -294,6 +294,7 @@ return [
'/{id:\d+}/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]], '/{id:\d+}/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]],
'/{id:\d+}/ignore' => [Module\Item\Ignore::class, [ R::POST]], '/{id:\d+}/ignore' => [Module\Item\Ignore::class, [ R::POST]],
'/{id:\d+}/pin' => [Module\Item\Pin::class, [ R::POST]], '/{id:\d+}/pin' => [Module\Item\Pin::class, [ R::POST]],
'/{id:\d+}/star' => [Module\Item\Star::class, [ R::POST]],
], ],
'/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]], '/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]],
@ -412,7 +413,6 @@ return [
'/rsd.xml' => [Module\ReallySimpleDiscovery::class, [R::GET]], '/rsd.xml' => [Module\ReallySimpleDiscovery::class, [R::GET]],
'/smilies[/json]' => [Module\Smilies::class, [R::GET]], '/smilies[/json]' => [Module\Smilies::class, [R::GET]],
'/statistics.json' => [Module\Statistics::class, [R::GET]], '/statistics.json' => [Module\Statistics::class, [R::GET]],
'/starred/{item:\d+}' => [Module\Starred::class, [R::GET]],
'/toggle_mobile' => [Module\ToggleMobile::class, [R::GET]], '/toggle_mobile' => [Module\ToggleMobile::class, [R::GET]],
'/tos' => [Module\Tos::class, [R::GET]], '/tos' => [Module\Tos::class, [R::GET]],

View file

@ -682,21 +682,26 @@ function dosubthread(ident) {
liking = 1; liking = 1;
} }
function dostar(ident) { function doStar(ident) {
ident = ident.toString(); ident = ident.toString();
$('#like-rotator-' + ident).show(); $('#like-rotator-' + ident).show();
$.get('starred/' + ident, function(data) { $.post('item/' + ident + '/star')
if (data.match(/1/)) { .then(function(data) {
$('#starred-' + ident).addClass('starred'); if (data.state === 1) {
$('#starred-' + ident).removeClass('unstarred'); $('#starred-' + ident)
.addClass('starred')
.removeClass('unstarred');
$('#star-' + ident).addClass('hidden'); $('#star-' + ident).addClass('hidden');
$('#unstar-' + ident).removeClass('hidden'); $('#unstar-' + ident).removeClass('hidden');
} else { } else {
$('#starred-' + ident).addClass('unstarred'); $('#starred-' + ident)
$('#starred-' + ident).removeClass('starred'); .addClass('unstarred')
.removeClass('starred');
$('#star-' + ident).removeClass('hidden'); $('#star-' + ident).removeClass('hidden');
$('#unstar-' + ident).addClass('hidden'); $('#unstar-' + ident).addClass('hidden');
} }
})
.always(function () {
$('#like-rotator-' + ident).hide(); $('#like-rotator-' + ident).hide();
}); });
} }

View file

@ -105,7 +105,7 @@
<a href="#" id="pinned-{{$item.id}}" onclick="doPin({{$item.id}}); return false;" class="pin-item icon {{$item.ispinned}}" title="{{$item.pin.toggle}}"></a> <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}}
{{if $item.star}} {{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> <a href="#" id="starred-{{$item.id}}" onclick="doStar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>
{{/if}} {{/if}}
{{if $item.tagger}} {{if $item.tagger}}
<a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="tag-item icon tagged" title="{{$item.tagger.add}}"></a> <a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="tag-item icon tagged" title="{{$item.tagger.add}}"></a>

View file

@ -206,8 +206,8 @@
{{if $item.star}} {{if $item.star}}
<li role="menuitem"> <li role="menuitem">
<a id="star-{{$item.id}}" href="javascript: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}}</a> <a id="star-{{$item.id}}" href="javascript: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}}</a>
<a id="unstar-{{$item.id}}" href="javascript:dostar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i>&nbsp;{{$item.star.undo}}</a> <a id="unstar-{{$item.id}}" href="javascript:doStar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i>&nbsp;{{$item.star.undo}}</a>
</li> </li>
{{/if}} {{/if}}

View file

@ -358,8 +358,8 @@ as the value of $top_child_total (this is done at the end of this file)
{{if $item.star}} {{if $item.star}}
<li role="menuitem"> <li role="menuitem">
<a id="star-{{$item.id}}" href="javascript: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}}</a> <a id="star-{{$item.id}}" href="javascript: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}}</a>
<a id="unstar-{{$item.id}}" href="javascript:dostar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i>&nbsp;{{$item.star.undo}}</a> <a id="unstar-{{$item.id}}" href="javascript:doStar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i>&nbsp;{{$item.star.undo}}</a>
</li> </li>
{{/if}} {{/if}}
@ -523,8 +523,8 @@ as the value of $top_child_total (this is done at the end of this file)
{{if $item.star}} {{if $item.star}}
<li role="menuitem"> <li role="menuitem">
<a id="star-{{$item.id}}" href="javascript: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}}</a> <a id="star-{{$item.id}}" href="javascript: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}}</a>
<a id="unstar-{{$item.id}}" href="javascript:dostar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i>&nbsp;{{$item.star.undo}}</a> <a id="unstar-{{$item.id}}" href="javascript:doStar({{$item.id}});" class="btn-link {{$item.star.classundo}}" title="{{$item.star.undo}}"><i class="fa fa-star" aria-hidden="true"></i>&nbsp;{{$item.star.undo}}</a>
</li> </li>
{{/if}} {{/if}}

View file

@ -33,8 +33,8 @@
<div class="wall-item-actions-social"> <div class="wall-item-actions-social">
{{if $star}} {{if $star}}
<a href="#" id="star-{{$id}}" onclick="dostar({{$id}}); return false;" class="{{$star.classdo}}" title="{{$star.do}}">{{$star.do}}</a> <a href="#" id="star-{{$id}}" onclick="doStar({{$id}}); return false;" class="{{$star.classdo}}" title="{{$star.do}}">{{$star.do}}</a>
<a href="#" id="unstar-{{$id}}" onclick="dostar({{$id}}); return false;" class="{{$star.classundo}}" title="{{$star.undo}}">{{$star.undo}}</a> <a href="#" id="unstar-{{$id}}" onclick="doStar({{$id}}); return false;" class="{{$star.classundo}}" title="{{$star.undo}}">{{$star.undo}}</a>
<a href="#" id="tagger-{{$id}}" onclick="itemTag({{$id}}); return false;" class="{{$star.classtagger}}" title="{{$star.tagger}}">{{$star.tagger}}</a> <a href="#" id="tagger-{{$id}}" onclick="itemTag({{$id}}); return false;" class="{{$star.classtagger}}" title="{{$star.tagger}}">{{$star.tagger}}</a>
{{/if}} {{/if}}

View file

@ -52,8 +52,8 @@
<div class="wall-item-actions-social"> <div class="wall-item-actions-social">
{{if $item.star}} {{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="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> <a href="#" id="unstar-{{$item.id}}" onclick="doStar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}">{{$item.star.undo}}</a>
<a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="{{$item.star.classtagger}}" title="{{$item.star.tagger}}">{{$item.star.tagger}}</a> <a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="{{$item.star.classtagger}}" title="{{$item.star.tagger}}">{{$item.star.tagger}}</a>
{{/if}} {{/if}}

View file

@ -102,8 +102,8 @@
<a href="#" id="unpin-{{$item.id}}" onclick="doPin({{$item.id}}); return false;" class="{{$item.pin.classundo}}" title="{{$item.pin.undo}}">{{$item.pin.undo}}</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}}
{{if $item.star}} {{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="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> <a href="#" id="unstar-{{$item.id}}" onclick="doStar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}">{{$item.star.undo}}</a>
{{/if}} {{/if}}
{{if $item.ignore}} {{if $item.ignore}}
<a href="#" id="ignore-{{$item.id}}" onclick="doIgnoreThread({{$item.id}}); return false;" class="{{$item.ignore.classdo}}" title="{{$item.ignore.do}}">{{$item.ignore.do}}</a> <a href="#" id="ignore-{{$item.id}}" onclick="doIgnoreThread({{$item.id}}); return false;" class="{{$item.ignore.classdo}}" title="{{$item.ignore.do}}">{{$item.ignore.do}}</a>

View file

@ -117,7 +117,7 @@
<a href="#" id="pinned-{{$item.id}}" onclick="doPin({{$item.id}}); return false;" class="pin-item icon {{$item.ispinned}}" title="{{$item.pin.toggle}}"></a> <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}}
{{if $item.star}} {{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> <a href="#" id="starred-{{$item.id}}" onclick="doStar({{$item.id}}); return false;" class="star-item icon {{$item.isstarred}}" title="{{$item.star.toggle}}"></a>
{{/if}} {{/if}}
{{if $item.tagger}} {{if $item.tagger}}
<a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="tag-item icon tagged" title="{{$item.tagger.add}}"></a> <a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="tag-item icon tagged" title="{{$item.tagger.add}}"></a>

View file

@ -40,8 +40,8 @@
<div class="wall-item-actions-social"> <div class="wall-item-actions-social">
{{if $star}} {{if $star}}
<a href="#" id="star-{{$id}}" onclick="dostar({{$id}}); return false;" class="{{$star.classdo}}" title="{{$star.do}}">{{$star.do}}</a> <a href="#" id="star-{{$id}}" onclick="doStar({{$id}}); return false;" class="{{$star.classdo}}" title="{{$star.do}}">{{$star.do}}</a>
<a href="#" id="unstar-{{$id}}" onclick="dostar({{$id}}); return false;" class="{{$star.classundo}}" title="{{$star.undo}}">{{$star.undo}}</a> <a href="#" id="unstar-{{$id}}" onclick="doStar({{$id}}); return false;" class="{{$star.classundo}}" title="{{$star.undo}}">{{$star.undo}}</a>
<a href="#" id="tagger-{{$id}}" onclick="itemTag({{$id}}); return false;" class="{{$star.classtagger}}" title="{{$star.tagger}}">{{$star.tagger}}</a> <a href="#" id="tagger-{{$id}}" onclick="itemTag({{$id}}); return false;" class="{{$star.classtagger}}" title="{{$star.tagger}}">{{$star.tagger}}</a>
{{/if}} {{/if}}

View file

@ -57,8 +57,8 @@
<div class="wall-item-actions-social"> <div class="wall-item-actions-social">
{{if $item.star}} {{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="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> <a href="#" id="unstar-{{$item.id}}" onclick="doStar({{$item.id}}); return false;" class="{{$item.star.classundo}}" title="{{$item.star.undo}}">{{$item.star.undo}}</a>
<a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="{{$item.star.classtagger}}" title="{{$item.star.tagger}}">{{$item.star.tagger}}</a> <a href="#" id="tagger-{{$item.id}}" onclick="itemTag({{$item.id}}); return false;" class="{{$item.star.classtagger}}" title="{{$item.star.tagger}}">{{$item.star.tagger}}</a>
{{/if}} {{/if}}

View file

@ -140,8 +140,8 @@
<a role="button" id="unpin-{{$item.id}}" onclick="doPin({{$item.id}}); return false;" class="{{$item.pin.classundo}}" title="{{$item.pin.undo}}"><i class="icon-remove-circle icon-large"><span class="sr-only">{{$item.pin.undo}}</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-remove-circle icon-large"><span class="sr-only">{{$item.pin.undo}}</span></i></a>
{{/if}} {{/if}}
{{if $item.star}} {{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="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> <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>
{{/if}} {{/if}}
{{if $item.ignore}} {{if $item.ignore}}
<a role="button" id="ignore-{{$item.id}}" onclick="doIgnoreThread({{$item.id}}); return false;" class="{{$item.ignore.classdo}}" title="{{$item.ignore.do}}"><i class="icon-bell-slash icon-large"><span class="sr-only">{{$item.ignore.do}}</span></i></a> <a role="button" id="ignore-{{$item.id}}" onclick="doIgnoreThread({{$item.id}}); return false;" class="{{$item.ignore.classdo}}" title="{{$item.ignore.do}}"><i class="icon-bell-slash icon-large"><span class="sr-only">{{$item.ignore.do}}</span></i></a>