[NOTE] Add isVisibleTo

This commit is contained in:
Hugo Sales 2020-09-10 22:27:23 +00:00 committed by Hugo Sales
parent 0c0b00da93
commit a6c24393b5
No known key found for this signature in database
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -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 [