[UI] Add mechanism for rendering note contents in different formats. Implement plaintext rendering. Use rendered field for note content, rather than the content itself
This commit is contained in:
@@ -25,6 +25,7 @@ use App\Core\Cache;
|
||||
use App\Core\DB\DB;
|
||||
use App\Core\Entity;
|
||||
use App\Core\Event;
|
||||
use App\Core\GSFile;
|
||||
use App\Core\VisibilityScope;
|
||||
use DateTimeInterface;
|
||||
|
||||
@@ -208,7 +209,12 @@ class Note extends Entity
|
||||
// @codeCoverageIgnoreEnd
|
||||
// }}} Autocode
|
||||
|
||||
public function getActorNickname()
|
||||
public function getActor(): GSActor
|
||||
{
|
||||
return GSActor::getFromId($this->gsactor_id);
|
||||
}
|
||||
|
||||
public function getActorNickname(): string
|
||||
{
|
||||
return GSActor::getNicknameFromId($this->gsactor_id);
|
||||
}
|
||||
@@ -219,13 +225,14 @@ class Note extends Entity
|
||||
Event::handle('GetAvatarUrl', [$this->getGSActorId(), &$url]);
|
||||
return $url;
|
||||
}
|
||||
|
||||
public static function getAllNotes(int $noteScope): array
|
||||
{
|
||||
return DB::sql('select * from note n ' .
|
||||
'where n.reply_to is null and (n.scope & :notescope) <> 0 ' .
|
||||
'order by n.created DESC',
|
||||
['n' => 'App\Entity\Note'],
|
||||
['notescope' => $noteScope]
|
||||
'where n.reply_to is null and (n.scope & :notescope) <> 0 ' .
|
||||
'order by n.created DESC',
|
||||
['n' => 'App\Entity\Note'],
|
||||
['notescope' => $noteScope]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -290,6 +297,49 @@ class Note extends Entity
|
||||
['note_id' => $this->id, 'actor_id' => $a->getId()]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of NoteToLink or fill in the
|
||||
* properties of $obj with the associative array $args. Does
|
||||
* persist the result
|
||||
*/
|
||||
public static function create(array $args, mixed $obj = null): self
|
||||
{
|
||||
/** @var \Symfony\Component\HttpFoundation\File\UploadedFile[] $attachments */
|
||||
$attachments = $args['attachments'];
|
||||
unset($args['attachments']);
|
||||
|
||||
$note = parent::create($args, new self());
|
||||
|
||||
$processed_attachments = [];
|
||||
foreach ($attachments as $f) {
|
||||
Event::handle('EnforceUserFileQuota', [$f->getSize(), $args['gsactor_id']]);
|
||||
$processed_attachments[] = [GSFile::sanitizeAndStoreFileAsAttachment($f), $f->getClientOriginalName()];
|
||||
}
|
||||
|
||||
// Need file and note ids for the next step
|
||||
DB::persist($note);
|
||||
|
||||
if ($processed_attachments != []) {
|
||||
foreach ($processed_attachments as [$a, $fname]) {
|
||||
if (DB::count('gsactor_to_attachment', $args = ['attachment_id' => $a->getId(), 'gsactor_id' => $args['gsactor_id']]) === 0) {
|
||||
DB::persist(GSActorToAttachment::create($args));
|
||||
}
|
||||
DB::persist(AttachmentToNote::create(['attachment_id' => $a->getId(), 'note_id' => $note->getId(), 'title' => $fname]));
|
||||
}
|
||||
}
|
||||
|
||||
return $note;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GSActor[]
|
||||
*/
|
||||
public function getAttentionProfiles(): array
|
||||
{
|
||||
// TODO implement
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function schemaDef(): array
|
||||
{
|
||||
return [
|
||||
|
Reference in New Issue
Block a user