Merge pull request #9887 from MrPetovan/task/9872-normalize-frontend-api-responses

Replace references of mod/subthread with item/{id}/follow
This commit is contained in:
Michael Vogel 2021-02-01 20:30:31 +01:00 committed by GitHub
commit 04caf17772
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 102 additions and 75 deletions

View file

@ -551,10 +551,6 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep-
Hook::callAll('about_hook', $o);
### mod/subthread.php
Hook::callAll('post_local_end', $arr);
### mod/profiles.php
Hook::callAll('profile_post', $_POST);

View file

@ -259,10 +259,6 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap
Hook::callAll('about_hook', $o);
### mod/subthread.php
Hook::callAll('post_local_end', $arr);
### mod/profiles.php
Hook::callAll('profile_post', $_POST);

View file

@ -894,7 +894,7 @@ function item_photo_menu($item) {
$ignore_link = '';
if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self']) {
$sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
$sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;';
}
$author = ['uid' => 0, 'id' => $item['author-id'],

View file

@ -1,43 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2020, Friendica
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use Friendica\App;
use Friendica\Network\HTTPException;
use Friendica\Core\Logger;
use Friendica\Core\Session;
use Friendica\Model\Item;
use Friendica\Util\Strings;
function subthread_content(App $a)
{
if (!Session::isAuthenticated()) {
throw new HTTPException\ForbiddenException();
}
$item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
if (!Item::performActivity($item_id, 'follow', local_user())) {
Logger::info('Following item failed', ['item' => $item_id]);
throw new HTTPException\BadRequestException();
}
Logger::info('Followed item', ['item' => $item_id]);
return;
}

View file

@ -0,0 +1,77 @@
<?php
/**
* @copyright Copyright (C) 2020, Friendica
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Module\Item;
use Friendica\BaseModule;
use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
/**
* Module for following threads
*/
class Follow extends BaseModule
{
public static function rawContent(array $parameters = [])
{
$l10n = DI::l10n();
if (!Session::isAuthenticated()) {
throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
}
if (empty($parameters['id'])) {
throw new HTTPException\BadRequestException();
}
$itemId = intval($parameters['id']);
if (!Item::performActivity($itemId, 'follow', local_user())) {
throw new HTTPException\BadRequestException($l10n->t('Unable to follow this item.'));
}
// See if we've been passed a return path to redirect to
$return_path = $_REQUEST['return'] ?? '';
if (!empty($return_path)) {
$rand = '_=' . time();
if (strpos($return_path, '?')) {
$rand = "&$rand";
} else {
$rand = "?$rand";
}
DI::baseUrl()->redirect($return_path . $rand);
}
$return = [
'status' => 'ok',
'item_id' => $itemId,
'verb' => 'follow',
'state' => 1
];
System::jsonExit($return);
}
}

View file

@ -290,11 +290,12 @@ return [
'/testrewrite' => [Module\Install::class, [R::GET]],
],
'/item' => [
'/{id:\d+}/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]],
'/{id:\d+}/ignore' => [Module\Item\Ignore::class, [ R::POST]],
'/{id:\d+}/pin' => [Module\Item\Pin::class, [ R::POST]],
'/{id:\d+}/star' => [Module\Item\Star::class, [ R::POST]],
'/item/{id:\d+}' => [
'/activity/{verb}' => [Module\Item\Activity::class, [ R::POST]],
'/follow' => [Module\Item\Follow::class, [ R::POST]],
'/ignore' => [Module\Item\Ignore::class, [ R::POST]],
'/pin' => [Module\Item\Pin::class, [ R::POST]],
'/star' => [Module\Item\Star::class, [ R::POST]],
],
'/localtime' => [Module\Debug\Localtime::class, [R::GET, R::POST]],

View file

@ -675,10 +675,10 @@ function doActivityItem(ident, verb, un) {
update_item = ident.toString();
}
function dosubthread(ident) {
function doFollowThread(ident) {
unpause();
$('#like-rotator-' + ident.toString()).show();
$.get('subthread/' + ident.toString(), NavUpdate);
$.post('item/' + ident.toString() + '/follow', NavUpdate);
liking = 1;
}

View file

@ -174,7 +174,7 @@
{{* Put additional actions in a dropdown menu *}}
{{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.subthread || $item.ignore || $item.drop.dropping}}
{{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping}}
<span role="presentation" class="separator"></span>
<span class="more-links btn-group{{if $item.thread_level > 1}} dropup{{/if}}">
<button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" id="dropdownMenuOptions-{{$item.id}}" aria-haspopup="true" aria-expanded="false" title="{{$item.menu}}"><i class="fa fa-ellipsis-h" aria-hidden="true"></i>&nbsp;{{$item.menu}}</button>
@ -211,9 +211,9 @@
</li>
{{/if}}
{{if $item.subthread}}
{{if $item.follow_thread}}
<li role="menuitem">
<a id="subthread-{{$item.id}}" href="javascript:{{$item.subthread.action}}" class="btn-link" title="{{$item.subthread.title}}"><i class="fa fa-plus" aria-hidden="true"></i>&nbsp;{{$item.subthread.title}}</a>
<a id="follow_thread-{{$item.id}}" href="javascript:{{$item.follow_thread.action}}" class="btn-link" title="{{$item.follow_thread.title}}"><i class="fa fa-plus" aria-hidden="true"></i>&nbsp;{{$item.follow_thread.title}}</a>
</li>
{{/if}}
@ -223,7 +223,7 @@
</li>
{{/if}}
{{if ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.subthread) && ($item.ignore || $item.drop.dropping)}}
{{if ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread) && ($item.ignore || $item.drop.dropping)}}
<li role="separator" class="divider"></li>
{{/if}}

View file

@ -326,7 +326,7 @@ as the value of $top_child_total (this is done at the end of this file)
{{/if}}
{{* Put additional actions in a dropdown menu *}}
{{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.subthread || $item.ignore || $item.drop.dropping}}
{{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping}}
<span role="presentation" class="separator"></span>
<span class="more-links btn-group{{if $item.thread_level > 1}} dropup{{/if}}">
<button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" id="dropdownMenuOptions-{{$item.id}}" aria-haspopup="true" aria-expanded="false" title="{{$item.menu}}"><i class="fa fa-ellipsis-h" aria-hidden="true"></i>&nbsp;{{$item.menu}}</button>
@ -363,9 +363,9 @@ as the value of $top_child_total (this is done at the end of this file)
</li>
{{/if}}
{{if $item.subthread}}
{{if $item.follow_thread}}
<li role="menuitem">
<a id="subthread-{{$item.id}}" href="javascript:{{$item.subthread.action}}" class="btn-link" title="{{$item.subthread.title}}"><i class="fa fa-plus" aria-hidden="true"></i>&nbsp;{{$item.subthread.title}}</a>
<a id="follow_thread-{{$item.id}}" href="javascript:{{$item.follow_thread.action}}" class="btn-link" title="{{$item.follow_thread.title}}"><i class="fa fa-plus" aria-hidden="true"></i>&nbsp;{{$item.follow_thread.title}}</a>
</li>
{{/if}}
@ -375,7 +375,7 @@ as the value of $top_child_total (this is done at the end of this file)
</li>
{{/if}}
{{if ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.subthread) && ($item.ignore || $item.drop.dropping)}}
{{if ($item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread) && ($item.ignore || $item.drop.dropping)}}
<li role="separator" class="divider"></li>
{{/if}}
@ -492,7 +492,7 @@ as the value of $top_child_total (this is done at the end of this file)
</div>
{{/if}}
{{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.subthread || $item.ignore || $item.drop.dropping}}
{{if $item.edpost || $item.tagger || $item.filer || $item.pin || $item.star || $item.follow_thread || $item.ignore || $item.drop.dropping}}
<div class="more-links btn-group{{if $item.thread_level > 1}} dropup{{/if}}">
<button type="button" class="btn btn-sm dropdown-toggle" data-toggle="dropdown" id="dropdownMenuOptions-{{$item.id}}" aria-haspopup="true" aria-expanded="false" title="{{$item.menu}}"><i class="fa fa-ellipsis-h" aria-hidden="true"></i></button>
<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="dropdownMenuOptions-{{$item.id}}">
@ -528,9 +528,9 @@ as the value of $top_child_total (this is done at the end of this file)
</li>
{{/if}}
{{if $item.subthread}}
{{if $item.follow_thread}}
<li role="menuitem">
<a id="subthread-{{$item.id}}" href="javascript:{{$item.subthread.action}}" class="btn-link" title="{{$item.subthread.title}}"><i class="fa fa-plus" aria-hidden="true"></i>&nbsp;{{$item.subthread.title}}</a>
<a id="follow_thread-{{$item.id}}" href="javascript:{{$item.follow_thread.action}}" class="btn-link" title="{{$item.follow_thread.title}}"><i class="fa fa-plus" aria-hidden="true"></i>&nbsp;{{$item.follow_thread.title}}</a>
</li>
{{/if}}

View file

@ -308,20 +308,20 @@ function frio_acl_lookup(App $a, &$results)
*/
function frio_display_item(App $a, &$arr)
{
// Add subthread to the item menu
$subthread = [];
// Add follow to the item menu
$followThread = [];
if (
local_user()
&& local_user() == $arr['item']['uid']
&& $arr['item']['gravity'] == GRAVITY_PARENT
&& !$arr['item']['self'])
{
$subthread = [
$followThread = [
'menu' => 'follow_thread',
'title' => DI::l10n()->t('Follow Thread'),
'action' => 'dosubthread(' . $arr['item']['id'] . ');',
'action' => 'doFollowThread(' . $arr['item']['id'] . ');',
'href' => '#'
];
}
$arr['output']['subthread'] = $subthread;
$arr['output']['follow_thread'] = $followThread;
}