[PLUGIN][Reply] Separated replies from Note table.

[PLUGIN][Repeat] Deleted unnecessary card note template, info now to
appended at the end of note.
[PLUGIN][TreeNotes] WIP to accomodate reply plugin changes.
[TWIG][Runtime] Removed getAdditionalTemplateVars event.
This commit is contained in:
2021-11-07 01:32:06 +00:00
parent 7d8819a3da
commit f2f1bdc145
14 changed files with 291 additions and 232 deletions

View File

@@ -49,11 +49,9 @@ class Note extends Entity
private ?string $content_type = null;
private ?string $content = null;
private ?string $rendered = null;
private ?int $reply_to;
private ?bool $is_local;
private ?string $source;
private ?int $conversation;
private ?int $repeat_of;
private int $scope = VisibilityScope::PUBLIC;
private string $url;
private string $language;
@@ -118,17 +116,6 @@ class Note extends Entity
return $this->rendered;
}
public function setReplyTo(?int $reply_to): self
{
$this->reply_to = $reply_to;
return $this;
}
public function getReplyTo(): ?int
{
return $this->reply_to;
}
public function setIsLocal(?bool $is_local): self
{
$this->is_local = $is_local;
@@ -162,17 +149,6 @@ class Note extends Entity
return $this->conversation;
}
/* public function setRepeatOf(?int $repeat_of): self
{
$this->repeat_of = $repeat_of;
return $this;
}
public function getRepeatOf(): ?int
{
return $this->repeat_of;
}*/
public function setScope(int $scope): self
{
$this->scope = $scope;
@@ -291,27 +267,6 @@ class Note extends Entity
});
}
public function getReplies(): array
{
return Cache::getList('note-replies-' . $this->id, fn () => DB::dql('select n from note n where n.reply_to = :id', ['id' => $this->id]));
}
public function getReplyToNickname(): ?string
{
if (!empty($this->reply_to)) {
return Cache::get('note-reply-to-' . $this->id, function () {
return DB::dql(
<<<'EOF'
select g from note n join
actor g with n.actor_id = g.id where n.reply_to = :reply
EOF,
['reply' => $this->reply_to],
)[0]->getNickname();
});
}
return null;
}
/**
* Whether this note is visible to the given actor
*/
@@ -321,18 +276,18 @@ class Note extends Entity
$scope = VisibilityScope::create($this->scope);
return $scope->public
|| (!\is_null($a) && (
($scope->subscriber && 0 != DB::count('subscription', ['subscriber' => $a->getId(), 'subscribed' => $this->actor_id]))
|| ($scope->addressee && 0 != DB::count('notification', ['activity_id' => $this->id, 'actor_id' => $a->getId()]))
|| ($scope->group && [] != DB::dql(
<<<'EOF'
($scope->subscriber && 0 != DB::count('subscription', ['subscriber' => $a->getId(), 'subscribed' => $this->actor_id]))
|| ($scope->addressee && 0 != DB::count('notification', ['activity_id' => $this->id, 'actor_id' => $a->getId()]))
|| ($scope->group && [] != DB::dql(
<<<'EOF'
select m from group_member m
join group_inbox i with m.group_id = i.group_id
join note n with i.activity_id = n.id
where n.id = :note_id and m.actor_id = :actor_id
EOF,
['note_id' => $this->id, 'actor_id' => $a->getId()],
))
));
['note_id' => $this->id, 'actor_id' => $a->getId()],
))
));
}
/**
@@ -354,11 +309,9 @@ class Note extends Entity
'content' => ['type' => 'text', 'description' => 'note content'],
'content_type' => ['type' => 'varchar', 'not null' => true, 'default' => 'text/plain', 'length' => 129, 'description' => 'A note can be written in a multitude of formats such as text/plain, text/markdown, application/x-latex, and text/html'],
'rendered' => ['type' => 'text', 'description' => 'rendered note content, so we can keep the microtags (if not local)'],
'reply_to' => ['type' => 'int', 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'description' => 'note replied to, null if root of a conversation'],
'is_local' => ['type' => 'bool', 'description' => 'was this note generated by a local actor'],
'source' => ['type' => 'varchar', 'foreign key' => true, 'length' => 32, 'target' => 'NoteSource.code', 'multiplicity' => 'many to one', 'description' => 'fkey to source of note, like "web", "im", or "clientname"'],
'conversation' => ['type' => 'int', 'foreign key' => true, 'target' => 'Conversation.id', 'multiplicity' => 'one to one', 'description' => 'the local conversation id'],
// 'repeat_of' => ['type' => 'int', 'foreign key' => true, 'target' => 'Note.id', 'multiplicity' => 'one to one', 'description' => 'note this is a repeat of'],
'scope' => ['type' => 'int', 'not null' => true, 'default' => VisibilityScope::PUBLIC, 'description' => 'bit map for distribution scope; 0 = everywhere; 1 = this server only; 2 = addressees; 4 = groups; 8 = subscribers; 16 = messages; null = default'],
'url' => ['type' => 'text', 'description' => 'Permalink to Note'],
'language' => ['type' => 'int', 'foreign key' => true, 'target' => 'Language.id', 'multiplicity' => 'one to many', 'description' => 'The language for this note'],
@@ -370,7 +323,6 @@ class Note extends Entity
'note_created_id_is_local_idx' => ['created', 'is_local'],
'note_actor_created_idx' => ['actor_id', 'created'],
'note_is_local_created_actor_idx' => ['is_local', 'created', 'actor_id'],
// 'note_repeat_of_created_idx' => ['repeat_of', 'created'],
'note_conversation_created_idx' => ['conversation', 'created'],
'note_reply_to_idx' => ['reply_to'],
],