Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,42 @@
],
],

/**
* Block
*/
[
'name' => 'Block#block',
'url' => '/api/{apiVersion}/block',
'verb' => 'POST',
'requirements' => [
'apiVersion' => 'v1'
]
],
[
'name' => 'Block#unblock',
'url' => '/api/{apiVersion}/block',
'verb' => 'DELETE',
'requirements' => [
'apiVersion' => 'v1'
]
],
[
'name' => 'Block#listBlocked',
'url' => '/api/{apiVersion}/block',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v1'
]
],
[
'name' => 'Block#listBlockedByType',
'url' => '/api/{apiVersion}/block/type/{type}',
'verb' => 'GET',
'requirements' => [
'apiVersion' => 'v1'
]
],

/**
* HostedSignalingServer
*/
Expand Down
9 changes: 9 additions & 0 deletions lib/Chat/AutoComplete/SearchPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCA\Talk\GuestManager;
use OCA\Talk\Model\Attendee;
use OCA\Talk\Room;
use OCA\Talk\Service\BlockActorService;
use OCA\Talk\Service\ParticipantService;
use OCA\Talk\TalkSession;
use OCP\Collaboration\Collaborators\ISearchPlugin;
Expand All @@ -46,6 +47,8 @@ class SearchPlugin implements ISearchPlugin {
protected $talkSession;
/** @var ParticipantService */
protected $participantService;
/** @var BlockActorService */
protected $blockActorService;
/** @var Util */
protected $util;
/** @var string|null */
Expand All @@ -60,13 +63,15 @@ public function __construct(IUserManager $userManager,
GuestManager $guestManager,
TalkSession $talkSession,
ParticipantService $participantService,
BlockActorService $blockActorService,
Util $util,
?string $userId,
IL10N $l) {
$this->userManager = $userManager;
$this->guestManager = $guestManager;
$this->talkSession = $talkSession;
$this->participantService = $participantService;
$this->blockActorService = $blockActorService;
$this->util = $util;
$this->userId = $userId;
$this->l = $l;
Expand Down Expand Up @@ -133,6 +138,10 @@ protected function searchUsers(string $search, array $userIds, ISearchResult $se
continue;
}

if ($this->userId !== '' && $this->blockActorService->user1BlockedUser2($this->userId, $userId)) {
continue;
}

if ($search === '') {
$matches[] = $this->createResult('user', $userId, '');
continue;
Expand Down
90 changes: 90 additions & 0 deletions lib/Controller/BlockController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2021, Vitor Mattos <[email protected]>
*
* @author Vitor Mattos <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Talk\Controller;

use OCA\Talk\Model\Attendee;
use OCA\Talk\Service\BlockActorService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
use OCP\IUserSession;

class BlockController extends AEnvironmentAwareController {
/** @var BlockActorService */
protected $blockActorService;
/** @var IUserSession */
protected $userSession;

public function __construct(string $appName,
IRequest $request,
BlockActorService $blockActorService,
IUserSession $userSession
) {
parent::__construct($appName, $request);
$this->blockActorService = $blockActorService;
$this->userSession = $userSession;
}

/**
* @NoAdminRequired
*/
public function block(string $blockedId, string $type = Attendee::ACTOR_USERS): DataResponse {
$this->blockActorService->block(Attendee::ACTOR_USERS, $this->userSession->getUser()->getUID(), $type, $blockedId);
return new DataResponse([], Http::STATUS_OK);
}

/**
* @NoAdminRequired
*/
public function unblock(string $blockedId, string $type = Attendee::ACTOR_USERS): DataResponse {
$this->blockActorService->unblock(Attendee::ACTOR_USERS, $this->userSession->getUser()->getUID(), $type, $blockedId);
return new DataResponse([], Http::STATUS_OK);
}

/**
* @NoAdminRequired
*/
public function listBlocked(): DataResponse {
$typedList = $this->blockActorService->listBlocked($this->userSession->getUser()->getUID());
$return = [];
foreach ($typedList as $blockActor) {
$return[] = $blockActor->asArray();
}
return new DataResponse($return, Http::STATUS_OK);
}

/**
* @NoAdminRequired
*/
public function listBlockedByType(string $type): DataResponse {
$typedList = $this->blockActorService->listBlockedByType($this->userSession->getUser()->getUID(), $type);
$return = [];
foreach ($typedList as $blockActor) {
$return[] = $blockActor->asArray();
}
return new DataResponse($return, Http::STATUS_OK);
}
}
78 changes: 78 additions & 0 deletions lib/Migration/Version13000Date20211102171628.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2021, Vitor Mattos <[email protected]>
*
* @author Vitor Mattos <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Talk\Migration;

use Closure;
use Doctrine\DBAL\Types\Types;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Auto-generated migration step: Please modify to your needs!
*/
class Version13000Date20211102171628 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if (!$schema->hasTable('talk_block_actor')) {
$table = $schema->createTable('talk_block_actor');
$table->addColumn('id', Types::BIGINT, [
'autoincrement' => true,
'notnull' => true,
]);
$table->addColumn('actor_type', Types::STRING, [
'notnull' => true,
'length' => 32,
]);
$table->addColumn('actor_id', Types::STRING, [
'notnull' => true,
'length' => 255,
]);
$table->addColumn('blocked_type', Types::STRING, [
'notnull' => true,
'length' => 32,
]);
$table->addColumn('blocked_id', Types::STRING, [
'notnull' => true,
'length' => 255,
]);
$table->addColumn('datetime', Types::DATETIME_MUTABLE, [
'notnull' => false,
]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['actor_type', 'actor_id', 'blocked_type', 'blocked_id'], 'unq_block_actor');
}
return $schema;
}
}
81 changes: 81 additions & 0 deletions lib/Model/BlockActor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2021, Vitor Mattos <[email protected]>
*
* @author Vitor Mattos <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Talk\Model;

use OCP\AppFramework\Db\Entity;

/**
* @method void setActorType(string $actorType)
* @method string getActorType()
* @method void setActorId(string $actorId)
* @method string getActorId()
* @method void setBlockedType(string $blockedType)
* @method string getBlockedType()
* @method void setBlockedId(string $blockedId)
* @method string getBlockedId()
* @method void setDatetime(\DateTime $datetime)
* @method \DateTime getDatetime()
*/
class BlockActor extends Entity {
/** @var string */
protected $actorType;
/** @var string */
protected $actorId;
/** @var string */
protected $blockedType;
/** @var string */
protected $blockedId;
/** @var \DateTime */
protected $datetime;
public function __construct() {
$this->addType('actorType', 'string');
$this->addType('actorId', 'string');
$this->addType('blockedType', 'string');
$this->addType('blockedId', 'string');
$this->addType('datetime', 'datetime');
}

public function setDatetime($datetime): void {
if (!$datetime instanceof \DateTime) {
$datetime = new \DateTime($datetime);
}
$this->datetime = $datetime;
$this->markFieldUpdated('datetime');
}

/**
* @return array
*/
public function asArray(): array {
return [
'actorType' => $this->getActorType(),
'actorId' => $this->getActorId(),
'blockedType' => $this->getBlockedType(),
'blockedId' => $this->getBlockedId(),
'datetime' => $this->getDatetime()
];
}
}
Loading