[PLUGIN][ActivityPub][Model][Note] Handle Mentions properly

This commit is contained in:
Diogo Peralta Cordeiro 2022-02-23 22:17:52 +00:00
parent f3c2e49e3f
commit bc3d5245f5
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
1 changed files with 6 additions and 23 deletions

View File

@ -254,15 +254,6 @@ class Note extends Model
foreach ($type_note->get('tag') ?? [] as $ap_tag) { foreach ($type_note->get('tag') ?? [] as $ap_tag) {
switch ($ap_tag->get('type')) { switch ($ap_tag->get('type')) {
case 'Mention': case 'Mention':
case 'Group':
try {
$actor = ActivityPub::getActorByUri($ap_tag->get('href'));
$object_mentions_ids[$actor->getId()] = $ap_tag->get('href');
} catch (Exception $e) {
Log::debug('ActivityPub->Model->Note->fromJson->getActorByUri', [$e]);
}
break;
case 'Collection':
$explorer = new Explorer(); $explorer = new Explorer();
try { try {
$actors = $explorer->lookup($ap_tag->get('href')); $actors = $explorer->lookup($ap_tag->get('href'));
@ -270,7 +261,7 @@ class Note extends Model
$object_mentions_ids[$actor->getId()] = $ap_tag->get('href'); $object_mentions_ids[$actor->getId()] = $ap_tag->get('href');
} }
} catch (Exception $e) { } catch (Exception $e) {
Log::debug('ActivityPub->Model->Note->fromJson->getActorByUri', [$e]); Log::debug('ActivityPub->Model->Note->fromJson->Mention->Explorer', [$e]);
} }
break; break;
case 'Hashtag': case 'Hashtag':
@ -393,19 +384,11 @@ class Note extends Model
// Mentions // Mentions
foreach ($object->getNotificationTargets() as $mention) { foreach ($object->getNotificationTargets() as $mention) {
if ($mention->isGroup()) { $attr['tag'][] = [
$attr['tag'][] = [ 'type' => 'Mention',
'type' => 'Group', 'href' => ($href = $mention->getUri()),
'href' => ($href = $mention->getUri()), 'name' => $mention->isGroup() ? FreeNetwork::groupTagToName($mention->getNickname(), $href) : FreeNetwork::mentionTagToName($mention->getNickname(), $href),
'name' => FreeNetwork::groupTagToName($mention->getNickname(), $href), ];
];
} else {
$attr['tag'][] = [
'type' => 'Mention',
'href' => ($href = $mention->getUri()),
'name' => FreeNetwork::mentionTagToName($mention->getNickname(), $href),
];
}
$attr['to'][] = $href; $attr['to'][] = $href;
} }