aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Model
diff options
context:
space:
mode:
Diffstat (limited to 'Digitigrade/Model')
-rw-r--r--Digitigrade/Model/Interaction.php20
-rw-r--r--Digitigrade/Model/Note.php37
-rw-r--r--Digitigrade/Model/UserAccount.php4
3 files changed, 55 insertions, 6 deletions
diff --git a/Digitigrade/Model/Interaction.php b/Digitigrade/Model/Interaction.php
index 4ca1a0c..ed4ef45 100644
--- a/Digitigrade/Model/Interaction.php
+++ b/Digitigrade/Model/Interaction.php
@@ -1,6 +1,10 @@
<?php
namespace Digitigrade\Model;
+use Digitigrade\Timeline\HomeTimelineItem;
+use Digitigrade\Timeline\ReasonReshared;
+use Digitigrade\Timeline\TimelineItem;
+
class Interaction extends PushableModel {
public ?int $id;
public string $uri;
@@ -57,6 +61,22 @@ class Interaction extends PushableModel {
return array_unique($instances);
}
+ public function processTimelineAdditions() {
+ // basically, if this is a reshare, we need to put a home timeline item
+ // for all followers who can see the shared note
+ if ($this->kind != InteractionKind::RESHARE)
+ return;
+ $reason = new ReasonReshared($this->author);
+ $item = new TimelineItem($this->target, $reason);
+
+ foreach ($this->target->getRelevantActors() as $actor) {
+ if (!$actor->isLocal)
+ return;
+ $user = UserAccount::findByLinkedActor($actor);
+ HomeTimelineItem::fromTimelineItem($item, $user)->save();
+ }
+ }
+
public function jsonSerialize(): array {
if ($this->deleted) {
return [
diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php
index 71b25ae..7fb1221 100644
--- a/Digitigrade/Model/Note.php
+++ b/Digitigrade/Model/Note.php
@@ -2,8 +2,9 @@
namespace Digitigrade\Model;
use Digitigrade\Db;
-use Digitigrade\Job\PushObject;
-use Digitigrade\TimelineIncludeable;
+use Digitigrade\Timeline\HomeTimelineItem;
+use Digitigrade\Timeline\TimelineIncludeable;
+use Digitigrade\Timeline\TimelineItem;
class Note extends PushableModel implements TimelineIncludeable {
public ?int $id;
@@ -139,13 +140,19 @@ class Note extends PushableModel implements TimelineIncludeable {
return self::countWhere('in_reply_to = ? AND deleted = false', [$this->id]);
}
- protected function getRelevantServers(): array {
- $recipientActors = match ($this->privacy->scope) {
+ /**
+ * @return Actor[] actors who this note can be seen by, are mentioned, etc
+ */
+ public function getRelevantActors(): array {
+ return array_unique(array_merge(match ($this->privacy->scope) {
NotePrivacyScope::NONE => [],
NotePrivacyScope::MUTUALS => $this->author->findMutualFollows(),
default => $this->author->findFollowers()
- };
- $recipientActors = array_merge($recipientActors, $this->mentions, $this->privacy->alsoVisibleTo);
+ }, $this->mentions, $this->privacy->alsoVisibleTo, [$this->author]));
+ }
+
+ protected function getRelevantServers(): array {
+ $recipientActors = $this->getRelevantActors();
// reply-to and thread apex author should be covered by mentions but in case they're not:
if (isset($this->inReplyTo))
$recipientActors[] = $this->inReplyTo->author;
@@ -170,6 +177,24 @@ class Note extends PushableModel implements TimelineIncludeable {
render_template('note', ['note' => $this]);
}
+ public function toJsonReference(): mixed {
+ return $this->id;
+ }
+
+ public static function fromJsonReference(mixed $reference): self {
+ return self::find($reference);
+ }
+
+ public function processTimelineAdditions() {
+ $item = new TimelineItem($this);
+ foreach ($this->getRelevantActors() as $actor) {
+ if (!$actor->isLocal)
+ continue;
+ $user = UserAccount::findByLinkedActor($actor);
+ HomeTimelineItem::fromTimelineItem($item, $user)->save();
+ }
+ }
+
public function jsonSerialize(): array {
if ($this->deleted) {
return [
diff --git a/Digitigrade/Model/UserAccount.php b/Digitigrade/Model/UserAccount.php
index 72a9ce9..d0fa94b 100644
--- a/Digitigrade/Model/UserAccount.php
+++ b/Digitigrade/Model/UserAccount.php
@@ -59,6 +59,10 @@ class UserAccount extends Model {
return $user;
}
+ public static function findByLinkedActor(Actor $actor): ?self {
+ return self::findWhere('actor = ?', [$actor->id]);
+ }
+
public function verifyPassword(#[\SensitiveParameter] $attemptedPassword): bool {
return password_verify($attemptedPassword, $this->passwordHash);
}