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,36 +1373,22 @@ class Transmitter
return $data; return $data;
} }
// Fetch the original id of the object if (empty($announce['comment'])) {
$activity = ActivityPub::fetchContent($announce['id'], $item['uid']); // Pure announce, without a quote
if (!empty($activity)) { $data['type'] = 'Announce';
$ldactivity = JsonLD::compact($activity); $data['object'] = $announce['id'];
$id = JsonLD::fetchElement($ldactivity, '@id'); return $data;
$type = str_replace('as:', '', JsonLD::fetchElement($ldactivity, '@type'));
if (!empty($id)) {
if (empty($announce['comment'])) {
// Pure announce, without a quote
$data['type'] = 'Announce';
$data['object'] = $id;
return $data;
}
// Quote
$data['type'] = 'Create';
$item['body'] = $announce['comment'] . "\n" . $id;
$data['object'] = self::createNote($item);
/// @todo Finally descide how to implement this in AP. This is a possible way:
$data['object']['attachment'][] = ['type' => $type, 'id' => $id];
$data['object']['source']['content'] = $orig_body;
return $data;
}
} }
$item['body'] = $orig_body; // Quote
$data['type'] = 'Create'; $data['type'] = 'Create';
$item['body'] = $announce['comment'] . "\n" . $id;
$data['object'] = self::createNote($item); $data['object'] = self::createNote($item);
/// @todo Finally descide how to implement this in AP. This is a possible way:
$data['object']['attachment'][] = ['type' => $type, 'id' => $id];
$data['object']['source']['content'] = $orig_body;
return $data; return $data;
} }
@ -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)];
} }
/** /**