<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Module\BaseApi;
-use Friendica\Model\Group;
+use Friendica\Model\Circle;
/**
* @see https://docs.joinmastodon.org/methods/timelines/lists/
*/
class Lists extends BaseApi
{
- protected function delete()
+ protected function delete(array $request = [])
{
- self::checkAllowedScope(self::SCOPE_WRITE);
+ $this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
- if (!Group::exists($this->parameters['id'], $uid)) {
- DI::mstdnError()->RecordNotFound();
+ if (!Circle::exists($this->parameters['id'], $uid)) {
+ $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
}
- if (!Group::remove($this->parameters['id'])) {
+ if (!Circle::remove($this->parameters['id'])) {
DI::mstdnError()->InternalError();
}
- System::jsonExit([]);
+ $this->jsonExit([]);
}
- protected function post(array $request = [], array $post = [])
+ protected function post(array $request = [])
{
- self::checkAllowedScope(self::SCOPE_WRITE);
+ $this->checkAllowedScope(self::SCOPE_WRITE);
$uid = self::getCurrentUserID();
- $request = self::getRequest([
+ $request = $this->getRequest([
'title' => '',
], $request);
if (empty($request['title'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
- Group::create($uid, $request['title']);
+ Circle::create($uid, $request['title']);
- $id = Group::getIdByName($uid, $request['title']);
+ $id = Circle::getIdByName($uid, $request['title']);
if (!$id) {
DI::mstdnError()->InternalError();
}
- System::jsonExit(DI::mstdnList()->createFromGroupId($id));
+ $this->jsonExit(DI::mstdnList()->createFromCircleId($id));
}
- public function put()
+ public function put(array $request = [])
{
- $request = self::getRequest([
+ $request = $this->getRequest([
'title' => '', // The title of the list to be updated.
'replies_policy' => '', // One of: "followed", "list", or "none".
- ]);
+ ], $request);
if (empty($request['title']) || empty($this->parameters['id'])) {
- DI::mstdnError()->UnprocessableEntity();
+ $this->logErrorAndJsonExit(422, $this->errorFactory->UnprocessableEntity());
}
- Group::update($this->parameters['id'], $request['title']);
+ Circle::update($this->parameters['id'], $request['title']);
}
/**
*/
protected function rawContent(array $request = [])
{
- self::checkAllowedScope(self::SCOPE_READ);
+ $this->checkAllowedScope(self::SCOPE_READ);
$uid = self::getCurrentUserID();
if (empty($this->parameters['id'])) {
$lists = [];
- $groups = Group::getByUserId($uid);
-
- foreach ($groups as $group) {
- $lists[] = DI::mstdnList()->createFromGroupId($group['id']);
+ foreach (Circle::getByUserId($uid) as $circle) {
+ $lists[] = DI::mstdnList()->createFromCircleId($circle['id']);
}
} else {
$id = $this->parameters['id'];
- if (!Group::exists($id, $uid)) {
- DI::mstdnError()->RecordNotFound();
+ if (!Circle::exists($id, $uid)) {
+ $this->logErrorAndJsonExit(404, $this->errorFactory->RecordNotFound());
}
- $lists = DI::mstdnList()->createFromGroupId($id);
+ $lists = DI::mstdnList()->createFromCircleId($id);
}
- System::jsonExit($lists);
+ $this->jsonExit($lists);
}
}