mirror of
https://github.com/friendica/friendica
synced 2025-04-29 19:44:22 +02:00
Cleanup Mastodon Factories
This commit is contained in:
parent
88b50313c8
commit
322f0b3ecf
16 changed files with 223 additions and 138 deletions
|
@ -22,12 +22,27 @@
|
|||
namespace Friendica\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Contact;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Conversation extends BaseFactory
|
||||
{
|
||||
/** @var Database */
|
||||
private $dba;
|
||||
/** @var Status */
|
||||
private $mstdnStatusFactory;
|
||||
/** @var Account */
|
||||
private $mstdnAccountFactory;
|
||||
|
||||
public function __construct(LoggerInterface $logger, Database $dba, Status $mstdnStatusFactory, Account $mstdnAccountFactoryFactory)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
$this->dba = $dba;
|
||||
$this->mstdnStatusFactory = $mstdnStatusFactory;
|
||||
$this->mstdnAccountFactory = $mstdnAccountFactoryFactory;
|
||||
}
|
||||
|
||||
public function CreateFromConvId(int $id)
|
||||
{
|
||||
$accounts = [];
|
||||
|
@ -36,8 +51,8 @@ class Conversation extends BaseFactory
|
|||
|
||||
$ids = [];
|
||||
|
||||
$mails = DBA::select('mail', ['id', 'from-url', 'uid', 'seen'], ['convid' => $id], ['order' => ['id' => true]]);
|
||||
while ($mail = DBA::fetch($mails)) {
|
||||
$mails = $this->dba->select('mail', ['id', 'from-url', 'uid', 'seen'], ['convid' => $id], ['order' => ['id' => true]]);
|
||||
while ($mail = $this->dba->fetch($mails)) {
|
||||
if (!$mail['seen']) {
|
||||
$unread = true;
|
||||
}
|
||||
|
@ -50,10 +65,10 @@ class Conversation extends BaseFactory
|
|||
$ids[] = $id;
|
||||
|
||||
if (empty($last_status)) {
|
||||
$last_status = DI::mstdnStatus()->createFromMailId($mail['id']);
|
||||
$last_status = $this->mstdnStatusFactory->createFromMailId($mail['id']);
|
||||
}
|
||||
|
||||
$accounts[] = DI::mstdnAccount()->createFromContactId($id, 0);
|
||||
$accounts[] = $this->mstdnAccountFactory->createFromContactId($id, 0);
|
||||
}
|
||||
|
||||
return new \Friendica\Object\Api\Mastodon\Conversation($id, $accounts, $unread, $last_status);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue