[COMPONENT][Posting] Add facility to allow mentioning groups that don't yet exist
This commit is contained in:
parent
36976d8fe7
commit
315fd95b94
|
@ -220,25 +220,27 @@ class Posting extends Component
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$act = Activity::create([
|
$activity = Activity::create([
|
||||||
'actor_id' => $actor->getId(),
|
'actor_id' => $actor->getId(),
|
||||||
'verb' => 'create',
|
'verb' => 'create',
|
||||||
'object_type' => 'note',
|
'object_type' => 'note',
|
||||||
'object_id' => $note->getId(),
|
'object_id' => $note->getId(),
|
||||||
'source' => 'web',
|
'source' => 'web',
|
||||||
]);
|
]);
|
||||||
DB::persist($act);
|
DB::persist($activity);
|
||||||
|
|
||||||
DB::flush();
|
DB::flush();
|
||||||
|
|
||||||
$mentioned = [];
|
$mentioned = [];
|
||||||
foreach ($mentions as $mention) {
|
foreach ($mentions as $mention) {
|
||||||
foreach ($mention['mentioned'] as $m) {
|
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;
|
return $note;
|
||||||
}
|
}
|
||||||
|
|
|
@ -487,6 +487,19 @@ class Actor extends Entity
|
||||||
return $url;
|
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
|
public function getAliases(): array
|
||||||
{
|
{
|
||||||
return array_keys($this->getAliasesWithIDs());
|
return array_keys($this->getAliasesWithIDs());
|
||||||
|
|
|
@ -35,7 +35,6 @@ namespace App\Util;
|
||||||
use App\Core\Event;
|
use App\Core\Event;
|
||||||
use App\Core\Log;
|
use App\Core\Log;
|
||||||
use App\Entity\Actor;
|
use App\Entity\Actor;
|
||||||
use App\Entity\Group;
|
|
||||||
use App\Entity\Note;
|
use App\Entity\Note;
|
||||||
use App\Util\Exception\NicknameException;
|
use App\Util\Exception\NicknameException;
|
||||||
use App\Util\Exception\ServerException;
|
use App\Util\Exception\ServerException;
|
||||||
|
@ -355,22 +354,16 @@ abstract class Formatting
|
||||||
$group_matches = self::findMentionsRaw($text, '!');
|
$group_matches = self::findMentionsRaw($text, '!');
|
||||||
foreach ($group_matches as $group_match) {
|
foreach ($group_matches as $group_match) {
|
||||||
$nickname = Nickname::normalize($group_match[0], check_already_used: false, check_is_allowed: false);
|
$nickname = Nickname::normalize($group_match[0], check_already_used: false, check_is_allowed: false);
|
||||||
$group = Group::getByNickname($nickname, $actor);
|
$group = Actor::getByNickname($nickname, Actor::GROUP);
|
||||||
|
|
||||||
if (!$group instanceof Group) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$profile = $group->getActor();
|
|
||||||
|
|
||||||
$mentions[] = [
|
$mentions[] = [
|
||||||
'mentioned' => [$profile],
|
'mentioned' => [$group],
|
||||||
'type' => 'group',
|
'type' => 'group',
|
||||||
'text' => $group_match[0],
|
'text' => $group_match[0],
|
||||||
'position' => $group_match[1],
|
'position' => $group_match[1],
|
||||||
'length' => mb_strlen($group_match[0]),
|
'length' => mb_strlen($group_match[0]),
|
||||||
'url' => $group->getUri(),
|
'url' => !\is_null($group) ? $group->getUri() : Actor::getPlaceholderUri($nickname, Actor::GROUP),
|
||||||
'title' => $group->getFullname() ?? $group->getNickname(),
|
'title' => $group?->getFullname() ?? $group?->getNickname(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user