Use dynamic functions

This commit is contained in:
Michael 2021-12-19 08:32:19 +00:00
parent 465ee3718d
commit 2ee5745d3c
2 changed files with 40 additions and 6 deletions

View file

@ -21,9 +21,15 @@
namespace Friendica\Module\Api\Twitter\DirectMessages;
use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\Module\Api\ApiResponse;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
/**
* delete a direct_message from mail table through api
@ -32,6 +38,15 @@ use Friendica\Network\HTTPException\BadRequestException;
*/
class Destroy extends BaseApi
{
/** @var Database */
private $dba;
public function __construct(Database $dba, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->dba = $dba;
}
protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
@ -58,7 +73,7 @@ class Destroy extends BaseApi
$sql_extra = ($parenturi != "" ? " AND `parent-uri` = '" . DBA::escape($parenturi) . "'" : "");
// error message if specified id is not in database
if (!DBA::exists('mail', ["`uid` = ? AND `id` = ? " . $sql_extra, $uid, $id])) {
if (!$this->dba->exists('mail', ["`uid` = ? AND `id` = ? " . $sql_extra, $uid, $id])) {
if ($verbose) {
$answer = ['result' => 'error', 'message' => 'message id not in database'];
$this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null);
@ -68,7 +83,7 @@ class Destroy extends BaseApi
}
// delete message
$result = DBA::delete('mail', ["`uid` = ? AND `id` = ? " . $sql_extra, $uid, $id]);
$result = $this->dba->delete('mail', ["`uid` = ? AND `id` = ? " . $sql_extra, $uid, $id]);
if ($verbose) {
if ($result) {

View file

@ -21,12 +21,17 @@
namespace Friendica\Module\Api\Twitter\DirectMessages;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Database\Database;
use Friendica\Factory\Api\Twitter\DirectMessage;
use Friendica\Model\Contact;
use Friendica\Model\Mail;
use Friendica\Module\Api\ApiResponse;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Util\Profiler;
use Psr\Log\LoggerInterface;
/**
* Sends a new direct message.
@ -35,6 +40,20 @@ use Friendica\Network\HTTPException\NotFoundException;
*/
class NewDM extends BaseApi
{
/** @var Database */
private $dba;
/** @var DirectMessage */
private $directMessage;
public function __construct(DirectMessage $directMessage, Database $dba, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, array $server, array $parameters = [])
{
parent::__construct($app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->dba = $dba;
$this->directMessage = $directMessage;
}
protected function rawContent(array $request = [])
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
@ -51,7 +70,7 @@ class NewDM extends BaseApi
$replyto = '';
if (!empty($request['replyto'])) {
$mail = DBA::selectFirst('mail', ['parent-uri', 'title'], ['uid' => $uid, 'id' => $request['replyto']]);
$mail = $this->dba->selectFirst('mail', ['parent-uri', 'title'], ['uid' => $uid, 'id' => $request['replyto']]);
$replyto = $mail['parent-uri'];
$sub = $mail['title'];
} else {
@ -67,7 +86,7 @@ class NewDM extends BaseApi
$id = Mail::send($cdata['user'], $request['text'], $sub, $replyto);
if ($id > -1) {
$ret = DI::twitterDirectMessage()->createFromMailId($id, $uid, $request['getText'] ?? '');
$ret = $this->directMessage->createFromMailId($id, $uid, $request['getText'] ?? '');
} else {
$ret = ['error' => $id];
}