[PLUGIN][ActivityPub][Model][Note] Replace our directMessage extension with LitePub's

This commit is contained in:
Diogo Peralta Cordeiro 2022-02-23 22:25:11 +00:00
parent bc3d5245f5
commit af02bc7b32
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
4 changed files with 19 additions and 21 deletions

View File

@ -1,6 +1,6 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
@ -52,15 +52,15 @@ class ActivityCreate extends Activity
protected static function handle_core_activity(\App\Entity\Actor $actor, AbstractObject $type_activity, mixed $type_object, ?ActivitypubActivity &$ap_act): ActivitypubActivity
{
if ($type_object instanceof AbstractObject) {
if ($type_object->get('type') === 'Note' || $type_object->get('type') === 'Page') {
$actual_to = array_flip(is_string($type_object->get('to')) ? [$type_object->get('to')] : $type_object->get('to'));
$actual_cc = array_flip(is_string($type_object->get('cc')) ? [$type_object->get('cc')] : $type_object->get('cc'));
foreach (is_string($type_activity->get('to')) ? [$type_activity->get('to')] : ($type_activity->get('to') ?? []) as $to) {
if ($type_object->get('type') === 'Note' || $type_object->get('type') === 'ChatMessage' || $type_object->get('type') === 'Page') {
$actual_to = array_flip(\is_string($type_object->get('to')) ? [$type_object->get('to')] : $type_object->get('to'));
$actual_cc = array_flip(\is_string($type_object->get('cc')) ? [$type_object->get('cc')] : $type_object->get('cc'));
foreach (\is_string($type_activity->get('to')) ? [$type_activity->get('to')] : ($type_activity->get('to') ?? []) as $to) {
if ($to !== 'https://www.w3.org/ns/activitystreams#Public') {
$actual_to[$to] = true;
}
}
foreach (is_string($type_activity->get('cc')) ? [$type_activity->get('cc')] : ($type_activity->get('cc') ?? []) as $cc) {
foreach (\is_string($type_activity->get('cc')) ? [$type_activity->get('cc')] : ($type_activity->get('cc') ?? []) as $cc) {
if ($cc !== 'https://www.w3.org/ns/activitystreams#Public') {
$actual_cc[$cc] = true;
}
@ -78,20 +78,20 @@ class ActivityCreate extends Activity
}
// Store Activity
$act = GSActivity::create([
'actor_id' => $actor->getId(),
'verb' => 'create',
'actor_id' => $actor->getId(),
'verb' => 'create',
'object_type' => 'note',
'object_id' => $note->getId(),
'created' => new DateTime($type_activity->get('published') ?? 'now'),
'source' => 'ActivityPub',
'object_id' => $note->getId(),
'created' => new DateTime($type_activity->get('published') ?? 'now'),
'source' => 'ActivityPub',
]);
DB::persist($act);
// Store ActivityPub Activity
$ap_act = ActivitypubActivity::create([
'activity_id' => $act->getId(),
'activity_id' => $act->getId(),
'activity_uri' => $type_activity->get('id'),
'created' => new DateTime($type_activity->get('published') ?? 'now'),
'modified' => new DateTime(),
'created' => new DateTime($type_activity->get('published') ?? 'now'),
'modified' => new DateTime(),
]);
DB::persist($ap_act);
$ap_act->setObjectMentionIds($note->_object_mentions_ids);

View File

@ -176,7 +176,7 @@ class Note extends Model
$map['scope'] = 'unlisted';
} else {
// Either Followers-only or Direct
if ($type_note->get('directMessage') ?? false // Is DM explicitly?
if ($type_note->get('type') === 'ChatMessage' // Is DM explicitly?
|| (empty($type_note->get('cc')))) { // Only has TO targets
$map['scope'] = VisibilityScope::MESSAGE;
} else { // Then is collection
@ -328,9 +328,9 @@ class Note extends Model
$attr = [
'@context' => ActivityPub::$activity_streams_two_context,
'type' => match ($object->getType()) {
'type' => $object->getScope() === VisibilityScope::MESSAGE ? 'ChatMessage' : (match ($object->getType()) {
NoteType::NOTE => 'Note', NoteType::PAGE => 'Page'
},
}),
'id' => $object->getUrl(),
'published' => $object->getCreated()->format(DateTimeInterface::RFC3339),
'attributedTo' => $object->getActor()->getUri(Router::ABSOLUTE_URL),
@ -342,7 +342,6 @@ class Note extends Model
'tag' => [],
'inReplyTo' => \is_null($object->getReplyTo()) ? null : ActivityPub::getUriByObject(GSNote::getById($object->getReplyTo())),
'inConversation' => $object->getConversationUri(),
'directMessage' => $object->getScope() === VisibilityScope::MESSAGE,
];
// Target scope

View File

@ -80,7 +80,6 @@ class Favourite extends NoteHandlerPlugin
'source' => $source,
]);
DB::persist($activity);
}
return $activity;
}
@ -283,7 +282,7 @@ class Favourite extends NoteHandlerPlugin
}
if ($type_activity->get('type') === 'Like') { // Favourite
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
if ($type_object->get('type') === 'Note' || $type_object->get('type') === 'Page') {
if ($type_object->get('type') === 'Note' || $type_object->get('type') === 'ChatMessage' || $type_object->get('type') === 'Page') {
$note = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object);
$note_id = $note->getId();
} else {

View File

@ -357,7 +357,7 @@ class RepeatNote extends NoteHandlerPlugin
}
if ($type_activity->get('type') === 'Announce') { // Repeat
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
if ($type_object->get('type') === 'Note' || $type_object->get('type') === 'Page') {
if ($type_object->get('type') === 'Note' || $type_object->get('type') === 'ChatMessage' || $type_object->get('type') === 'Page') {
$note = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object);
$note_id = $note->getId();
} else {