Fetch the user id when not provided
This commit is contained in:
parent
9c60b4127b
commit
a5a1c81790
|
@ -263,17 +263,7 @@ class Receiver
|
||||||
{
|
{
|
||||||
$id = JsonLD::fetchElement($activity, '@id');
|
$id = JsonLD::fetchElement($activity, '@id');
|
||||||
if (!empty($id) && !$trust_source) {
|
if (!empty($id) && !$trust_source) {
|
||||||
if (empty($uid)) {
|
$fetch_uid = $uid ?: self::getBestUserForActivity($activity);
|
||||||
$actor = JsonLD::fetchElement($activity, 'as:actor', '@id');
|
|
||||||
if (empty($actor)) {
|
|
||||||
$actor = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch a user out of the receivers of the message.
|
|
||||||
$fetch_uid = Receiver::getBestUserForActivity($activity, $actor);
|
|
||||||
} else {
|
|
||||||
$fetch_uid = $uid;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fetched_activity = ActivityPub::fetchContent($id, $fetch_uid);
|
$fetched_activity = ActivityPub::fetchContent($id, $fetch_uid);
|
||||||
if (!empty($fetched_activity)) {
|
if (!empty($fetched_activity)) {
|
||||||
|
@ -314,12 +304,12 @@ class Receiver
|
||||||
if (empty($activity['thread-completion']) && (empty($reception_types[$uid]) || in_array($reception_types[$uid], [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL]))) {
|
if (empty($activity['thread-completion']) && (empty($reception_types[$uid]) || in_array($reception_types[$uid], [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL]))) {
|
||||||
$reception_types[$uid] = self::TARGET_BCC;
|
$reception_types[$uid] = self::TARGET_BCC;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// We possibly need some user to fetch private content,
|
|
||||||
// so we fetch the first out ot the list.
|
|
||||||
$uid = self::getFirstUserFromReceivers($receivers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We possibly need some user to fetch private content,
|
||||||
|
// so we fetch one out of the receivers if no uid is provided.
|
||||||
|
$fetch_uid = $uid ?: self::getBestUserForActivity($activity);
|
||||||
|
|
||||||
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
||||||
if (empty($object_id)) {
|
if (empty($object_id)) {
|
||||||
Logger::info('No object found');
|
Logger::info('No object found');
|
||||||
|
@ -331,11 +321,11 @@ class Receiver
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$object_type = self::fetchObjectType($activity, $object_id, $uid);
|
$object_type = self::fetchObjectType($activity, $object_id, $fetch_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, array_merge(self::ACTIVITY_TYPES, ['as:Delete', 'as:Undo', 'as:Update']))) {
|
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, $fetch_uid);
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
$type = $object_type;
|
$type = $object_type;
|
||||||
$activity = JsonLD::compact($data);
|
$activity = JsonLD::compact($data);
|
||||||
|
@ -343,7 +333,7 @@ class Receiver
|
||||||
// Some variables need to be refetched since the activity changed
|
// Some variables need to be refetched since the activity changed
|
||||||
$actor = JsonLD::fetchElement($activity, 'as:actor', '@id');
|
$actor = JsonLD::fetchElement($activity, 'as:actor', '@id');
|
||||||
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
||||||
$object_type = self::fetchObjectType($activity, $object_id, $uid);
|
$object_type = self::fetchObjectType($activity, $object_id, $fetch_uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,7 +350,7 @@ class Receiver
|
||||||
// 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
|
||||||
// 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'), $fetch_uid);
|
||||||
if (empty($object_data)) {
|
if (empty($object_data)) {
|
||||||
Logger::info("Object data couldn't be processed");
|
Logger::info("Object data couldn't be processed");
|
||||||
return [];
|
return [];
|
||||||
|
@ -408,7 +398,7 @@ class Receiver
|
||||||
|
|
||||||
// An Undo is done on the object of an object, so we need that type as well
|
// An Undo is done on the object of an object, so we need that type as well
|
||||||
if (($type == 'as:Undo') && !empty($object_data['object_object'])) {
|
if (($type == 'as:Undo') && !empty($object_data['object_object'])) {
|
||||||
$object_data['object_object_type'] = self::fetchObjectType([], $object_data['object_object'], $uid);
|
$object_data['object_object_type'] = self::fetchObjectType([], $object_data['object_object'], $fetch_uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,9 +653,11 @@ class Receiver
|
||||||
*
|
*
|
||||||
* @return int user id
|
* @return int user id
|
||||||
*/
|
*/
|
||||||
private static function getBestUserForActivity(array $activity, string $actor)
|
public static function getBestUserForActivity(array $activity)
|
||||||
{
|
{
|
||||||
$uid = 0;
|
$uid = 0;
|
||||||
|
$actor = JsonLD::fetchElement($activity, 'as:actor', '@id') ?? '';
|
||||||
|
|
||||||
$receivers = self::getReceivers($activity, $actor);
|
$receivers = self::getReceivers($activity, $actor);
|
||||||
foreach ($receivers as $receiver) {
|
foreach ($receivers as $receiver) {
|
||||||
if ($receiver['type'] == self::TARGET_GLOBAL) {
|
if ($receiver['type'] == self::TARGET_GLOBAL) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user