diff --git a/components/Posting/Posting.php b/components/Posting/Posting.php index 9cfb698fca..c9e6099b86 100644 --- a/components/Posting/Posting.php +++ b/components/Posting/Posting.php @@ -220,25 +220,27 @@ class Posting extends Component } } - $act = Activity::create([ + $activity = Activity::create([ 'actor_id' => $actor->getId(), 'verb' => 'create', 'object_type' => 'note', 'object_id' => $note->getId(), 'source' => 'web', ]); - DB::persist($act); + DB::persist($activity); DB::flush(); $mentioned = []; foreach ($mentions as $mention) { foreach ($mention['mentioned'] as $m) { - $mentioned[] = $m->getId(); + if (!\is_null($m)) { + $mentioned[] = $m->getId(); + } } } - Event::handle('NewNotification', [$actor, $act, ['object' => $mentioned], "{$actor->getNickname()} created note {$note->getUrl()}"]); + Event::handle('NewNotification', [$actor, $activity, ['object' => $mentioned], "{$actor->getNickname()} created note {$note->getUrl()}"]); return $note; } diff --git a/src/Entity/Actor.php b/src/Entity/Actor.php index ca9d1e6021..e1d16ddd2a 100644 --- a/src/Entity/Actor.php +++ b/src/Entity/Actor.php @@ -487,6 +487,19 @@ class Actor extends Entity return $url; } + public static function getPlaceholderUri(string $nickname, int $type = self::PERSON, int $uri_type = Router::ABSOLUTE_URL): string + { + switch ($type) { + case self::PERSON: + case self::ORGANIZATION: + case self::BUSINESS: + case self::BOT: + return Router::url('actor_view_nickname', ['nickname' => $nickname], $uri_type); + case self::GROUP: + return Router::url('group_actor_view_nickname', ['nickname' => $nickname], $uri_type); + } + } + public function getAliases(): array { return array_keys($this->getAliasesWithIDs()); diff --git a/src/Util/Formatting.php b/src/Util/Formatting.php index c5a00384de..7de2292e2b 100644 --- a/src/Util/Formatting.php +++ b/src/Util/Formatting.php @@ -35,7 +35,6 @@ namespace App\Util; use App\Core\Event; use App\Core\Log; use App\Entity\Actor; -use App\Entity\Group; use App\Entity\Note; use App\Util\Exception\NicknameException; use App\Util\Exception\ServerException; @@ -355,22 +354,16 @@ abstract class Formatting $group_matches = self::findMentionsRaw($text, '!'); foreach ($group_matches as $group_match) { $nickname = Nickname::normalize($group_match[0], check_already_used: false, check_is_allowed: false); - $group = Group::getByNickname($nickname, $actor); - - if (!$group instanceof Group) { - continue; - } - - $profile = $group->getActor(); + $group = Actor::getByNickname($nickname, Actor::GROUP); $mentions[] = [ - 'mentioned' => [$profile], + 'mentioned' => [$group], 'type' => 'group', 'text' => $group_match[0], 'position' => $group_match[1], 'length' => mb_strlen($group_match[0]), - 'url' => $group->getUri(), - 'title' => $group->getFullname() ?? $group->getNickname(), + 'url' => !\is_null($group) ? $group->getUri() : Actor::getPlaceholderUri($nickname, Actor::GROUP), + 'title' => $group?->getFullname() ?? $group?->getNickname(), ]; }