Improved code style

This commit is contained in:
Michael 2025-01-06 22:15:41 +00:00
parent 8e76d13a96
commit e090fd4495
6 changed files with 29 additions and 30 deletions

View file

@ -237,7 +237,7 @@ abstract class BaseModule implements ICanHandleRequests
case Router::GET:
$this->get($request);
break;
}
}
$timestamp = microtime(true);
// "rawContent" is especially meant for technical endpoints.

View file

@ -7,7 +7,6 @@
namespace Friendica\Module\Api\Mastodon\Lists;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Circle;
@ -40,7 +39,7 @@ class Accounts extends BaseApi
$this->checkAllowedScope(self::SCOPE_WRITE);
$request = $this->getRequest([
'account_ids' => [], // Array of account IDs to add to the list
'account_ids' => [], // Array of account IDs to add to the list
], $request);
if (empty($request['account_ids']) || empty($this->parameters['id'])) {

View file

@ -36,7 +36,7 @@ class Markers extends BaseApi
}
$condition = ['application-id' => $application['id'], 'uid' => $uid, 'timeline' => $timeline];
$marker = DBA::selectFirst('application-marker', [], $condition);
$marker = DBA::selectFirst('application-marker', [], $condition);
if (!empty($marker['version'])) {
$version = $marker['version'] + 1;
} else {
@ -62,7 +62,7 @@ class Markers extends BaseApi
private function fetchTimelines(int $application_id, int $uid): \stdClass
{
$values = new \stdClass();
$values = new \stdClass();
$markers = DBA::select('application-marker', [], ['application-id' => $application_id, 'uid' => $uid]);
while ($marker = DBA::fetch($markers)) {
$values->{$marker['timeline']} = [

View file

@ -49,9 +49,9 @@ class PushSubscription extends BaseApi
$subscription = [
'application-id' => $application['id'],
'uid' => $uid,
'endpoint' => $request['subscription']['endpoint'] ?? '',
'endpoint' => $request['subscription']['endpoint'] ?? '',
'pubkey' => $request['subscription']['keys']['p256dh'] ?? '',
'secret' => $request['subscription']['keys']['auth'] ?? '',
'secret' => $request['subscription']['keys']['auth'] ?? '',
Notification::TYPE_FOLLOW => filter_var($request['data']['alerts'][Notification::TYPE_FOLLOW] ?? false, FILTER_VALIDATE_BOOLEAN),
Notification::TYPE_LIKE => filter_var($request['data']['alerts'][Notification::TYPE_LIKE] ?? false, FILTER_VALIDATE_BOOLEAN),
Notification::TYPE_RESHARE => filter_var($request['data']['alerts'][Notification::TYPE_RESHARE] ?? false, FILTER_VALIDATE_BOOLEAN),

View file

@ -8,7 +8,6 @@
namespace Friendica\Module\Api\Mastodon;
use Friendica\App\Router;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Post;
@ -58,10 +57,10 @@ class ScheduledStatuses extends BaseApi
}
$request = $this->getRequest([
'limit' => 20, // Max number of results to return. Defaults to 20.
'max_id' => 0, // Return results older than ID
'since_id' => 0, // Return results newer than ID
'min_id' => 0, // Return results immediately newer than ID
'limit' => 20, // Max number of results to return. Defaults to 20.
'max_id' => 0, // Return results older than ID
'since_id' => 0, // Return results newer than ID
'min_id' => 0, // Return results immediately newer than ID
], $request);
$params = ['order' => ['id' => true], 'limit' => $request['limit']];
@ -77,7 +76,7 @@ class ScheduledStatuses extends BaseApi
}
if (!empty($request['min_id'])) {
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]);
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]);
$params['order'] = ['uri-id'];
}

View file

@ -64,18 +64,18 @@ class Statuses extends BaseApi
throw new HTTPException\NotFoundException('Item with URI ID ' . $this->parameters['id'] . ' not found for user ' . $uid . '.');
}
$item['title'] = '';
$item['uid'] = $post['uid'];
$item['body'] = $this->formatStatus($request['status'], $uid);
$item['network'] = $post['network'];
$item['gravity'] = $post['gravity'];
$item['verb'] = $post['verb'];
$item['allow_cid'] = $post['allow_cid'];
$item['allow_gid'] = $post['allow_gid'];
$item['deny_cid'] = $post['deny_cid'];
$item['deny_gid'] = $post['deny_gid'];
$item['app'] = $this->getApp();
$item['sensitive'] = $request['sensitive'];
$item['title'] = '';
$item['uid'] = $post['uid'];
$item['body'] = $this->formatStatus($request['status'], $uid);
$item['network'] = $post['network'];
$item['gravity'] = $post['gravity'];
$item['verb'] = $post['verb'];
$item['allow_cid'] = $post['allow_cid'];
$item['allow_gid'] = $post['allow_gid'];
$item['deny_cid'] = $post['deny_cid'];
$item['deny_gid'] = $post['deny_gid'];
$item['app'] = $this->getApp();
$item['sensitive'] = $request['sensitive'];
if (!empty($request['language'])) {
$item['language'] = json_encode([$request['language'] => 1]);
@ -91,7 +91,7 @@ class Statuses extends BaseApi
if (!isset($request['friendica']['title']) && $post['gravity'] == Item::GRAVITY_PARENT && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) {
$item['title'] = $spoiler_text;
} else {
$item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $spoiler_text . "[/abstract]\n" . $item['body'];
$item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $spoiler_text . "[/abstract]\n" . $item['body'];
$item['content-warning'] = BBCode::toPlaintext($spoiler_text);
}
}
@ -307,7 +307,8 @@ class Statuses extends BaseApi
if (!empty($request['scheduled_at'])) {
$item['guid'] = Item::guid($item, true);
$item['uri'] = Item::newURI($item['guid']);
$item['uri'] = Item::newURI($item['guid']);
$id = Post\Delayed::add($item['uri'], $item, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED, DateTimeFormat::utc($request['scheduled_at']));
if (empty($id)) {
$this->logAndJsonError(500, $this->errorFactory->InternalError());
@ -385,7 +386,7 @@ class Statuses extends BaseApi
foreach ($media_ids as $id) {
if (DI::mstdnAttachment()->isAttach($id) && Attach::exists(['id' => substr($id, 7)])) {
$attach = Attach::selectFirst([], ['id' => substr($id, 7)]);
$attach = Attach::selectFirst([], ['id' => substr($id, 7)]);
$attachment = [
'type' => Post\Media::getType($attach['filetype']),
'mimetype' => $attach['filetype'],
@ -422,8 +423,8 @@ class Statuses extends BaseApi
];
if (count($media) > 1) {
$attachment['preview'] = DI::baseUrl() . '/photo/' . $media[1]['resource-id'] . '-' . $media[1]['scale'] . $ext;
$attachment['preview-width'] = $media[1]['width'];
$attachment['preview'] = DI::baseUrl() . '/photo/' . $media[1]['resource-id'] . '-' . $media[1]['scale'] . $ext;
$attachment['preview-width'] = $media[1]['width'];
$attachment['preview-height'] = $media[1]['height'];
}
$item['attachments'][] = $attachment;