mirror of
https://github.com/friendica/friendica
synced 2024-11-10 05:02:58 +00:00
Fetch the user id when not provided
This commit is contained in:
parent
9c60b4127b
commit
a5a1c81790
1 changed files with 13 additions and 21 deletions
|
@ -263,17 +263,7 @@ class Receiver
|
|||
{
|
||||
$id = JsonLD::fetchElement($activity, '@id');
|
||||
if (!empty($id) && !$trust_source) {
|
||||
if (empty($uid)) {
|
||||
$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;
|
||||
}
|
||||
$fetch_uid = $uid ?: self::getBestUserForActivity($activity);
|
||||
|
||||
$fetched_activity = ActivityPub::fetchContent($id, $fetch_uid);
|
||||
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]))) {
|
||||
$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');
|
||||
if (empty($object_id)) {
|
||||
Logger::info('No object found');
|
||||
|
@ -331,11 +321,11 @@ class Receiver
|
|||
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)
|
||||
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)) {
|
||||
$type = $object_type;
|
||||
$activity = JsonLD::compact($data);
|
||||
|
@ -343,7 +333,7 @@ class Receiver
|
|||
// Some variables need to be refetched since the activity changed
|
||||
$actor = JsonLD::fetchElement($activity, 'as:actor', '@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
|
||||
// We can receive "#emojiReaction" when fetching content from Hubzilla systems
|
||||
// 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)) {
|
||||
Logger::info("Object data couldn't be processed");
|
||||
return [];
|
||||
|
@ -408,7 +398,7 @@ class Receiver
|
|||
|
||||
// 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'])) {
|
||||
$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
|
||||
*/
|
||||
private static function getBestUserForActivity(array $activity, string $actor)
|
||||
public static function getBestUserForActivity(array $activity)
|
||||
{
|
||||
$uid = 0;
|
||||
$actor = JsonLD::fetchElement($activity, 'as:actor', '@id') ?? '';
|
||||
|
||||
$receivers = self::getReceivers($activity, $actor);
|
||||
foreach ($receivers as $receiver) {
|
||||
if ($receiver['type'] == self::TARGET_GLOBAL) {
|
||||
|
|
Loading…
Reference in a new issue