mirror of
https://github.com/friendica/friendica
synced 2025-04-26 21:50:11 +00:00
API: some more converted functions
This commit is contained in:
parent
fca9379348
commit
02210f285b
8 changed files with 402 additions and 313 deletions
64
src/Module/Api/Friendica/Activity.php
Normal file
64
src/Module/Api/Friendica/Activity.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @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\Api\Friendica;
|
||||
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* API endpoints:
|
||||
* - /api/friendica/activity/like
|
||||
* - /api/friendica/activity/dislike
|
||||
* - /api/friendica/activity/attendyes
|
||||
* - /api/friendica/activity/attendno
|
||||
* - /api/friendica/activity/attendmaybe
|
||||
* - /api/friendica/activity/unlike
|
||||
* - /api/friendica/activity/undislike
|
||||
* - /api/friendica/activity/unattendyes
|
||||
* - /api/friendica/activity/unattendno
|
||||
* - /api/friendica/activity/unattendmaybe
|
||||
*/
|
||||
class Activity extends BaseApi
|
||||
{
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = self::getRequest([
|
||||
'id' => 0, // Id of the post
|
||||
]);
|
||||
|
||||
$res = Item::performActivity($request['id'], $parameters['verb'], $uid);
|
||||
|
||||
if ($res) {
|
||||
if (!empty($parameters['extension']) && ($parameters['extension'] == 'xml')) {
|
||||
$ok = 'true';
|
||||
} else {
|
||||
$ok = 'ok';
|
||||
}
|
||||
self::exit('ok', ['ok' => $ok], $parameters['extension'] ?? null);
|
||||
} else {
|
||||
self::error(500, 'Error adding activity', '', $parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
||||
}
|
65
src/Module/Api/Friendica/DirectMessages/Setseen.php
Normal file
65
src/Module/Api/Friendica/DirectMessages/Setseen.php
Normal file
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @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\Api\Friendica\DirectMessages;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
* API endpoint: /api/friendica/direct_messages_setseen
|
||||
*/
|
||||
class Setseen extends BaseApi
|
||||
{
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = self::getRequest([
|
||||
'id' => 0, // Id of the direct message
|
||||
]);
|
||||
|
||||
// return error if id is zero
|
||||
if (empty($request['id'])) {
|
||||
$answer = ['result' => 'error', 'message' => 'message id not specified'];
|
||||
self::exit('direct_messages_setseen', ['$result' => $answer], $parameters['extension'] ?? null);
|
||||
}
|
||||
|
||||
// error message if specified id is not in database
|
||||
if (!DBA::exists('mail', ['id' => $request['id'], 'uid' => $uid])) {
|
||||
$answer = ['result' => 'error', 'message' => 'message id not in database'];
|
||||
self::exit('direct_messages_setseen', ['$result' => $answer], $parameters['extension'] ?? null);
|
||||
}
|
||||
|
||||
// update seen indicator
|
||||
$result = DBA::update('mail', ['seen' => true], ['id' => $request['id']]);
|
||||
|
||||
if ($result) {
|
||||
// return success
|
||||
$answer = ['result' => 'ok', 'message' => 'message set to seen'];
|
||||
self::exit('direct_messages_setseen', ['$result' => $answer], $parameters['extension'] ?? null);
|
||||
} else {
|
||||
$answer = ['result' => 'error', 'message' => 'unknown error'];
|
||||
self::exit('direct_messages_setseen', ['$result' => $answer], $parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
||||
}
|
61
src/Module/Api/Friendica/Notification.php
Normal file
61
src/Module/Api/Friendica/Notification.php
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @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\Api\Friendica;
|
||||
|
||||
use Friendica\Collection\Api\Notifications as ApiNotifications;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Object\Api\Friendica\Notification as ApiNotification;
|
||||
|
||||
/**
|
||||
* API endpoint: /api/friendica/notification
|
||||
*/
|
||||
class Notification extends BaseApi
|
||||
{
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_READ);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$Notifies = DI::notify()->selectAllForUser($uid, 50);
|
||||
|
||||
$notifications = new ApiNotifications();
|
||||
foreach ($Notifies as $Notify) {
|
||||
$notifications[] = new ApiNotification($Notify);
|
||||
}
|
||||
|
||||
if (!empty($parameters['extension']) && ($parameters['extension'] == 'xml')) {
|
||||
$xmlnotes = [];
|
||||
foreach ($notifications as $notification) {
|
||||
$xmlnotes[] = ['@attributes' => $notification->toArray()];
|
||||
}
|
||||
|
||||
$result = $xmlnotes;
|
||||
} elseif (count($notifications) > 0) {
|
||||
$result = $notifications->getArrayCopy();
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
self::exit('notes', ['note' => $result], $parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
74
src/Module/Api/Friendica/Photoalbum/Delete.php
Normal file
74
src/Module/Api/Friendica/Photoalbum/Delete.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @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\Api\Friendica\Photoalbum;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException\BadRequestException;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
|
||||
/**
|
||||
* API endpoint: /api/friendica/photoalbum/delete
|
||||
*/
|
||||
class Delete extends BaseApi
|
||||
{
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = self::getRequest([
|
||||
'album' => '', // Album name
|
||||
]);
|
||||
|
||||
// we do not allow calls without album string
|
||||
if (empty($request['album'])) {
|
||||
throw new BadRequestException("no albumname specified");
|
||||
}
|
||||
// check if album is existing
|
||||
|
||||
$photos = DBA::selectToArray('photo', ['resource-id'], ['uid' => $uid, 'album' => $request['album']], ['group_by' => ['resource-id']]);
|
||||
if (!DBA::isResult($photos)) {
|
||||
throw new BadRequestException("album not available");
|
||||
}
|
||||
|
||||
$resourceIds = array_column($photos, 'resource-id');
|
||||
|
||||
// function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
|
||||
// to the user and the contacts of the users (drop_items() performs the federation of the deletion to other networks
|
||||
$condition = ['uid' => $uid, 'resource-id' => $resourceIds, 'type' => 'photo'];
|
||||
Item::deleteForUser($condition, $uid);
|
||||
|
||||
// now let's delete all photos from the album
|
||||
$result = Photo::delete(['uid' => $uid, 'album' => $request['album']]);
|
||||
|
||||
// return success of deletion or error message
|
||||
if ($result) {
|
||||
$answer = ['result' => 'deleted', 'message' => 'album `' . $request['album'] . '` with all containing photos has been deleted.'];
|
||||
self::exit('photoalbum_delete', ['$result' => $answer], $parameters['extension'] ?? null);
|
||||
} else {
|
||||
throw new InternalServerErrorException("unknown error - deleting from database failed");
|
||||
}
|
||||
}
|
||||
}
|
66
src/Module/Api/Friendica/Photoalbum/Update.php
Normal file
66
src/Module/Api/Friendica/Photoalbum/Update.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2021, the Friendica project
|
||||
*
|
||||
* @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\Api\Friendica\Photoalbum;
|
||||
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException\BadRequestException;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
|
||||
/**
|
||||
* API endpoint: /api/friendica/photoalbum/update
|
||||
*/
|
||||
class Update extends BaseApi
|
||||
{
|
||||
public static function rawContent(array $parameters = [])
|
||||
{
|
||||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
$request = self::getRequest([
|
||||
'album' => '', // Current album name
|
||||
'album_new' => '', // New album name
|
||||
]);
|
||||
|
||||
// we do not allow calls without album string
|
||||
if ($request['album'] == "") {
|
||||
throw new BadRequestException("no albumname specified");
|
||||
}
|
||||
if ($request['album_new'] == "") {
|
||||
throw new BadRequestException("no new albumname specified");
|
||||
}
|
||||
// check if album is existing
|
||||
if (!Photo::exists(['uid' => $uid, 'album' => $request['album']])) {
|
||||
throw new BadRequestException("album not available");
|
||||
}
|
||||
// now let's update all photos to the albumname
|
||||
$result = Photo::update(['album' => $request['album_new']], ['uid' => $uid, 'album' => $request['album']]);
|
||||
|
||||
// return success of updating or error message
|
||||
if ($result) {
|
||||
$answer = ['result' => 'updated', 'message' => 'album `' . $request['album'] . '` with all containing photos has been renamed to `' . $request['album_new'] . '`.'];
|
||||
self::exit('photoalbum_update', ['$result' => $answer], $parameters['extension'] ?? null);
|
||||
} else {
|
||||
throw new InternalServerErrorException("unknown error - updating in database failed");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue