converting published time

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/33/head
Maxence Lange 2018-11-16 09:47:59 -01:00
rodzic 595e734a81
commit 26dad9973e
11 zmienionych plików z 69 dodań i 18 usunięć

Wyświetl plik

@ -195,6 +195,12 @@
<notnull>true</notnull>
</field>
<field>
<name>published_time</name>
<type>timestamp</type>
<default>0</default>
</field>
<field>
<name>attributed_to</name>
<type>text</type>

Wyświetl plik

@ -5,7 +5,7 @@
<name>Social</name>
<summary>🎉 Nextcloud becomes part of the federated social networks!</summary>
<description><![CDATA[test]]></description>
<version>0.0.32</version>
<version>0.0.33</version>
<licence>agpl</licence>
<author mail="maxence@artificial-owl.com">Maxence Lange</author>
<author mail="jus@bitgrid.net">Julius Härtl</author>

8
composer.lock wygenerowano
Wyświetl plik

@ -12,12 +12,12 @@
"source": {
"type": "git",
"url": "https://github.com/daita/my-small-php-tools.git",
"reference": "f063c1101ee10e9cee68cc0cedbccd3aedec5ad3"
"reference": "d3e752060bde0206e6153b84ec1a7c8ff973fb75"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/f063c1101ee10e9cee68cc0cedbccd3aedec5ad3",
"reference": "f063c1101ee10e9cee68cc0cedbccd3aedec5ad3",
"url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/d3e752060bde0206e6153b84ec1a7c8ff973fb75",
"reference": "d3e752060bde0206e6153b84ec1a7c8ff973fb75",
"shasum": ""
},
"require": {
@ -40,7 +40,7 @@
}
],
"description": "My small PHP Tools",
"time": "2018-11-12T11:01:02+00:00"
"time": "2018-11-16T10:15:50+00:00"
}
],
"packages-dev": [],

Wyświetl plik

@ -31,7 +31,7 @@ declare(strict_types=1);
namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\TNCDataResponse;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception;
use OCA\Social\AppInfo\Application;
use OCA\Social\Service\ActorService;

Wyświetl plik

@ -30,7 +30,7 @@ declare(strict_types=1);
namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\TNCDataResponse;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception;
use OCA\Social\AppInfo\Application;
use OCA\Social\Db\NotesRequest;

Wyświetl plik

@ -31,7 +31,7 @@ namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TNCDataResponse;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception;
use OCA\Social\AppInfo\Application;
use OCA\Social\Model\Post;

Wyświetl plik

@ -31,7 +31,7 @@ namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TNCDataResponse;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use OC\User\NoUserException;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\AccountAlreadyExistsException;

Wyświetl plik

@ -30,7 +30,7 @@ declare(strict_types=1);
namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\TNCDataResponse;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use OCA\Social\AppInfo\Application;
use OCA\Social\Service\ActivityService;
use OCA\Social\Service\ActorService;

Wyświetl plik

@ -30,6 +30,7 @@ declare(strict_types=1);
namespace OCA\Social\Db;
use DateTime;
use OCA\Social\Model\ActivityPub\Note;
use OCA\Social\Service\ActivityService;
use OCA\Social\Service\ConfigService;
@ -64,6 +65,10 @@ class NotesRequest extends NotesRequestBuilder {
*/
public function save(Note $note): int {
try {
$dTime = new DateTime();
$dTime->setTimestamp($note->getPublishedTime());
$qb = $this->getNotesInsertSql();
$qb->setValue('id', $qb->createNamedParameter($note->getId()))
->setValue('to', $qb->createNamedParameter($note->getTo()))
@ -85,13 +90,17 @@ class NotesRequest extends NotesRequestBuilder {
->setValue('content', $qb->createNamedParameter($note->getContent()))
->setValue('summary', $qb->createNamedParameter($note->getSummary()))
->setValue('published', $qb->createNamedParameter($note->getPublished()))
->setValue(
'published_time', $qb->createNamedParameter($dTime, IQueryBuilder::PARAM_DATE)
)
->setValue('attributed_to', $qb->createNamedParameter($note->getAttributedTo()))
->setValue('in_reply_to', $qb->createNamedParameter($note->getInReplyTo()))
->setValue('source', $qb->createNamedParameter($note->getSource()))
->setValue(
'creation',
$qb->createNamedParameter(new \DateTime('now'), IQueryBuilder::PARAM_DATE)
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
);
$qb->execute();
return $qb->getLastInsertId();

Wyświetl plik

@ -78,7 +78,8 @@ class NotesRequestBuilder extends CoreRequestBuilder {
/** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->select(
'sn.id', 'sn.to', 'sn.to_array', 'sn.cc', 'sn.bcc', 'sn.content', 'sn.summary',
'sn.published', 'sn.attributed_to', 'sn.in_reply_to', 'sn.source', 'sn.creation'
'sn.published', 'sn.published_time', 'sn.attributed_to', 'sn.in_reply_to', 'sn.source',
'sn.creation'
)
->from(self::TABLE_SERVER_NOTES, 'sn');
@ -115,6 +116,7 @@ class NotesRequestBuilder extends CoreRequestBuilder {
->setBccArray(json_decode($data['bcc']))
->setPublished($data['published']);
$note->setContent($data['content'])
->setPublishedTime($this->getInt('published_time', $data, 0))
->setAttributedTo($data['attributed_to'])
->setInReplyTo($data['in_reply_to']);

Wyświetl plik

@ -30,7 +30,9 @@ declare(strict_types=1);
namespace OCA\Social\Model\ActivityPub;
use DateTime;
use JsonSerializable;
use OCA\Social\Service\ActivityService;
class Note extends ACore implements JsonSerializable {
@ -50,6 +52,9 @@ class Note extends ACore implements JsonSerializable {
/** @var string */
private $conversation = '';
/** @var int */
private $publishedTime;
/**
* Note constructor.
@ -157,6 +162,34 @@ class Note extends ACore implements JsonSerializable {
}
/**
* @return int
*/
public function getPublishedTime(): int {
return $this->publishedTime;
}
/**
* @param int $time
*
* @return Note
*/
public function setPublishedTime(int $time): Note {
$this->publishedTime = $time;
return $this;
}
/**
*
*/
public function convertPublished() {
$dTime = new DateTime($this->getPublished());
$dTime->format(ActivityService::DATE_FORMAT);
$this->publishedTime = $dTime->getTimestamp();
}
/**
* @param array $data
*/
@ -169,6 +202,7 @@ class Note extends ACore implements JsonSerializable {
$this->setSensitive($this->getBool('sensitive', $data, false));
$this->setConversation($this->get('conversation', $data, ''));
$this->setContent($this->get('content', $data, ''));
$this->convertPublished();
}
@ -179,12 +213,12 @@ class Note extends ACore implements JsonSerializable {
return array_merge(
parent::jsonSerialize(),
[
'content' => $this->getContent(),
'published' => $this->getPublished(),
'attributedTo' => $this->getRoot() . $this->getAttributedTo(),
'inReplyTo' => $this->getInReplyTo(),
'sensitive' => $this->isSensitive(),
'conversation' => $this->getConversation()
'content' => $this->getContent(),
'publishedTime' => $this->getPublishedTime(),
'attributedTo' => $this->getRoot() . $this->getAttributedTo(),
'inReplyTo' => $this->getInReplyTo(),
'sensitive' => $this->isSensitive(),
'conversation' => $this->getConversation()
]
);
}