Merge pull request #11175 from annando/lemmy

Improved handling of several object types
This commit is contained in:
Hypolite Petovan 2022-01-23 05:47:26 -05:00 committed by GitHub
commit 3b19ccc351
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 5 deletions

View file

@ -56,6 +56,7 @@ class Item
const PT_VIDEO = 18; const PT_VIDEO = 18;
const PT_DOCUMENT = 19; const PT_DOCUMENT = 19;
const PT_EVENT = 32; const PT_EVENT = 32;
const PT_POLL = 33;
const PT_PERSONAL_NOTE = 128; const PT_PERSONAL_NOTE = 128;
// Posting reasons (Why had a post been stored for a user?) // Posting reasons (Why had a post been stored for a user?)

View file

@ -258,6 +258,8 @@ class Processor
$item['post-type'] = Item::PT_IMAGE; $item['post-type'] = Item::PT_IMAGE;
} elseif ($activity['object_type'] == 'as:Page') { } elseif ($activity['object_type'] == 'as:Page') {
$item['post-type'] = Item::PT_PAGE; $item['post-type'] = Item::PT_PAGE;
} elseif ($activity['object_type'] == 'as:Question') {
$item['post-type'] = Item::PT_POLL;
} elseif ($activity['object_type'] == 'as:Video') { } elseif ($activity['object_type'] == 'as:Video') {
$item['post-type'] = Item::PT_VIDEO; $item['post-type'] = Item::PT_VIDEO;
} else { } else {

View file

@ -56,7 +56,7 @@ class Receiver
{ {
const PUBLIC_COLLECTION = 'as:Public'; const PUBLIC_COLLECTION = 'as:Public';
const ACCOUNT_TYPES = ['as:Person', 'as:Organization', 'as:Service', 'as:Group', 'as:Application']; const ACCOUNT_TYPES = ['as:Person', 'as:Organization', 'as:Service', 'as:Group', 'as:Application'];
const CONTENT_TYPES = ['as:Note', 'as:Article', 'as:Video', 'as:Image', 'as:Event', 'as:Audio', 'as:Page']; const CONTENT_TYPES = ['as:Note', 'as:Article', 'as:Video', 'as:Image', 'as:Event', 'as:Audio', 'as:Page', 'as:Question'];
const ACTIVITY_TYPES = ['as:Like', 'as:Dislike', 'as:Accept', 'as:Reject', 'as:TentativeAccept']; const ACTIVITY_TYPES = ['as:Like', 'as:Dislike', 'as:Accept', 'as:Reject', 'as:TentativeAccept'];
const TARGET_UNKNOWN = 0; const TARGET_UNKNOWN = 0;
@ -322,7 +322,7 @@ class Receiver
$object_type = self::fetchObjectType($activity, $object_id, $uid); $object_type = self::fetchObjectType($activity, $object_id, $uid);
// Fetch the activity on Lemmy "Announce" messages (announces of activities) // Fetch the activity on Lemmy "Announce" messages (announces of activities)
if (($type == 'as:Announce') && in_array($object_type, self::ACTIVITY_TYPES)) { if (($type == 'as:Announce') && in_array($object_type, array_merge(self::ACTIVITY_TYPES, ['as:Delete', 'as:Undo', 'as:Update']))) {
$data = ActivityPub::fetchContent($object_id, $uid); $data = ActivityPub::fetchContent($object_id, $uid);
if (!empty($data)) { if (!empty($data)) {
$type = $object_type; $type = $object_type;
@ -335,9 +335,18 @@ class Receiver
} }
} }
// Any activities on account types must not be altered
if (in_array($object_type, self::ACCOUNT_TYPES)) {
$object_data = [];
$object_data['id'] = JsonLD::fetchElement($activity, '@id');
$object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
$object_data['object_actor'] = JsonLD::fetchElement($activity['as:object'], 'as:actor', '@id');
$object_data['object_object'] = JsonLD::fetchElement($activity['as:object'], 'as:object');
$object_data['object_type'] = JsonLD::fetchElement($activity['as:object'], '@type');
$object_data['push'] = $push;
} elseif (in_array($type, ['as:Create', 'as:Update', 'as:Announce']) || strpos($type, '#emojiReaction')) {
// Fetch the content only on activities where this matters // Fetch the content only on activities where this matters
// We can receive "#emojiReaction" when fetching content from Hubzilla systems // We can receive "#emojiReaction" when fetching content from Hubzilla systems
if (in_array($type, ['as:Create', 'as:Update', 'as:Announce']) || strpos($type, '#emojiReaction')) {
// Always fetch on "Announce" // Always fetch on "Announce"
$object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source && ($type != 'as:Announce'), $uid); $object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source && ($type != 'as:Announce'), $uid);
if (empty($object_data)) { if (empty($object_data)) {
@ -361,7 +370,7 @@ class Receiver
} }
} elseif (in_array($type, array_merge(self::ACTIVITY_TYPES, ['as:Follow'])) && in_array($object_type, self::CONTENT_TYPES)) { } elseif (in_array($type, array_merge(self::ACTIVITY_TYPES, ['as:Follow'])) && in_array($object_type, self::CONTENT_TYPES)) {
// Create a mostly empty array out of the activity data (instead of the object). // Create a mostly empty array out of the activity data (instead of the object).
// This way we later don't have to check for the existence of ech individual array element. // This way we later don't have to check for the existence of each individual array element.
$object_data = self::processObject($activity); $object_data = self::processObject($activity);
$object_data['name'] = $type; $object_data['name'] = $type;
$object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id'); $object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
@ -489,7 +498,7 @@ class Receiver
// Lemmy is announcing activities. // Lemmy is announcing activities.
// We are changing the announces into regular activities. // We are changing the announces into regular activities.
if (($type == 'as:Announce') && in_array($object_data['type'] ?? '', self::ACTIVITY_TYPES)) { if (($type == 'as:Announce') && in_array($object_data['type'] ?? '', array_merge(self::ACTIVITY_TYPES, ['as:Delete', 'as:Undo', 'as:Update']))) {
$type = $object_data['type']; $type = $object_data['type'];
} }

View file

@ -2712,6 +2712,9 @@ class Diaspora
$datarray["object-type"] = Activity\ObjectType::IMAGE; $datarray["object-type"] = Activity\ObjectType::IMAGE;
$datarray["post-type"] = Item::PT_IMAGE; $datarray["post-type"] = Item::PT_IMAGE;
} elseif ($data->poll) {
$datarray["object-type"] = Activity\ObjectType::NOTE;
$datarray["post-type"] = Item::PT_POLL;
} else { } else {
$datarray["object-type"] = Activity\ObjectType::NOTE; $datarray["object-type"] = Activity\ObjectType::NOTE;
$datarray["post-type"] = Item::PT_NOTE; $datarray["post-type"] = Item::PT_NOTE;