use Friendica\App;
use Friendica\Content\Feature;
+use Friendica\Content\Smilies;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
$data['outbox'] = DI::baseUrl() . '/outbox/' . $owner['nick'];
$data['featured'] = DI::baseUrl() . '/featured/' . $owner['nick'];
} else {
- $data['inbox'] = DI::baseUrl() . '/friendica/inbox';
+ $data['inbox'] = DI::baseUrl() . '/friendica/inbox';
+ $data['outbox'] = DI::baseUrl() . '/friendica/outbox';
}
$data['preferredUsername'] = $owner['nick'];
*/
public static function getReceiversForUriId(int $uri_id, bool $blindcopy)
{
+ $tags = Tag::getByURIId($uri_id, [Tag::TO, Tag::CC, Tag::BCC, Tag::AUDIENCE]);
+ if (empty($tags)) {
+ Logger::debug('No receivers found', ['uri-id' => $uri_id]);
+ $post = Post::selectFirst(Item::DELIVER_FIELDLIST, ['uri-id' => $uri_id, 'origin' => true]);
+ if (!empty($post)) {
+ ActivityPub\Transmitter::storeReceiversForItem($post);
+ $tags = Tag::getByURIId($uri_id, [Tag::TO, Tag::CC, Tag::BCC, Tag::AUDIENCE]);
+ Logger::debug('Receivers are created', ['uri-id' => $uri_id, 'receivers' => count($tags)]);
+ } else {
+ Logger::debug('Origin item not found', ['uri-id' => $uri_id]);
+ }
+ }
+
$receivers = [
'to' => [],
'cc' => [],
'audience' => [],
];
- foreach (Tag::getByURIId($uri_id, [Tag::TO, Tag::CC, Tag::BCC, Tag::AUDIENCE]) as $receiver) {
+ foreach ($tags as $receiver) {
switch ($receiver['type']) {
case Tag::TO:
$receivers['to'][] = $receiver['url'];
* Fetches a list of inboxes of followers of a given user
*
* @param integer $uid User ID
- * @param boolean $personal fetch personal inboxes
* @param boolean $all_ap Retrieve all AP enabled inboxes
* @return array of follower inboxes
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function fetchTargetInboxesforUser(int $uid, bool $personal = false, bool $all_ap = false): array
+ public static function fetchTargetInboxesforUser(int $uid, bool $all_ap = false): array
{
$inboxes = [];
$profile = APContact::getByURL($contact['url'], false);
if (!empty($profile)) {
- if (empty($profile['sharedinbox']) || $personal || Contact::isLocal($contact['url'])) {
+ if (empty($profile['sharedinbox']) || Contact::isLocal($contact['url'])) {
$target = $profile['inbox'];
} else {
$target = $profile['sharedinbox'];
*
* @param array $item Item array
* @param integer $uid User ID
- * @param boolean $personal fetch personal inboxes
* @return array with inboxes
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function fetchTargetInboxes(array $item, int $uid, bool $personal = false): array
+ public static function fetchTargetInboxes(array $item, int $uid): array
{
$permissions = self::getReceiversForUriId($item['uri-id'], true);
if (empty($permissions)) {
}
if ($item_profile && ($receiver == $item_profile['followers']) && ($uid == $profile_uid)) {
- $inboxes = array_merge_recursive($inboxes, self::fetchTargetInboxesforUser($uid, $personal, true));
+ $inboxes = array_merge_recursive($inboxes, self::fetchTargetInboxesforUser($uid, true));
} else {
$profile = APContact::getByURL($receiver, false);
if (!empty($profile)) {
$contact = Contact::getByURLForUser($receiver, $uid, false, ['id']);
- if (empty($profile['sharedinbox']) || $personal || $blindcopy || Contact::isLocal($receiver)) {
+ if (empty($profile['sharedinbox']) || $blindcopy || Contact::isLocal($receiver)) {
$target = $profile['inbox'];
} else {
$target = $profile['sharedinbox'];
return $inboxes;
}
+ /**
+ * Fetch the target inboxes for a given mail id
+ *
+ * @param integer $mail_id
+ * @return array
+ */
+ public static function fetchTargetInboxesFromMail(int $mail_id): array
+ {
+ $mail = DBA::selectFirst('mail', ['contact-id'], ['id' => $mail_id]);
+ if (!DBA::isResult($mail)) {
+ return [];
+ }
+
+ $account = DBA::selectFirst('account-user-view', ['ap-inbox'], ['id' => $mail['contact-id']]);
+ if (empty($account['ap-inbox'])) {
+ return [];
+ }
+
+ return [$account['ap-inbox'] => [$mail['contact-id']]];
+ }
+
/**
* Creates an array in the structure of the item table for a given mail id
*
return $location;
}
+ /**
+ * Appends emoji tags to a tag array according to the tags used.
+ *
+ * @param array $tags Tag array
+ * @param string $text Text containing tags like :tag:
+ * @return string normalized text
+ */
+ private static function addEmojiTags(array &$tags, string $text): string
+ {
+ $emojis = Smilies::extractUsedSmilies($text, $normalized);
+ foreach ($emojis as $name => $url) {
+ $tags[] = [
+ 'type' => 'Emoji',
+ 'name' => $name,
+ 'icon' => [
+ 'type' => 'Image',
+ 'url' => $url,
+ ],
+ ];
+ }
+ return $normalized;
+ }
+
/**
* Returns a tag array for a given item array
*
$item = Post\Media::addHTMLAttachmentToItem($item);
$body = $item['body'];
-
+ $emojis = [];
if ($type == 'Note') {
$body = $item['raw-body'] ?? self::removePictures($body);
}
+ $body = self::addEmojiTags($emojis, $body);
/**
* @todo Improve the automated summary
}
$data['attachment'] = self::createAttachmentList($item);
- $data['tag'] = self::createTagList($item, $data['quoteUrl'] ?? '');
+ $data['tag'] = array_merge(self::createTagList($item, $data['quoteUrl'] ?? ''), $emojis);
if (empty($data['location']) && (!empty($item['coord']) || !empty($item['location']))) {
$data['location'] = self::createLocation($item);
if (!empty($item['language'])) {
$languages = array_keys(json_decode($item['language'], true));
if (!empty($languages[0])) {
- return $languages[0];
+ return DI::l10n()->toISO6391($languages[0]);
}
}
if (!empty($item['uid'])) {
$user = DBA::selectFirst('user', ['language'], ['uid' => $item['uid']]);
if (!empty($user['language'])) {
- return $user['language'];
+ return DI::l10n()->toISO6391($user['language']);
}
}
// And finally just use the system language
- return DI::config()->get('system', 'language');
+ return DI::l10n()->toISO6391(DI::config()->get('system', 'language'));
}
/**