$object_data['from-relay'] = $activity['from-relay'];
}
+ if (in_array('as:Question', [$object_data['object_type'] ?? '', $object_data['object_object_type'] ?? ''])) {
+ self::storeUnhandledActivity(false, $type, $object_data, $activity, $body, $uid, $trust_source, $push, $signer);
+ }
+
switch ($type) {
case 'as:Create':
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
// Fetch the receivers for the public and the followers collection
if ((($receiver == $followers) || (($receiver == self::PUBLIC_COLLECTION) && !$is_forum)) && !empty($actor)) {
- $receivers = self::getReceiverForActor($actor, $tags, $receivers, $follower_target);
+ $receivers = self::getReceiverForActor($actor, $tags, $receivers, $follower_target, $profile);
continue;
}
* @param array $tags
* @param array $receivers
* @param integer $target_type
+ * @param array $profile
*
* @return array with receivers (user id)
* @throws \Exception
*/
- private static function getReceiverForActor($actor, $tags, $receivers, $target_type)
+ private static function getReceiverForActor($actor, $tags, $receivers, $target_type, $profile)
{
$basecondition = ['rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
'network' => Protocol::FEDERATED, 'archive' => false, 'pending' => false];
- $condition = DBA::mergeConditions($basecondition, ["`nurl` = ? AND `uid` != ?", Strings::normaliseLink($actor), 0]);
- $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
- while ($contact = DBA::fetch($contacts)) {
- if (empty($receivers[$contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) {
- $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $target_type];
+ if (!empty($profile['uri-id'])) {
+ $condition = DBA::mergeConditions($basecondition, ["`uri-id` = ? AND `uid` != ?", $profile['uri-id'], 0]);
+ $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
+ while ($contact = DBA::fetch($contacts)) {
+ if (empty($receivers[$contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) {
+ $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $target_type];
+ }
}
- }
- DBA::close($contacts);
-
- // The queries are split because of performance issues
- $condition = DBA::mergeConditions($basecondition, ["`alias` IN (?, ?) AND `uid` != ?", Strings::normaliseLink($actor), $actor, 0]);
- $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
- while ($contact = DBA::fetch($contacts)) {
- if (empty($receivers[$contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) {
- $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $target_type];
+ DBA::close($contacts);
+ } else {
+ // This part will only be called while post update 1426 wasn't finished
+ $condition = DBA::mergeConditions($basecondition, ["`nurl` = ? AND `uid` != ?", Strings::normaliseLink($actor), 0]);
+ $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
+ while ($contact = DBA::fetch($contacts)) {
+ if (empty($receivers[$contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) {
+ $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $target_type];
+ }
+ }
+ DBA::close($contacts);
+
+ // The queries are split because of performance issues
+ $condition = DBA::mergeConditions($basecondition, ["`alias` IN (?, ?) AND `uid` != ?", Strings::normaliseLink($actor), $actor, 0]);
+ $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
+ while ($contact = DBA::fetch($contacts)) {
+ if (empty($receivers[$contact['uid']]) && self::isValidReceiverForActor($contact, $tags)) {
+ $receivers[$contact['uid']] = ['uid' => $contact['uid'], 'type' => $target_type];
+ }
}
+ DBA::close($contacts);
}
- DBA::close($contacts);
return $receivers;
}
return $attachlist;
}
+ /**
+ * Convert questions from JSON-LD format into a simplified format
+ *
+ * @param array $object
+ *
+ * @return array Questions in a simplified format
+ */
+ private static function processQuestion(array $object)
+ {
+ $question = [];
+
+ if (!empty($object['as:oneOf'])) {
+ $question['multiple'] = false;
+ $options = JsonLD::fetchElementArray($object, 'as:oneOf') ?? [];
+ } elseif (!empty($object['as:anyOf'])) {
+ $question['multiple'] = true;
+ $options = JsonLD::fetchElementArray($object, 'as:anyOf') ?? [];
+ } else {
+ return [];
+ }
+
+ $closed = JsonLD::fetchElement($object, 'as:closed', '@value');
+ if (!empty($closed)) {
+ $question['end-time'] = $closed;
+ } else {
+ $question['end-time'] = JsonLD::fetchElement($object, 'as:endTime', '@value');
+ }
+
+ $question['voters'] = (int)JsonLD::fetchElement($object, 'toot:votersCount', '@value');
+ $question['options'] = [];
+
+ $voters = 0;
+
+ foreach ($options as $option) {
+ if (JsonLD::fetchElement($option, '@type') != 'as:Note') {
+ continue;
+ }
+
+ $name = JsonLD::fetchElement($option, 'as:name', '@value');
+
+ if (empty($option['as:replies'])) {
+ continue;
+ }
+
+ $replies = JsonLD::fetchElement($option['as:replies'], 'as:totalItems', '@value');
+
+ $question['options'][] = ['name' => $name, 'replies' => $replies];
+
+ $voters += (int)$replies;
+ }
+
+ // For single choice question we can count the number of voters if not provided (like with Misskey)
+ if (empty($question['voters']) && !$question['multiple']) {
+ $question['voters'] = $voters;
+ }
+
+ return $question;
+ }
+
/**
* Fetch the original source or content with the "language" Markdown or HTML
*
$object_data['alternate-url'] = null;
}
+ if ($object_data['object_type'] == 'as:Question') {
+ $object_data['question'] = self::processQuestion($object);
+ }
+
$receiverdata = self::getReceivers($object, $object_data['actor'], $object_data['tags'], true);
$receivers = $reception_types = [];
foreach ($receiverdata as $key => $data) {