[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(),
|
||||
'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;
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user