From 2ee5745d3c6f27168bb42f62fd9614189dc1e356 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 19 Dec 2021 08:32:19 +0000 Subject: [PATCH] Use dynamic functions --- .../Api/Twitter/DirectMessages/Destroy.php | 19 +++++++++++-- .../Api/Twitter/DirectMessages/NewDM.php | 27 ++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/Module/Api/Twitter/DirectMessages/Destroy.php b/src/Module/Api/Twitter/DirectMessages/Destroy.php index c289864f2..0d697de44 100644 --- a/src/Module/Api/Twitter/DirectMessages/Destroy.php +++ b/src/Module/Api/Twitter/DirectMessages/Destroy.php @@ -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) { diff --git a/src/Module/Api/Twitter/DirectMessages/NewDM.php b/src/Module/Api/Twitter/DirectMessages/NewDM.php index 64582b6a7..8df6c5ec0 100644 --- a/src/Module/Api/Twitter/DirectMessages/NewDM.php +++ b/src/Module/Api/Twitter/DirectMessages/NewDM.php @@ -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]; }