Superflous spaces

This commit is contained in:
Michael 2022-01-16 07:14:09 +00:00
parent c55c42b303
commit 8ff2cc3976
8 changed files with 35 additions and 36 deletions

View file

@ -35,27 +35,27 @@ class Create extends BaseApi
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
// params
$name = $_REQUEST['name'] ?? '';
$json = json_decode($_POST['json'], true);
$users = $json['user'];
// error if no name specified
if ($name == '') {
throw new HTTPException\BadRequestException('group name not specified');
}
// error message if specified group name already exists
if (DBA::exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => false])) {
throw new HTTPException\BadRequestException('group name already exists');
}
// Check if the group needs to be reactivated
if (DBA::exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => true])) {
$reactivate_group = true;
}
// create group
$ret = Group::create($uid, $name);
if ($ret) {
@ -63,7 +63,7 @@ class Create extends BaseApi
} else {
throw new HTTPException\BadRequestException('other API error');
}
// add members
$erroraddinguser = false;
$errorusers = [];
@ -76,12 +76,12 @@ class Create extends BaseApi
$errorusers[] = $cid;
}
}
// return success message incl. missing users in array
$status = ($erroraddinguser ? 'missing user' : ((isset($reactivate_group) && $reactivate_group) ? 'reactivated' : 'ok'));
$result = ['success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers];
$this->response->exit('group_create', ['$result' => $result], $this->parameters['extension'] ?? null);
}
}

View file

@ -22,7 +22,6 @@
namespace Friendica\Module\Api\Friendica\Group;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Group;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException\BadRequestException;

View file

@ -37,14 +37,14 @@ class Show extends BaseApi
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID();
$type = $this->parameters['extension'] ?? '';
// params
$gid = $_REQUEST['gid'] ?? 0;
// get data of the specified group id or all groups if not specified
if ($gid != 0) {
$groups = DBA::selectToArray('group', [], ['deleted' => false, 'uid' => $uid, 'id' => $gid]);
// error message if specified gid is not in database
if (!DBA::isResult($groups)) {
throw new HTTPException\BadRequestException('gid not available');
@ -52,13 +52,13 @@ class Show extends BaseApi
} else {
$groups = DBA::selectToArray('group', [], ['deleted' => false, 'uid' => $uid]);
}
// loop through all groups and retrieve all members for adding data in the user array
$grps = [];
foreach ($groups as $rr) {
$members = Contact\Group::getById($rr['id']);
$users = [];
if ($type == 'xml') {
$user_element = 'users';
$k = 0;

View file

@ -53,33 +53,33 @@ class Create extends BaseApi
$this->dba = $dba;
$this->friendicaGroup = $friendicaGroup;
}
protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
// params
$name = $_REQUEST['name'] ?? '';
if ($name == '') {
throw new HTTPException\BadRequestException('group name not specified');
}
// error message if specified group name already exists
if ($this->dba->exists('group', ['uid' => $uid, 'name' => $name, 'deleted' => false])) {
throw new HTTPException\BadRequestException('group name already exists');
}
$ret = Group::create($uid, $name);
if ($ret) {
$gid = Group::getIdByName($uid, $name);
} else {
throw new HTTPException\BadRequestException('other API error');
}
$grp = $this->friendicaGroup->createFromId($gid);
$this->response->exit('statuses', ['lists' => ['lists' => $grp]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
}
}

View file

@ -53,29 +53,29 @@ class Destroy extends BaseApi
$this->dba = $dba;
$this->friendicaGroup = $friendicaGroup;
}
protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
// params
$gid = $_REQUEST['list_id'] ?? 0;
// error if no gid specified
if ($gid == 0) {
throw new HTTPException\BadRequestException('gid not specified');
}
// get data of the specified group id
$group = $this->dba->selectFirst('group', [], ['uid' => $uid, 'id' => $gid]);
// error message if specified gid is not in database
if (!$group) {
throw new HTTPException\BadRequestException('gid not available');
}
$list = $this->friendicaGroup->createFromId($gid);
if (Group::remove($gid)) {
$this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
}

View file

@ -55,9 +55,9 @@ class Ownership extends BaseApi
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
$uid = BaseApi::getCurrentUserID();
$groups = $this->dba->select('group', [], ['deleted' => false, 'uid' => $uid]);
// loop through all groups
$lists = [];
foreach ($groups as $group) {

View file

@ -54,7 +54,7 @@ class Statuses extends BaseApi
$this->dba = $dba;
$this->twitterStatus = $twitterStatus;
}
protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);

View file

@ -58,26 +58,26 @@ class Update extends BaseApi
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
// params
$gid = $_REQUEST['list_id'] ?? 0;
$name = $_REQUEST['name'] ?? '';
// error if no gid specified
if ($gid == 0) {
throw new HTTPException\BadRequestException('gid not specified');
}
// get data of the specified group id
$group = $this->dba->selectFirst('group', [], ['uid' => $uid, 'id' => $gid]);
// error message if specified gid is not in database
if (!$group) {
throw new HTTPException\BadRequestException('gid not available');
}
if (Group::update($gid, $name)) {
$list = $this->friendicaGroup->createFromId($gid);
$this->response->exit('statuses', ['lists' => ['lists' => $list]], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
}
}