forked from GNUsocial/gnu-social
[PLUGIN][ActivityPub][Model][Note] Replace our directMessage extension with LitePub's
This commit is contained in:
parent
bc3d5245f5
commit
af02bc7b32
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types = 1);
|
||||||
|
|
||||||
// {{{ License
|
// {{{ License
|
||||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
// 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
|
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 instanceof 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') {
|
||||||
$actual_to = array_flip(is_string($type_object->get('to')) ? [$type_object->get('to')] : $type_object->get('to'));
|
$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'));
|
$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) {
|
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') {
|
if ($to !== 'https://www.w3.org/ns/activitystreams#Public') {
|
||||||
$actual_to[$to] = true;
|
$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') {
|
if ($cc !== 'https://www.w3.org/ns/activitystreams#Public') {
|
||||||
$actual_cc[$cc] = true;
|
$actual_cc[$cc] = true;
|
||||||
}
|
}
|
||||||
@ -78,20 +78,20 @@ class ActivityCreate extends Activity
|
|||||||
}
|
}
|
||||||
// Store Activity
|
// Store Activity
|
||||||
$act = GSActivity::create([
|
$act = GSActivity::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(),
|
||||||
'created' => new DateTime($type_activity->get('published') ?? 'now'),
|
'created' => new DateTime($type_activity->get('published') ?? 'now'),
|
||||||
'source' => 'ActivityPub',
|
'source' => 'ActivityPub',
|
||||||
]);
|
]);
|
||||||
DB::persist($act);
|
DB::persist($act);
|
||||||
// Store ActivityPub Activity
|
// Store ActivityPub Activity
|
||||||
$ap_act = ActivitypubActivity::create([
|
$ap_act = ActivitypubActivity::create([
|
||||||
'activity_id' => $act->getId(),
|
'activity_id' => $act->getId(),
|
||||||
'activity_uri' => $type_activity->get('id'),
|
'activity_uri' => $type_activity->get('id'),
|
||||||
'created' => new DateTime($type_activity->get('published') ?? 'now'),
|
'created' => new DateTime($type_activity->get('published') ?? 'now'),
|
||||||
'modified' => new DateTime(),
|
'modified' => new DateTime(),
|
||||||
]);
|
]);
|
||||||
DB::persist($ap_act);
|
DB::persist($ap_act);
|
||||||
$ap_act->setObjectMentionIds($note->_object_mentions_ids);
|
$ap_act->setObjectMentionIds($note->_object_mentions_ids);
|
||||||
|
@ -176,7 +176,7 @@ class Note extends Model
|
|||||||
$map['scope'] = 'unlisted';
|
$map['scope'] = 'unlisted';
|
||||||
} else {
|
} else {
|
||||||
// Either Followers-only or Direct
|
// 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
|
|| (empty($type_note->get('cc')))) { // Only has TO targets
|
||||||
$map['scope'] = VisibilityScope::MESSAGE;
|
$map['scope'] = VisibilityScope::MESSAGE;
|
||||||
} else { // Then is collection
|
} else { // Then is collection
|
||||||
@ -328,9 +328,9 @@ class Note extends Model
|
|||||||
|
|
||||||
$attr = [
|
$attr = [
|
||||||
'@context' => ActivityPub::$activity_streams_two_context,
|
'@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'
|
NoteType::NOTE => 'Note', NoteType::PAGE => 'Page'
|
||||||
},
|
}),
|
||||||
'id' => $object->getUrl(),
|
'id' => $object->getUrl(),
|
||||||
'published' => $object->getCreated()->format(DateTimeInterface::RFC3339),
|
'published' => $object->getCreated()->format(DateTimeInterface::RFC3339),
|
||||||
'attributedTo' => $object->getActor()->getUri(Router::ABSOLUTE_URL),
|
'attributedTo' => $object->getActor()->getUri(Router::ABSOLUTE_URL),
|
||||||
@ -342,7 +342,6 @@ class Note extends Model
|
|||||||
'tag' => [],
|
'tag' => [],
|
||||||
'inReplyTo' => \is_null($object->getReplyTo()) ? null : ActivityPub::getUriByObject(GSNote::getById($object->getReplyTo())),
|
'inReplyTo' => \is_null($object->getReplyTo()) ? null : ActivityPub::getUriByObject(GSNote::getById($object->getReplyTo())),
|
||||||
'inConversation' => $object->getConversationUri(),
|
'inConversation' => $object->getConversationUri(),
|
||||||
'directMessage' => $object->getScope() === VisibilityScope::MESSAGE,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// Target scope
|
// Target scope
|
||||||
|
@ -80,7 +80,6 @@ class Favourite extends NoteHandlerPlugin
|
|||||||
'source' => $source,
|
'source' => $source,
|
||||||
]);
|
]);
|
||||||
DB::persist($activity);
|
DB::persist($activity);
|
||||||
|
|
||||||
}
|
}
|
||||||
return $activity;
|
return $activity;
|
||||||
}
|
}
|
||||||
@ -283,7 +282,7 @@ class Favourite extends NoteHandlerPlugin
|
|||||||
}
|
}
|
||||||
if ($type_activity->get('type') === 'Like') { // Favourite
|
if ($type_activity->get('type') === 'Like') { // Favourite
|
||||||
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
|
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 = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object);
|
||||||
$note_id = $note->getId();
|
$note_id = $note->getId();
|
||||||
} else {
|
} else {
|
||||||
|
@ -357,7 +357,7 @@ class RepeatNote extends NoteHandlerPlugin
|
|||||||
}
|
}
|
||||||
if ($type_activity->get('type') === 'Announce') { // Repeat
|
if ($type_activity->get('type') === 'Announce') { // Repeat
|
||||||
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
|
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 = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object);
|
||||||
$note_id = $note->getId();
|
$note_id = $note->getId();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user