aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model
diff options
context:
space:
mode:
authorwinter2025-03-30 19:00:19 +0100
committerwinter2025-03-30 19:00:19 +0100
commitcd10f94269d7dcdd93df9fcda142a1e5a4441ae9 (patch)
tree75a00ef94c94259d3e6308d67e491b3800b47d89 /Digitigrade/Model
parentc26a1dca22fcced7b9cd37ace7a20ae71491fd66 (diff)
implement basic interaction controls
Diffstat (limited to 'Digitigrade/Model')
-rw-r--r--Digitigrade/Model/Note.php23
1 files changed, 22 insertions, 1 deletions
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