summaryrefslogtreecommitdiffstats
path: root/lib/Db/NotesRequest.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Db/NotesRequest.php')
-rw-r--r--lib/Db/NotesRequest.php26
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php
index 306c85ff..3d42679e 100644
--- a/lib/Db/NotesRequest.php
+++ b/lib/Db/NotesRequest.php
@@ -30,11 +30,13 @@ declare(strict_types=1);
namespace OCA\Social\Db;
+use daita\MySmallPhpTools\Model\Cache;
use DateTime;
use OCA\Social\Exceptions\NoteNotFoundException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Note;
+use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -60,12 +62,17 @@ class NotesRequest extends NotesRequestBuilder {
/**
* Insert a new Note in the database.
*
- * @param Note $note
+ * @param Stream $note
*/
- public function save(Note $note) {
+ public function save(Stream $note) {
$dTime = new DateTime();
$dTime->setTimestamp($note->getPublishedTime());
+ $cache = '[]';
+ if ($note->gotCache()) {
+ $cache = json_encode($note->getCache(), JSON_UNESCAPED_SLASHES);
+ }
+
$qb = $this->getNotesInsertSql();
$qb->setValue('id', $qb->createNamedParameter($note->getId()))
->setValue('type', $qb->createNamedParameter($note->getType()))
@@ -94,6 +101,7 @@ class NotesRequest extends NotesRequestBuilder {
->setValue('attributed_to', $qb->createNamedParameter($note->getAttributedTo()))
->setValue('in_reply_to', $qb->createNamedParameter($note->getInReplyTo()))
->setValue('source', $qb->createNamedParameter($note->getSource()))
+ ->setValue('cache', $qb->createNamedParameter($cache))
->setValue(
'instances', $qb->createNamedParameter(
json_encode($note->getInstancePaths(), JSON_UNESCAPED_SLASHES)
@@ -110,6 +118,20 @@ class NotesRequest extends NotesRequestBuilder {
/**
+ * @param Stream $stream
+ * @param Cache $cache
+ */
+ public function updateCache(Stream $stream, Cache $cache) {
+ $qb = $this->getNotesUpdateSql();
+ $qb->set('cache', $qb->createNamedParameter(json_encode($cache, JSON_UNESCAPED_SLASHES)));
+
+ $this->limitToIdString($qb, $stream->getId());
+
+ $qb->execute();
+ }
+
+
+ /**
* @param string $id
*
* @return Note