Use dynamic functions
This commit is contained in:
parent
465ee3718d
commit
2ee5745d3c
|
@ -21,9 +21,15 @@
|
||||||
|
|
||||||
namespace Friendica\Module\Api\Twitter\DirectMessages;
|
namespace Friendica\Module\Api\Twitter\DirectMessages;
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
|
use Friendica\Core\L10n;
|
||||||
|
use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\Module\Api\ApiResponse;
|
||||||
use Friendica\Module\BaseApi;
|
use Friendica\Module\BaseApi;
|
||||||
use Friendica\Network\HTTPException\BadRequestException;
|
use Friendica\Network\HTTPException\BadRequestException;
|
||||||
|
use Friendica\Util\Profiler;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete a direct_message from mail table through api
|
* delete a direct_message from mail table through api
|
||||||
|
@ -32,6 +38,15 @@ use Friendica\Network\HTTPException\BadRequestException;
|
||||||
*/
|
*/
|
||||||
class Destroy extends BaseApi
|
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 = [])
|
protected function rawContent(array $request = [])
|
||||||
{
|
{
|
||||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||||
|
@ -58,7 +73,7 @@ class Destroy extends BaseApi
|
||||||
$sql_extra = ($parenturi != "" ? " AND `parent-uri` = '" . DBA::escape($parenturi) . "'" : "");
|
$sql_extra = ($parenturi != "" ? " AND `parent-uri` = '" . DBA::escape($parenturi) . "'" : "");
|
||||||
|
|
||||||
// error message if specified id is not in database
|
// 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) {
|
if ($verbose) {
|
||||||
$answer = ['result' => 'error', 'message' => 'message id not in database'];
|
$answer = ['result' => 'error', 'message' => 'message id not in database'];
|
||||||
$this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null);
|
$this->response->exit('direct_messages_delete', ['direct_messages_delete' => $answer], $this->parameters['extension'] ?? null);
|
||||||
|
@ -68,7 +83,7 @@ class Destroy extends BaseApi
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete message
|
// 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 ($verbose) {
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
|
|
@ -21,12 +21,17 @@
|
||||||
|
|
||||||
namespace Friendica\Module\Api\Twitter\DirectMessages;
|
namespace Friendica\Module\Api\Twitter\DirectMessages;
|
||||||
|
|
||||||
use Friendica\Database\DBA;
|
use Friendica\App;
|
||||||
use Friendica\DI;
|
use Friendica\Core\L10n;
|
||||||
|
use Friendica\Database\Database;
|
||||||
|
use Friendica\Factory\Api\Twitter\DirectMessage;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Mail;
|
use Friendica\Model\Mail;
|
||||||
|
use Friendica\Module\Api\ApiResponse;
|
||||||
use Friendica\Module\BaseApi;
|
use Friendica\Module\BaseApi;
|
||||||
use Friendica\Network\HTTPException\NotFoundException;
|
use Friendica\Network\HTTPException\NotFoundException;
|
||||||
|
use Friendica\Util\Profiler;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a new direct message.
|
* Sends a new direct message.
|
||||||
|
@ -35,6 +40,20 @@ use Friendica\Network\HTTPException\NotFoundException;
|
||||||
*/
|
*/
|
||||||
class NewDM extends BaseApi
|
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 = [])
|
protected function rawContent(array $request = [])
|
||||||
{
|
{
|
||||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
||||||
|
@ -51,7 +70,7 @@ class NewDM extends BaseApi
|
||||||
|
|
||||||
$replyto = '';
|
$replyto = '';
|
||||||
if (!empty($request['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'];
|
$replyto = $mail['parent-uri'];
|
||||||
$sub = $mail['title'];
|
$sub = $mail['title'];
|
||||||
} else {
|
} else {
|
||||||
|
@ -67,7 +86,7 @@ class NewDM extends BaseApi
|
||||||
$id = Mail::send($cdata['user'], $request['text'], $sub, $replyto);
|
$id = Mail::send($cdata['user'], $request['text'], $sub, $replyto);
|
||||||
|
|
||||||
if ($id > -1) {
|
if ($id > -1) {
|
||||||
$ret = DI::twitterDirectMessage()->createFromMailId($id, $uid, $request['getText'] ?? '');
|
$ret = $this->directMessage->createFromMailId($id, $uid, $request['getText'] ?? '');
|
||||||
} else {
|
} else {
|
||||||
$ret = ['error' => $id];
|
$ret = ['error' => $id];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue