[ENTITY][Note] NoteType now becomes a varchar as predicted

This commit is contained in:
Diogo Peralta Cordeiro 2022-02-27 02:04:48 +00:00
parent a9b34b75b6
commit 5495a3c5ec
No known key found for this signature in database
GPG Key ID: 18D2D35001FBFAB0
3 changed files with 18 additions and 21 deletions

View File

@ -36,7 +36,6 @@ use App\Core\VisibilityScope;
use App\Entity\Activity;
use App\Entity\Actor;
use App\Entity\Note;
use App\Entity\NoteType;
use App\Util\Common;
use App\Util\Exception\BugFoundException;
use App\Util\Exception\ClientException;
@ -247,7 +246,7 @@ class Posting extends Component
rendered: $rendered,
source: $source,
);
$note->setType(NoteType::PAGE);
$note->setType('page');
$note->setTitle($title);
if ($flush_and_notify) {

View File

@ -44,7 +44,6 @@ use App\Core\Log;
use App\Core\Router\Router;
use App\Core\VisibilityScope;
use App\Entity\Note as GSNote;
use App\Entity\NoteType;
use App\Util\Common;
use App\Util\Exception\ClientException;
use App\Util\Exception\DuplicateFoundException;
@ -155,8 +154,8 @@ class Note extends Model
'reply_to' => $reply_to = $handleInReplyTo($type_note),
'modified' => new DateTime(),
'type' => match ($type_note->get('type')) {
'Page' => NoteType::PAGE,
default => NoteType::NOTE
'Page' => 'page',
default => 'note'
},
'source' => $source,
];
@ -354,8 +353,9 @@ class Note extends Model
$attr = [
'@context' => ActivityPub::$activity_streams_two_context,
'type' => $object->getScope() === VisibilityScope::MESSAGE ? 'ChatMessage' : (match ($object->getType()) {
NoteType::NOTE => 'Note',
NoteType::PAGE => 'Page'
'note' => 'Note',
'page' => 'Page',
default => throw new \Exception('Unsupported note type.')
}),
'id' => $object->getUrl(),
'published' => $object->getCreated()->format(DateTimeInterface::RFC3339),

View File

@ -43,20 +43,18 @@ use DateTimeInterface;
use function mb_substr;
use const PREG_SPLIT_NO_EMPTY;
// The domain of this enum are Notes
enum NoteType : int // having an int is just convenient
{
case NOTE = 1; // Is an element of microblogging, a direct message, or a reply to another note or page
case PAGE = 2; // Larger content note, beginning of a thread, or an email message
}
/**
* Entity for notices
* Entity for notes
*
* Notes can be of different types, such as:
* - Note: Is an element of microblogging, a direct message, or a reply to another note or page
* - Page: Larger content note, beginning of a thread, or an email message
*
* @category DB
* @package GNUsocial
*
* @author Hugo Sales <hugo@hsal.es>
* @author Diogo Peralta Cordeiro <@diogo.site>
* @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
@ -76,7 +74,7 @@ class Note extends Entity
private int $scope = 1; //VisibilityScope::EVERYWHERE->value;
private ?string $url = null;
private ?int $language_id = null;
private int $type = 1; //NoteType::NOTE->value;
private string $type = 'note';
private ?string $title = null;
private DateTimeInterface $created;
private DateTimeInterface $modified;
@ -213,15 +211,15 @@ class Note extends Entity
return $this->language_id;
}
public function setType(NoteType|int $type): self
public function setType(string $type): self
{
$this->type = \is_int($type) ? $type : $type->value;
$this->type = mb_substr($type, 0, 15);
return $this;
}
public function getType(): NoteType
public function getType(): string
{
return NoteType::from($this->type);
return $this->type;
}
public function setTitle(?string $title): self
@ -652,7 +650,7 @@ class Note extends Entity
'scope' => ['type' => 'int', 'not null' => true, 'default' => VisibilityScope::EVERYWHERE->value, 'description' => 'bit map for distribution scope; 1 = everywhere; 2 = this server only; 4 = addressees; 8 = groups; 16 = collection; 32 = messages'],
'url' => ['type' => 'text', 'description' => 'Permalink to Note'],
'language_id' => ['type' => 'int', 'foreign key' => true, 'target' => 'Language.id', 'multiplicity' => 'one to many', 'description' => 'The language for this note'],
'type' => ['type' => 'int', 'not null' => true, 'default' => NoteType::NOTE->value, 'description' => 'bit map for note type; 1 = Note; 2 = Page'],
'type' => ['type' => 'varchar', 'length' => 15, 'not null' => true, 'default' => 'note', 'description' => 'Such as note and page'],
'title' => ['type' => 'varchar', 'not null' => false, 'default' => null, 'length' => 129, 'description' => 'Title of a page or a note'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],