Merge pull request #9001 from annando/ap-forum
Improvements for delivering forum posts
This commit is contained in:
commit
8451939708
9 changed files with 192 additions and 71 deletions
|
@ -5710,7 +5710,7 @@ function api_friendica_activity($type)
|
||||||
|
|
||||||
$id = $_REQUEST['id'] ?? 0;
|
$id = $_REQUEST['id'] ?? 0;
|
||||||
|
|
||||||
$res = Item::performActivity($id, $verb);
|
$res = Item::performActivity($id, $verb, api_user());
|
||||||
|
|
||||||
if ($res) {
|
if ($res) {
|
||||||
if ($type == "xml") {
|
if ($type == "xml") {
|
||||||
|
|
|
@ -712,8 +712,13 @@ function conversation_fetch_comments($thread_items, $pinned) {
|
||||||
$lineno = 0;
|
$lineno = 0;
|
||||||
$actor = [];
|
$actor = [];
|
||||||
$received = '';
|
$received = '';
|
||||||
|
$owner = '';
|
||||||
|
|
||||||
while ($row = Item::fetch($thread_items)) {
|
while ($row = Item::fetch($thread_items)) {
|
||||||
|
if (($row['verb'] == Activity::ANNOUNCE) && ($row['author-link'] == $owner)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (($row['verb'] == Activity::ANNOUNCE) && !empty($row['contact-uid']) && ($row['received'] > $received) && ($row['thr-parent'] == $row['parent-uri'])) {
|
if (($row['verb'] == Activity::ANNOUNCE) && !empty($row['contact-uid']) && ($row['received'] > $received) && ($row['thr-parent'] == $row['parent-uri'])) {
|
||||||
$actor = ['link' => $row['author-link'], 'avatar' => $row['author-avatar'], 'name' => $row['author-name']];
|
$actor = ['link' => $row['author-link'], 'avatar' => $row['author-avatar'], 'name' => $row['author-name']];
|
||||||
$received = $row['received'];
|
$received = $row['received'];
|
||||||
|
@ -724,6 +729,10 @@ function conversation_fetch_comments($thread_items, $pinned) {
|
||||||
$parentlines[] = $lineno;
|
$parentlines[] = $lineno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (($row['gravity'] == GRAVITY_PARENT) && ($row['author-link'] != $row['owner-link'])) {
|
||||||
|
$owner = $row['owner-link'];
|
||||||
|
}
|
||||||
|
|
||||||
if ($row['gravity'] == GRAVITY_PARENT) {
|
if ($row['gravity'] == GRAVITY_PARENT) {
|
||||||
$row['pinned'] = $pinned;
|
$row['pinned'] = $pinned;
|
||||||
}
|
}
|
||||||
|
@ -765,7 +774,7 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
|
||||||
$max_comments = DI::config()->get('system', 'max_display_comments', 1000);
|
$max_comments = DI::config()->get('system', 'max_display_comments', 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
$params = ['order' => ['uid', 'commented' => true]];
|
$params = ['order' => ['gravity', 'uid', 'commented' => true]];
|
||||||
|
|
||||||
if ($max_comments > 0) {
|
if ($max_comments > 0) {
|
||||||
$params['limit'] = $max_comments;
|
$params['limit'] = $max_comments;
|
||||||
|
|
|
@ -34,7 +34,7 @@ function subthread_content(App $a)
|
||||||
|
|
||||||
$item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
|
$item_id = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : 0);
|
||||||
|
|
||||||
if (!Item::performActivity($item_id, 'follow')) {
|
if (!Item::performActivity($item_id, 'follow', local_user())) {
|
||||||
Logger::info('Following item failed', ['item' => $item_id]);
|
Logger::info('Following item failed', ['item' => $item_id]);
|
||||||
throw new HTTPException\BadRequestException();
|
throw new HTTPException\BadRequestException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1578,6 +1578,8 @@ class Item
|
||||||
return GRAVITY_COMMENT;
|
return GRAVITY_COMMENT;
|
||||||
} elseif ($activity->match($item['verb'], Activity::FOLLOW)) {
|
} elseif ($activity->match($item['verb'], Activity::FOLLOW)) {
|
||||||
return GRAVITY_ACTIVITY;
|
return GRAVITY_ACTIVITY;
|
||||||
|
} elseif ($activity->match($item['verb'], Activity::ANNOUNCE)) {
|
||||||
|
return GRAVITY_ACTIVITY;
|
||||||
}
|
}
|
||||||
Logger::info('Unknown gravity for verb', ['verb' => $item['verb']]);
|
Logger::info('Unknown gravity for verb', ['verb' => $item['verb']]);
|
||||||
return GRAVITY_UNKNOWN; // Should not happen
|
return GRAVITY_UNKNOWN; // Should not happen
|
||||||
|
@ -1798,6 +1800,7 @@ class Item
|
||||||
// It is mainly used in the "post_local" hook.
|
// It is mainly used in the "post_local" hook.
|
||||||
unset($item['api_source']);
|
unset($item['api_source']);
|
||||||
|
|
||||||
|
self::transformToForumPost($item);
|
||||||
|
|
||||||
// Check for hashtags in the body and repair or add hashtag links
|
// Check for hashtags in the body and repair or add hashtag links
|
||||||
$item['body'] = self::setHashtags($item['body']);
|
$item['body'] = self::setHashtags($item['body']);
|
||||||
|
@ -1988,6 +1991,44 @@ class Item
|
||||||
return $current_post;
|
return $current_post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert items to forum posts
|
||||||
|
*
|
||||||
|
* (public) forum posts in the new format consist of the regular post by the author
|
||||||
|
* followed by an announce message sent from the forum account.
|
||||||
|
* This means we have to look out for an announce message send by a forum account.
|
||||||
|
*
|
||||||
|
* @param array $item
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private static function transformToForumPost(array $item)
|
||||||
|
{
|
||||||
|
if ($item["verb"] != Activity::ANNOUNCE) {
|
||||||
|
// No announce message, so don't do anything
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pcontact = Contact::selectFirst(['nurl'], ['id' => $item['author-id'], 'contact-type' => Contact::TYPE_COMMUNITY]);
|
||||||
|
if (empty($pcontact['nurl'])) {
|
||||||
|
// The announce message wasn't created by a forum account, so we don't need to continue
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$contact = Contact::selectFirst(['id'], ['nurl' => $pcontact['nurl'], 'uid' => $item['uid']]);
|
||||||
|
if (!empty($contact['id'])) {
|
||||||
|
$condition = ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']];
|
||||||
|
Item::update(['owner-id' => $item['author-id'], 'contact-id' => $contact['id']], $condition);
|
||||||
|
$forum_item = Item::selectFirst(['id'], $condition);
|
||||||
|
if (!empty($forum_item['id'])) {
|
||||||
|
// This will trigger notifications like "X shared a new post"
|
||||||
|
UserItem::setNotification($forum_item['id']);
|
||||||
|
|
||||||
|
check_user_notification($forum_item['id']);
|
||||||
|
}
|
||||||
|
LOgger::info('Convert message into a forum message', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $item['uid'], 'owner-id' => $item['author-id'], 'contact-id' => $contact['id']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Distribute the given item to users who subscribed to their tags
|
* Distribute the given item to users who subscribed to their tags
|
||||||
*
|
*
|
||||||
|
@ -2673,6 +2714,10 @@ class Item
|
||||||
|
|
||||||
Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, $item_id);
|
Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, $item_id);
|
||||||
|
|
||||||
|
/// @todo This code should be activated by the end of the year 2020
|
||||||
|
// See also "createActivityFromItem"
|
||||||
|
//Item::performActivity($item_id, 'announce', $uid);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3002,11 +3047,12 @@ class Item
|
||||||
*
|
*
|
||||||
* Toggle activities as like,dislike,attend of an item
|
* Toggle activities as like,dislike,attend of an item
|
||||||
*
|
*
|
||||||
* @param string $item_id
|
* @param int $item_id
|
||||||
* @param string $verb
|
* @param string $verb
|
||||||
* Activity verb. One of
|
* Activity verb. One of
|
||||||
* like, unlike, dislike, undislike, attendyes, unattendyes,
|
* like, unlike, dislike, undislike, attendyes, unattendyes,
|
||||||
* attendno, unattendno, attendmaybe, unattendmaybe
|
* attendno, unattendno, attendmaybe, unattendmaybe,
|
||||||
|
* announce, unannouce
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
|
@ -3014,15 +3060,15 @@ class Item
|
||||||
* array $arr
|
* array $arr
|
||||||
* 'post_id' => ID of posted item
|
* 'post_id' => ID of posted item
|
||||||
*/
|
*/
|
||||||
public static function performActivity($item_id, $verb)
|
public static function performActivity(int $item_id, string $verb, int $uid)
|
||||||
{
|
{
|
||||||
if (!Session::isAuthenticated()) {
|
if (empty($uid)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::log('like: verb ' . $verb . ' item ' . $item_id);
|
Logger::notice('Start create activity', ['verb' => $verb, 'item' => $item_id, 'user' => $uid]);
|
||||||
|
|
||||||
$item = self::selectFirst(self::ITEM_FIELDLIST, ['`id` = ? OR `uri` = ?', $item_id, $item_id]);
|
$item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $item_id]);
|
||||||
if (!DBA::isResult($item)) {
|
if (!DBA::isResult($item)) {
|
||||||
Logger::log('like: unknown item ' . $item_id);
|
Logger::log('like: unknown item ' . $item_id);
|
||||||
return false;
|
return false;
|
||||||
|
@ -3030,48 +3076,35 @@ class Item
|
||||||
|
|
||||||
$item_uri = $item['uri'];
|
$item_uri = $item['uri'];
|
||||||
|
|
||||||
$uid = $item['uid'];
|
if (!in_array($item['uid'], [0, $uid])) {
|
||||||
if (($uid == 0) && local_user()) {
|
|
||||||
$uid = local_user();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Security::canWriteToUserWall($uid)) {
|
|
||||||
Logger::log('like: unable to write on wall ' . $uid);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Item::exists(['uri-id' => $item['parent-uri-id'], 'uid' => $uid])) {
|
if (!Item::exists(['uri-id' => $item['parent-uri-id'], 'uid' => $uid])) {
|
||||||
$stored = self::storeForUserByUriId($item['parent-uri-id'], $uid);
|
$stored = self::storeForUserByUriId($item['parent-uri-id'], $uid);
|
||||||
|
if (($item['parent-uri-id'] == $item['uri-id']) && !empty($stored)) {
|
||||||
|
$item = self::selectFirst(self::ITEM_FIELDLIST, ['id' => $stored]);
|
||||||
|
if (!DBA::isResult($item)) {
|
||||||
|
Logger::info('Could not fetch just created item - should not happen', ['stored' => $stored, 'uid' => $uid, 'item-uri' => $item_uri]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves the local post owner
|
// Retrieves the local post owner
|
||||||
$owner_self_contact = DBA::selectFirst('contact', [], ['uid' => $uid, 'self' => true]);
|
$owner = User::getOwnerDataById($uid);
|
||||||
if (!DBA::isResult($owner_self_contact)) {
|
if (empty($owner)) {
|
||||||
Logger::log('like: unknown owner ' . $uid);
|
Logger::info('Empty owner for user', ['uid' => $uid]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve the current logged in user's public contact
|
// Retrieve the current logged in user's public contact
|
||||||
$author_id = public_contact();
|
$author_id = Contact::getIdForURL($owner['url']);
|
||||||
|
if (empty($author_id)) {
|
||||||
$author_contact = DBA::selectFirst('contact', ['url'], ['id' => $author_id]);
|
Logger::info('Empty public contact');
|
||||||
if (!DBA::isResult($author_contact)) {
|
|
||||||
Logger::log('like: unknown author ' . $author_id);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contact-id is the uid-dependant author contact
|
|
||||||
if (local_user() == $uid) {
|
|
||||||
$item_contact_id = $owner_self_contact['id'];
|
|
||||||
} else {
|
|
||||||
$item_contact_id = Contact::getIdForURL($author_contact['url'], $uid);
|
|
||||||
$item_contact = DBA::selectFirst('contact', [], ['id' => $item_contact_id]);
|
|
||||||
if (!DBA::isResult($item_contact)) {
|
|
||||||
Logger::log('like: unknown item contact ' . $item_contact_id);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$activity = null;
|
$activity = null;
|
||||||
switch ($verb) {
|
switch ($verb) {
|
||||||
case 'like':
|
case 'like':
|
||||||
|
@ -3098,8 +3131,12 @@ class Item
|
||||||
case 'unfollow':
|
case 'unfollow':
|
||||||
$activity = Activity::FOLLOW;
|
$activity = Activity::FOLLOW;
|
||||||
break;
|
break;
|
||||||
|
case 'announce':
|
||||||
|
case 'unannounce':
|
||||||
|
$activity = Activity::ANNOUNCE;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Logger::log('like: unknown verb ' . $verb . ' for item ' . $item_id);
|
Logger::notice('unknown verb', ['verb' => $verb, 'item' => $item_id]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3170,7 +3207,7 @@ class Item
|
||||||
'guid' => System::createUUID(),
|
'guid' => System::createUUID(),
|
||||||
'uri' => self::newURI($item['uid']),
|
'uri' => self::newURI($item['uid']),
|
||||||
'uid' => $item['uid'],
|
'uid' => $item['uid'],
|
||||||
'contact-id' => $item_contact_id,
|
'contact-id' => $owner['id'],
|
||||||
'wall' => $item['wall'],
|
'wall' => $item['wall'],
|
||||||
'origin' => 1,
|
'origin' => 1,
|
||||||
'network' => Protocol::DFRN,
|
'network' => Protocol::DFRN,
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Like extends BaseModule
|
||||||
// @TODO: Replace with parameter from router
|
// @TODO: Replace with parameter from router
|
||||||
$itemId = (($app->argc > 1) ? Strings::escapeTags(trim($app->argv[1])) : 0);
|
$itemId = (($app->argc > 1) ? Strings::escapeTags(trim($app->argv[1])) : 0);
|
||||||
|
|
||||||
if (!Item::performActivity($itemId, $verb)) {
|
if (!Item::performActivity($itemId, $verb, local_user())) {
|
||||||
throw new HTTPException\BadRequestException();
|
throw new HTTPException\BadRequestException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -387,16 +387,11 @@ class Receiver
|
||||||
|
|
||||||
case 'as:Announce':
|
case 'as:Announce':
|
||||||
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
|
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
|
||||||
$profile = APContact::getByURL($object_data['actor']);
|
$object_data['thread-completion'] = true;
|
||||||
// Reshared posts from persons appear as summary at the bottom
|
|
||||||
// If this isn't set, then a single reshare appears on top. This is used for groups.
|
|
||||||
$object_data['thread-completion'] = ($profile['type'] != 'Group');
|
|
||||||
|
|
||||||
$item = ActivityPub\Processor::createItem($object_data);
|
$item = ActivityPub\Processor::createItem($object_data);
|
||||||
ActivityPub\Processor::postItem($object_data, $item);
|
ActivityPub\Processor::postItem($object_data, $item);
|
||||||
|
|
||||||
// Add the bottom reshare information only for persons
|
|
||||||
if ($profile['type'] != 'Group') {
|
|
||||||
$announce_object_data = self::processObject($activity);
|
$announce_object_data = self::processObject($activity);
|
||||||
$announce_object_data['name'] = $type;
|
$announce_object_data['name'] = $type;
|
||||||
$announce_object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
|
$announce_object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
|
||||||
|
@ -410,7 +405,6 @@ class Receiver
|
||||||
|
|
||||||
ActivityPub\Processor::createActivity($announce_object_data, Activity::ANNOUNCE);
|
ActivityPub\Processor::createActivity($announce_object_data, Activity::ANNOUNCE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'as:Like':
|
case 'as:Like':
|
||||||
|
|
|
@ -356,12 +356,14 @@ class Transmitter
|
||||||
}
|
}
|
||||||
|
|
||||||
$always_bcc = false;
|
$always_bcc = false;
|
||||||
|
$isforum = false;
|
||||||
|
|
||||||
// Check if we should always deliver our stuff via BCC
|
// Check if we should always deliver our stuff via BCC
|
||||||
if (!empty($item['uid'])) {
|
if (!empty($item['uid'])) {
|
||||||
$profile = Profile::getByUID($item['uid']);
|
$profile = User::getOwnerDataById($item['uid']);
|
||||||
if (!empty($profile)) {
|
if (!empty($profile)) {
|
||||||
$always_bcc = $profile['hide-friends'];
|
$always_bcc = $profile['hide-friends'];
|
||||||
|
$isforum = $profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +371,7 @@ class Transmitter
|
||||||
$always_bcc = true;
|
$always_bcc = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::isAnnounce($item) || DI::config()->get('debug', 'total_ap_delivery')) {
|
if ((self::isAnnounce($item) && !$isforum) || DI::config()->get('debug', 'total_ap_delivery')) {
|
||||||
// Will be activated in a later step
|
// Will be activated in a later step
|
||||||
$networks = Protocol::FEDERATED;
|
$networks = Protocol::FEDERATED;
|
||||||
} else {
|
} else {
|
||||||
|
@ -423,6 +425,10 @@ class Transmitter
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($isforum && DBA::isResult($contact) && ($contact['dfrn'] == Protocol::DFRN)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($profile = APContact::getByURL($contact['url'], false))) {
|
if (!empty($profile = APContact::getByURL($contact['url'], false))) {
|
||||||
$data['to'][] = $profile['url'];
|
$data['to'][] = $profile['url'];
|
||||||
}
|
}
|
||||||
|
@ -435,6 +441,10 @@ class Transmitter
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($isforum && DBA::isResult($contact) && ($contact['dfrn'] == Protocol::DFRN)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($profile = APContact::getByURL($contact['url'], false))) {
|
if (!empty($profile = APContact::getByURL($contact['url'], false))) {
|
||||||
if ($contact['hidden'] || $always_bcc) {
|
if ($contact['hidden'] || $always_bcc) {
|
||||||
$data['bcc'][] = $profile['url'];
|
$data['bcc'][] = $profile['url'];
|
||||||
|
@ -454,7 +464,9 @@ class Transmitter
|
||||||
if ($item['gravity'] != GRAVITY_PARENT) {
|
if ($item['gravity'] != GRAVITY_PARENT) {
|
||||||
// Comments to forums are directed to the forum
|
// Comments to forums are directed to the forum
|
||||||
// But comments to forums aren't directed to the followers collection
|
// But comments to forums aren't directed to the followers collection
|
||||||
if ($profile['type'] == 'Group') {
|
// This rule is only valid when the actor isn't the forum.
|
||||||
|
// The forum needs to transmit their content to their followers.
|
||||||
|
if (($profile['type'] == 'Group') && ($profile['url'] != $actor_profile['url'])) {
|
||||||
$data['to'][] = $profile['url'];
|
$data['to'][] = $profile['url'];
|
||||||
} else {
|
} else {
|
||||||
$data['cc'][] = $profile['url'];
|
$data['cc'][] = $profile['url'];
|
||||||
|
@ -555,6 +567,15 @@ class Transmitter
|
||||||
{
|
{
|
||||||
$inboxes = [];
|
$inboxes = [];
|
||||||
|
|
||||||
|
$isforum = false;
|
||||||
|
|
||||||
|
if (!empty($item['uid'])) {
|
||||||
|
$profile = User::getOwnerDataById($item['uid']);
|
||||||
|
if (!empty($profile)) {
|
||||||
|
$isforum = $profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (DI::config()->get('debug', 'total_ap_delivery')) {
|
if (DI::config()->get('debug', 'total_ap_delivery')) {
|
||||||
// Will be activated in a later step
|
// Will be activated in a later step
|
||||||
$networks = Protocol::FEDERATED;
|
$networks = Protocol::FEDERATED;
|
||||||
|
@ -579,6 +600,10 @@ class Transmitter
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($isforum && ($contact['dfrn'] == Protocol::DFRN)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (Network::isUrlBlocked($contact['url'])) {
|
if (Network::isUrlBlocked($contact['url'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -627,6 +652,8 @@ class Transmitter
|
||||||
$item_profile = APContact::getByURL($item['owner-link'], false);
|
$item_profile = APContact::getByURL($item['owner-link'], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$profile_uid = User::getIdForURL($item_profile['url']);
|
||||||
|
|
||||||
foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
|
foreach (['to', 'cc', 'bto', 'bcc'] as $element) {
|
||||||
if (empty($permissions[$element])) {
|
if (empty($permissions[$element])) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -639,7 +666,7 @@ class Transmitter
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($item_profile && $receiver == $item_profile['followers']) {
|
if ($item_profile && ($receiver == $item_profile['followers']) && ($uid == $profile_uid)) {
|
||||||
$inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal));
|
$inboxes = array_merge($inboxes, self::fetchTargetInboxesforUser($uid, $personal));
|
||||||
} else {
|
} else {
|
||||||
if (Contact::isLocal($receiver)) {
|
if (Contact::isLocal($receiver)) {
|
||||||
|
@ -807,6 +834,8 @@ class Transmitter
|
||||||
$type = 'Follow';
|
$type = 'Follow';
|
||||||
} elseif ($item['verb'] == Activity::TAG) {
|
} elseif ($item['verb'] == Activity::TAG) {
|
||||||
$type = 'Add';
|
$type = 'Add';
|
||||||
|
} elseif ($item['verb'] == Activity::ANNOUNCE) {
|
||||||
|
$type = 'Announce';
|
||||||
} else {
|
} else {
|
||||||
$type = '';
|
$type = '';
|
||||||
}
|
}
|
||||||
|
@ -851,12 +880,13 @@ class Transmitter
|
||||||
*/
|
*/
|
||||||
public static function createActivityFromItem($item_id, $object_mode = false)
|
public static function createActivityFromItem($item_id, $object_mode = false)
|
||||||
{
|
{
|
||||||
|
Logger::info('Fetching activity', ['item' => $item_id]);
|
||||||
$item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
|
$item = Item::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
|
||||||
|
|
||||||
if (!DBA::isResult($item)) {
|
if (!DBA::isResult($item)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @todo This code should be removed by the end of the year 2020
|
||||||
if ($item['wall'] && ($item['uri'] == $item['parent-uri'])) {
|
if ($item['wall'] && ($item['uri'] == $item['parent-uri'])) {
|
||||||
$owner = User::getOwnerDataById($item['uid']);
|
$owner = User::getOwnerDataById($item['uid']);
|
||||||
if (($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && ($item['author-link'] != $owner['url'])) {
|
if (($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && ($item['author-link'] != $owner['url'])) {
|
||||||
|
@ -868,6 +898,21 @@ class Transmitter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
/// @todo This code should be activated by the end of the year 2020
|
||||||
|
// See also "tagDeliver";
|
||||||
|
// In case of a forum post ensure to return the original post if author and forum are on the same machine
|
||||||
|
if (!empty($item['forum_mode'])) {
|
||||||
|
$author = Contact::getById($item['author-id'], ['nurl']);
|
||||||
|
if (!empty($author['nurl'])) {
|
||||||
|
$self = Contact::selectFirst(['uid'], ['nurl' => $author['nurl'], 'self' => true]);
|
||||||
|
if (!empty($self['uid'])) {
|
||||||
|
$item = Item::selectFirst([], ['uri-id' => $item['uri-id'], 'uid' => $self['uid']]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (empty($type)) {
|
if (empty($type)) {
|
||||||
$condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
|
$condition = ['item-uri' => $item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB];
|
||||||
$conversation = DBA::selectFirst('conversation', ['source'], $condition);
|
$conversation = DBA::selectFirst('conversation', ['source'], $condition);
|
||||||
|
@ -879,6 +924,7 @@ class Transmitter
|
||||||
unset($data['@context']);
|
unset($data['@context']);
|
||||||
unset($data['signature']);
|
unset($data['signature']);
|
||||||
}
|
}
|
||||||
|
Logger::info('Return stored conversation', ['item' => $item_id]);
|
||||||
return $data;
|
return $data;
|
||||||
} elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) {
|
} elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) {
|
||||||
if (!empty($data['@context'])) {
|
if (!empty($data['@context'])) {
|
||||||
|
@ -909,7 +955,7 @@ class Transmitter
|
||||||
$data['id'] = $item['uri'] . '/' . $type;
|
$data['id'] = $item['uri'] . '/' . $type;
|
||||||
$data['type'] = $type;
|
$data['type'] = $type;
|
||||||
|
|
||||||
if (Item::isForumPost($item) && ($type != 'Announce')) {
|
if (($type != 'Announce') || ($item['gravity'] != GRAVITY_PARENT)) {
|
||||||
$data['actor'] = $item['author-link'];
|
$data['actor'] = $item['author-link'];
|
||||||
} else {
|
} else {
|
||||||
$data['actor'] = $item['owner-link'];
|
$data['actor'] = $item['owner-link'];
|
||||||
|
@ -926,7 +972,11 @@ class Transmitter
|
||||||
} elseif ($data['type'] == 'Add') {
|
} elseif ($data['type'] == 'Add') {
|
||||||
$data = self::createAddTag($item, $data);
|
$data = self::createAddTag($item, $data);
|
||||||
} elseif ($data['type'] == 'Announce') {
|
} elseif ($data['type'] == 'Announce') {
|
||||||
|
if ($item['verb'] == ACTIVITY::ANNOUNCE) {
|
||||||
|
$data['object'] = $item['thr-parent'];
|
||||||
|
} else {
|
||||||
$data = self::createAnnounce($item, $data);
|
$data = self::createAnnounce($item, $data);
|
||||||
|
}
|
||||||
} elseif ($data['type'] == 'Follow') {
|
} elseif ($data['type'] == 'Follow') {
|
||||||
$data['object'] = $item['parent-uri'];
|
$data['object'] = $item['parent-uri'];
|
||||||
} elseif ($data['type'] == 'Undo') {
|
} elseif ($data['type'] == 'Undo') {
|
||||||
|
@ -947,7 +997,10 @@ class Transmitter
|
||||||
|
|
||||||
$owner = User::getOwnerDataById($uid);
|
$owner = User::getOwnerDataById($uid);
|
||||||
|
|
||||||
if (!$object_mode && !empty($owner)) {
|
Logger::info('Fetched activity', ['item' => $item_id, 'uid' => $uid]);
|
||||||
|
|
||||||
|
// We don't sign if we aren't the actor. This is important for relaying content especially for forums
|
||||||
|
if (!$object_mode && !empty($owner) && ($data['actor'] == $owner['url'])) {
|
||||||
return LDSignature::sign($data, $owner);
|
return LDSignature::sign($data, $owner);
|
||||||
} else {
|
} else {
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -1009,6 +1062,9 @@ class Transmitter
|
||||||
$tags[] = ['type' => 'Hashtag', 'href' => $url, 'name' => '#' . $term['name']];
|
$tags[] = ['type' => 'Hashtag', 'href' => $url, 'name' => '#' . $term['name']];
|
||||||
} else {
|
} else {
|
||||||
$contact = Contact::getByURL($term['url'], false, ['addr']);
|
$contact = Contact::getByURL($term['url'], false, ['addr']);
|
||||||
|
if (empty($contact)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!empty($contact['addr'])) {
|
if (!empty($contact['addr'])) {
|
||||||
$mention = '@' . $contact['addr'];
|
$mention = '@' . $contact['addr'];
|
||||||
} else {
|
} else {
|
||||||
|
@ -1491,6 +1547,10 @@ class Transmitter
|
||||||
*/
|
*/
|
||||||
public static function isAnnounce($item)
|
public static function isAnnounce($item)
|
||||||
{
|
{
|
||||||
|
if ($item['verb'] == Activity::ANNOUNCE) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$announce = self::getAnnounceArray($item);
|
$announce = self::getAnnounceArray($item);
|
||||||
if (empty($announce)) {
|
if (empty($announce)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -2162,6 +2162,7 @@ class DFRN
|
||||||
|| ($item["verb"] == Activity::ATTEND)
|
|| ($item["verb"] == Activity::ATTEND)
|
||||||
|| ($item["verb"] == Activity::ATTENDNO)
|
|| ($item["verb"] == Activity::ATTENDNO)
|
||||||
|| ($item["verb"] == Activity::ATTENDMAYBE)
|
|| ($item["verb"] == Activity::ATTENDMAYBE)
|
||||||
|
|| ($item["verb"] == Activity::ANNOUNCE)
|
||||||
) {
|
) {
|
||||||
$is_like = true;
|
$is_like = true;
|
||||||
$item["gravity"] = GRAVITY_ACTIVITY;
|
$item["gravity"] = GRAVITY_ACTIVITY;
|
||||||
|
|
|
@ -36,7 +36,7 @@ use Friendica\Model\Post;
|
||||||
use Friendica\Model\PushSubscriber;
|
use Friendica\Model\PushSubscriber;
|
||||||
use Friendica\Model\Tag;
|
use Friendica\Model\Tag;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Network\Probe;
|
use Friendica\Protocol\Activity;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
use Friendica\Protocol\Diaspora;
|
use Friendica\Protocol\Diaspora;
|
||||||
use Friendica\Protocol\OStatus;
|
use Friendica\Protocol\OStatus;
|
||||||
|
@ -301,8 +301,10 @@ class Notifier
|
||||||
|
|
||||||
// if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
|
// if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
|
||||||
// a delivery fork. private groups (forum_mode == 2) do not uplink
|
// a delivery fork. private groups (forum_mode == 2) do not uplink
|
||||||
|
/// @todo Possibly we should not uplink when the author is the forum itself?
|
||||||
|
|
||||||
if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== Delivery::UPLINK)) {
|
if ((intval($parent['forum_mode']) == 1) && !$top_level && ($cmd !== Delivery::UPLINK)
|
||||||
|
&& ($target_item['verb'] != Activity::ANNOUNCE)) {
|
||||||
Worker::add($a->queue['priority'], 'Notifier', Delivery::UPLINK, $target_id);
|
Worker::add($a->queue['priority'], 'Notifier', Delivery::UPLINK, $target_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +395,7 @@ class Notifier
|
||||||
if ($followup) {
|
if ($followup) {
|
||||||
$recipients = $recipients_followup;
|
$recipients = $recipients_followup;
|
||||||
}
|
}
|
||||||
$condition = ['id' => $recipients, 'self' => false,
|
$condition = ['id' => $recipients, 'self' => false, 'uid' => [0, $uid],
|
||||||
'blocked' => false, 'pending' => false, 'archive' => false];
|
'blocked' => false, 'pending' => false, 'archive' => false];
|
||||||
if (!empty($networks)) {
|
if (!empty($networks)) {
|
||||||
$condition['network'] = $networks;
|
$condition['network'] = $networks;
|
||||||
|
@ -439,7 +441,7 @@ class Notifier
|
||||||
|
|
||||||
// Add the relay to the list, avoid duplicates.
|
// Add the relay to the list, avoid duplicates.
|
||||||
// Don't send community posts to the relay. Forum posts via the Diaspora protocol are looking ugly.
|
// Don't send community posts to the relay. Forum posts via the Diaspora protocol are looking ugly.
|
||||||
if (!$followup && !Item::isForumPost($target_item, $owner)) {
|
if (!$followup && !Item::isForumPost($target_item, $owner) && !self::isForumPost($target_item)) {
|
||||||
$relay_list = Diaspora::relayList($target_id, $relay_list);
|
$relay_list = Diaspora::relayList($target_id, $relay_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -473,7 +475,7 @@ class Notifier
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::skipDFRN($rr, $target_item, $parent, $thr_parent, $cmd)) {
|
if (self::skipDFRN($rr, $target_item, $parent, $thr_parent, $owner, $cmd)) {
|
||||||
Logger::info('Contact can be delivered via AP, so skip delivery via legacy DFRN/Diaspora', ['id' => $target_id, 'url' => $rr['url']]);
|
Logger::info('Contact can be delivered via AP, so skip delivery via legacy DFRN/Diaspora', ['id' => $target_id, 'url' => $rr['url']]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -528,7 +530,7 @@ class Notifier
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::skipDFRN($contact, $target_item, $parent, $thr_parent, $cmd)) {
|
if (self::skipDFRN($contact, $target_item, $parent, $thr_parent, $owner, $cmd)) {
|
||||||
Logger::info('Contact can be delivered via AP, so skip delivery via legacy DFRN/Diaspora', ['target' => $target_id, 'url' => $contact['url']]);
|
Logger::info('Contact can be delivered via AP, so skip delivery via legacy DFRN/Diaspora', ['target' => $target_id, 'url' => $contact['url']]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -646,12 +648,13 @@ class Notifier
|
||||||
* @param array $item The post
|
* @param array $item The post
|
||||||
* @param array $parent The parent
|
* @param array $parent The parent
|
||||||
* @param array $thr_parent The thread parent
|
* @param array $thr_parent The thread parent
|
||||||
|
* @param array $owner Owner array
|
||||||
* @param string $cmd Notifier command
|
* @param string $cmd Notifier command
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
private static function skipDFRN($contact, $item, $parent, $thr_parent, $cmd)
|
private static function skipDFRN($contact, $item, $parent, $thr_parent, $owner, $cmd)
|
||||||
{
|
{
|
||||||
if (empty($parent['network'])) {
|
if (empty($parent['network'])) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -682,6 +685,12 @@ class Notifier
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For the time being we always deliver forum post via DFRN if possible
|
||||||
|
// This can be removed possible at the end of 2020 when hopefully most system can process AP forum posts
|
||||||
|
if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// We deliver reshares via AP whenever possible
|
// We deliver reshares via AP whenever possible
|
||||||
if (ActivityPub\Transmitter::isAnnounce($item)) {
|
if (ActivityPub\Transmitter::isAnnounce($item)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -812,4 +821,15 @@ class Notifier
|
||||||
|
|
||||||
return $delivery_queue_count;
|
return $delivery_queue_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the delivered item is a forum post
|
||||||
|
*
|
||||||
|
* @param array $item
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function isForumPost(array $item)
|
||||||
|
{
|
||||||
|
return !empty($item['forum_mode']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue