From a6c24393b5552e4a83c27cacdac00b97470ebebb Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 10 Sep 2020 22:27:23 +0000 Subject: [PATCH] [NOTE] Add isVisibleTo --- src/Entity/Note.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Entity/Note.php b/src/Entity/Note.php index 120164f9c2..182fd0da56 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -232,6 +232,21 @@ class Note extends Entity return null; } + public function isVisibleTo(/* GSActor|LocalUser */ $a): bool + { + $scope = NoteScope::create($this->scope); + return $scope->public + || ($scope->follower + && null != DB::find('follow', ['follower' => $a->getId(), 'followed' => $this->gsactor_id])) + || ($scope->addressee + && null != DB::find('notification', ['activity_id' => $this->id, 'gsactor_id' => $a->getId()])) + || ($scope->group + && [] != DB::sql('select m.gsactor_id from group_member m ' . + 'inner join group_inbox i on m.group_id = i.group_id ' . + 'inner join note n on i.activity_id = n.id where n.id = :id', + [], ['id' => $this->id])); + } + public static function schemaDef(): array { return [