forked from GNUsocial/gnu-social
[ActivityPub] Fix note URIs
This commit is contained in:
@@ -40,16 +40,17 @@ class Activitypub_create
|
||||
* Generates an ActivityPub representation of a Create
|
||||
*
|
||||
* @param string $actor
|
||||
* @param array $object
|
||||
* @param string $uri
|
||||
* @param mixed $object
|
||||
* @param bool $directMessage whether it is a private Create activity or not
|
||||
* @return array pretty array to be used in a response
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
*/
|
||||
public static function create_to_array(string $actor, array $object, bool $directMessage = false): array
|
||||
public static function create_to_array(string $actor, string $uri, $object, bool $directMessage = false): array
|
||||
{
|
||||
$res = [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => $object['id'] . '#create',
|
||||
'id' => $uri,
|
||||
'type' => 'Create',
|
||||
'directMessage' => $directMessage,
|
||||
'to' => $object['to'],
|
||||
|
@@ -100,7 +100,7 @@ class Activitypub_notice
|
||||
} else { // Note
|
||||
$item = [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => self::getUri($notice),
|
||||
'id' => self::note_uri($notice->getID()),
|
||||
'type' => 'Note',
|
||||
'published' => str_replace(' ', 'T', $notice->getCreated()) . 'Z',
|
||||
'url' => $notice->getUrl(),
|
||||
@@ -310,6 +310,7 @@ class Activitypub_notice
|
||||
* @throws InvalidUrlException
|
||||
* @throws Exception
|
||||
* @author Bruno Casteleiro <brunoccast@fc.up.pt>
|
||||
* @see note_uri when it's not a generic activity but a object type note
|
||||
*/
|
||||
public static function getUri(Notice $notice): string
|
||||
{
|
||||
@@ -320,6 +321,19 @@ class Activitypub_notice
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this if your Notice is in fact a note
|
||||
*
|
||||
* @param int $id
|
||||
* @return string it's uri
|
||||
* @author Diogo Cordeiro <diogo@fc.up.pt>
|
||||
* @see getUri for every other activity that aren't objects of a certain type like note
|
||||
*/
|
||||
public static function note_uri(int $id): string
|
||||
{
|
||||
return common_root_url() . 'object/note/' . $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract note policy type from note targets.
|
||||
*
|
||||
|
@@ -48,11 +48,11 @@ class Activitypub_tombstone
|
||||
$dead = Deleted_notice::getByID($id);
|
||||
$res = [
|
||||
'@context' => 'https://www.w3.org/ns/activitystreams',
|
||||
'id' => Activitypub_notice::getUri($id),
|
||||
'id' => Activitypub_notice::note_uri($id),
|
||||
'type' => 'Tombstone',
|
||||
'created' => str_replace(' ', 'T', $dead->act_created) . 'Z',
|
||||
'deleted' => str_replace(' ', 'T', $dead->created) . 'Z'
|
||||
];
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user