Check if reshared item is an AP item

This commit is contained in:
Michael 2019-12-04 08:08:48 +00:00
parent abed3ba906
commit ef3664e6d4

View file

@ -1373,17 +1373,10 @@ class Transmitter
return $data; return $data;
} }
// Fetch the original id of the object
$activity = ActivityPub::fetchContent($announce['id'], $item['uid']);
if (!empty($activity)) {
$ldactivity = JsonLD::compact($activity);
$id = JsonLD::fetchElement($ldactivity, '@id');
$type = str_replace('as:', '', JsonLD::fetchElement($ldactivity, '@type'));
if (!empty($id)) {
if (empty($announce['comment'])) { if (empty($announce['comment'])) {
// Pure announce, without a quote // Pure announce, without a quote
$data['type'] = 'Announce'; $data['type'] = 'Announce';
$data['object'] = $id; $data['object'] = $announce['id'];
return $data; return $data;
} }
@ -1398,13 +1391,6 @@ class Transmitter
$data['object']['source']['content'] = $orig_body; $data['object']['source']['content'] = $orig_body;
return $data; return $data;
} }
}
$item['body'] = $orig_body;
$data['type'] = 'Create';
$data['object'] = self::createNote($item);
return $data;
}
/** /**
* Return announce related data if the item is an annunce * Return announce related data if the item is an annunce
@ -1415,19 +1401,37 @@ class Transmitter
*/ */
public static function getAnnounceObject($item) public static function getAnnounceObject($item)
{ {
$announce = api_share_as_retweet($item); if (!preg_match("/(.*?)\[share(.*?)\]\s?.*?\s?\[\/share\]\s?/ism", $item['body'], $matches)) {
if (empty($announce['plink'])) {
return []; return [];
} }
/// @ToDo Check if the announced item is an AP object $attributes = $matches[2];
$comment = $matches[1];
$profile = APContact::getByURL($announce['author-link'], false); preg_match("/guid='(.*?)'/ism", $attributes, $matches);
if (empty($matches[1])) {
preg_match('/guid="(.*?)"/ism', $attributes, $matches);
}
if (empty($matches[1])) {
return [];
}
$reshared_item = Item::selectFirst(['author-link', 'uri', 'network'], ['guid' => $matches[1]]);
if (!DBA::isResult($reshared_item)) {
return [];
}
if (!in_array($reshared_item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
return [];
}
$profile = APContact::getByURL($reshared_item['author-link'], false);
if (empty($profile)) { if (empty($profile)) {
return []; return [];
} }
return ['id' => $announce['plink'], 'actor' => $profile, 'comment' => trim($announce['share-pre-body'])]; return ['id' => $reshared_item['uri'], 'actor' => $profile, 'comment' => trim($comment)];
} }
/** /**