From cd10f94269d7dcdd93df9fcda142a1e5a4441ae9 Mon Sep 17 00:00:00 2001 From: winter Date: Sun, 30 Mar 2025 19:00:19 +0100 Subject: implement basic interaction controls --- Digitigrade/Model/Note.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'Digitigrade/Model') diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php index 0f75f5b..4675546 100644 --- a/Digitigrade/Model/Note.php +++ b/Digitigrade/Model/Note.php @@ -266,7 +266,7 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { } public function isViewableBy(?UserAccount $viewer): bool { - if ($this->privacy->scope == NotePrivacyScope::PUBLIC ) { + if ($this->privacy->scope == NotePrivacyScope::PUBLIC) { return true; } if ($viewer == null) { @@ -275,6 +275,27 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { return in_array($viewer->actor, $this->getRelevantActors()); } + public function isInteractibleBy(string $interactionKind, ?UserAccount $user): bool { + if ($user == null) { + return false; + } + if ($user->actor == $this->author) { + return true; + } + $interactors = match ($interactionKind) { + 'like', 'dislike' => $this->privacy->canOtherInteract, + 'reshare' => $this->privacy->canReshare, + 'reply' => $this->privacy->canReply, + default => throw new \InvalidArgumentException("invalid interaction kind: $interactionKind") + }; + return match ($interactors) { + NotePrivacyInteractors::ALL => true, + NotePrivacyInteractors::FOLLOWERS => in_array($user->actor, $this->author->findFollowers()), + NotePrivacyInteractors::MUTUALS => in_array($user->actor, $this->author->findMutualFollows()), + NotePrivacyInteractors::NONE => false + }; + } + /** * Gets this note's formatted content in the given mimetype or null if there isn't one * @param string $mimetype content type to return -- cgit v1.3