Replace "forum" by "group" in the rest of the code

This commit is contained in:
Hypolite Petovan 2023-05-30 09:15:17 -04:00
parent 03bebf57c5
commit 3385147f25
59 changed files with 378 additions and 424 deletions

View file

@ -52,8 +52,8 @@ use Friendica\Util\JsonLD;
* - Polling the outboxes for missing content?
*
* Missing parts from DFRN:
* - Public Forum
* - Private Forum
* - Public Group
* - Private Group
* - Relocation
*/
class ActivityPub

View file

@ -415,7 +415,7 @@ class Processor
$item['post-type'] = Item::PT_NOTE;
}
$item['isForum'] = false;
$item['isGroup'] = false;
if (!empty($activity['thread-completion'])) {
if ($activity['thread-completion'] != $item['owner-id']) {
@ -434,7 +434,7 @@ class Processor
$item['owner-id'] = $item['author-id'];
} else {
$actor = APContact::getByURL($item['owner-link'], false);
$item['isForum'] = ($actor['type'] ?? 'Person') == 'Group';
$item['isGroup'] = ($actor['type'] ?? 'Person') == 'Group';
}
$item['uri'] = $activity['id'];
@ -1059,7 +1059,7 @@ class Processor
$item['causer-id'] = ($item['gravity'] == Item::GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'];
}
if ($item['isForum'] ?? false) {
if ($item['isGroup'] ?? false) {
$item['contact-id'] = Contact::getIdForURL($activity['actor'], $receiver);
} else {
$item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver);
@ -1075,7 +1075,7 @@ class Processor
}
if (($receiver != 0) && ($item['gravity'] == Item::GRAVITY_PARENT) && !in_array($item['post-reason'], [Item::PR_FOLLOWER, Item::PR_TAG, item::PR_TO, Item::PR_CC, Item::PR_AUDIENCE])) {
if (!($item['isForum'] ?? false)) {
if (!($item['isGroup'] ?? false)) {
if ($item['post-reason'] == Item::PR_BCC) {
Logger::info('Top level post via BCC from a non sharer, ignoring', ['uid' => $receiver, 'contact' => $item['contact-id'], 'url' => $item['uri']]);
continue;
@ -1089,16 +1089,16 @@ class Processor
}
}
$is_forum = false;
$isGroup = false;
$user = User::getById($receiver, ['account-type']);
if (!empty($user['account-type'])) {
$is_forum = ($user['account-type'] == User::ACCOUNT_TYPE_COMMUNITY);
$isGroup = ($user['account-type'] == User::ACCOUNT_TYPE_COMMUNITY);
}
if ((DI::pConfig()->get($receiver, 'system', 'accept_only_sharer') == Item::COMPLETION_NONE)
&& ((!$is_forum && !($item['isForum'] ?? false) && ($activity['type'] != 'as:Announce'))
&& ((!$isGroup && !($item['isGroup'] ?? false) && ($activity['type'] != 'as:Announce'))
|| !Contact::isSharingByURL($activity['actor'], $receiver))) {
Logger::info('Actor is a non sharer, is no forum or it is no announce', ['uid' => $receiver, 'actor' => $activity['actor'], 'url' => $item['uri'], 'type' => $activity['type']]);
Logger::info('Actor is a non sharer, is no group or it is no announce', ['uid' => $receiver, 'actor' => $activity['actor'], 'url' => $item['uri'], 'type' => $activity['type']]);
continue;
}
@ -1141,7 +1141,7 @@ class Processor
// Store send a follow request for every reshare - but only when the item had been stored
if ($stored && ($item['private'] != Item::PRIVATE) && ($item['gravity'] == Item::GRAVITY_PARENT) && !empty($item['author-link']) && ($item['author-link'] != $item['owner-link'])) {
$author = APContact::getByURL($item['owner-link'], false);
// We send automatic follow requests for reshared messages. (We don't need though for forum posts)
// We send automatic follow requests for reshared messages. (We don't need though for group posts)
if ($author['type'] != 'Group') {
Logger::info('Send follow request', ['uri' => $item['uri'], 'stored' => $stored, 'to' => $item['author-link']]);
ActivityPub\Transmitter::sendFollowObject($item['uri'], $item['author-link']);

View file

@ -1098,7 +1098,7 @@ class Receiver
if (!empty($actor)) {
$profile = APContact::getByURL($actor);
$followers = $profile['followers'] ?? '';
$is_forum = ($profile['type'] ?? '') == 'Group';
$isGroup = ($profile['type'] ?? '') == 'Group';
if ($push) {
Contact::updateByUrlIfNeeded($actor);
}
@ -1106,7 +1106,7 @@ class Receiver
} else {
Logger::info('Empty actor', ['activity' => $activity]);
$followers = '';
$is_forum = false;
$isGroup = false;
}
// We have to prevent false follower assumptions upon thread completions
@ -1129,7 +1129,7 @@ class Receiver
}
// Fetch the receivers for the public and the followers collection
if ((($receiver == $followers) || (($receiver == self::PUBLIC_COLLECTION) && !$is_forum)) && !empty($actor)) {
if ((($receiver == $followers) || (($receiver == self::PUBLIC_COLLECTION) && !$isGroup)) && !empty($actor)) {
$receivers = self::getReceiverForActor($actor, $tags, $receivers, $follower_target, $profile);
continue;
}
@ -1148,7 +1148,7 @@ class Receiver
$condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
'network' => $networks, 'archive' => false, 'pending' => false, 'uid' => $contact['uid']];
// Forum posts are only accepted from forum contacts
// Group posts are only accepted from group contacts
if ($contact['contact-type'] == Contact::TYPE_COMMUNITY) {
$condition['rel'] = [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER];
}

View file

@ -492,13 +492,13 @@ class Transmitter
* Returns an array with permissions of the thread parent of the given item array
*
* @param array $item
* @param bool $is_forum_thread
* @param bool $is_group_thread
*
* @return array with permissions
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
private static function fetchPermissionBlockFromThreadParent(array $item, bool $is_forum_thread): array
private static function fetchPermissionBlockFromThreadParent(array $item, bool $is_group_thread): array
{
if (empty($item['thr-parent-id'])) {
return [];
@ -528,7 +528,7 @@ class Transmitter
$type = [Tag::TO => 'to', Tag::CC => 'cc', Tag::BTO => 'bto', Tag::BCC => 'bcc'];
foreach (Tag::getByURIId($item['thr-parent-id'], [Tag::TO, Tag::CC, Tag::BTO, Tag::BCC]) as $receiver) {
if (!empty($parent_profile['followers']) && $receiver['url'] == $parent_profile['followers'] && !empty($item_profile['followers'])) {
if (!$is_forum_thread) {
if (!$is_group_thread) {
$permissions[$type[$receiver['type']]][] = $item_profile['followers'];
}
} elseif (!in_array($receiver['url'], $exclude)) {
@ -573,7 +573,7 @@ class Transmitter
}
$always_bcc = false;
$is_forum = false;
$is_group = false;
$follower = '';
// Check if we should always deliver our stuff via BCC
@ -581,7 +581,7 @@ class Transmitter
$owner = User::getOwnerDataById($item['uid']);
if (!empty($owner)) {
$always_bcc = $owner['hide-friends'];
$is_forum = ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && $owner['manually-approve'];
$is_group = ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) && $owner['manually-approve'];
$profile = APContact::getByURL($owner['url'], false);
$follower = $profile['followers'] ?? '';
@ -595,9 +595,9 @@ class Transmitter
$parent = Post::selectFirst(['causer-link', 'post-reason'], ['id' => $item['parent']]);
if (!empty($parent) && ($parent['post-reason'] == Item::PR_ANNOUNCEMENT) && !empty($parent['causer-link'])) {
$profile = APContact::getByURL($parent['causer-link'], false);
$is_forum_thread = isset($profile['type']) && $profile['type'] == 'Group';
$is_group_thread = isset($profile['type']) && $profile['type'] == 'Group';
} else {
$is_forum_thread = false;
$is_group_thread = false;
}
if (self::isAnnounce($item) || self::isAPPost($last_id)) {
@ -619,7 +619,7 @@ class Transmitter
$exclusive = false;
$mention = false;
if ($is_forum_thread) {
if ($is_group_thread) {
foreach (Tag::getByURIId($item['parent-uri-id'], [Tag::MENTION, Tag::EXCLUSIVE_MENTION]) as $term) {
$profile = APContact::getByURL($term['url'], false);
if (!empty($profile) && ($profile['type'] == 'Group')) {
@ -644,7 +644,7 @@ class Transmitter
$data['cc'][] = $announce['actor']['url'];
}
$data = array_merge($data, self::fetchPermissionBlockFromThreadParent($item, $is_forum_thread));
$data = array_merge($data, self::fetchPermissionBlockFromThreadParent($item, $is_group_thread));
// Check if the item is completely public or unlisted
if ($item['private'] == Item::PUBLIC) {
@ -702,7 +702,7 @@ class Transmitter
$exclusive = false;
}
if ($is_forum && !$exclusive && !empty($follower)) {
if ($is_group && !$exclusive && !empty($follower)) {
$data['cc'][] = $follower;
} elseif (!$exclusive) {
foreach ($receiver_list as $receiver) {
@ -739,19 +739,19 @@ class Transmitter
$profile = APContact::getByURL($parent['owner-link'], false);
if (!empty($profile)) {
if ($item['gravity'] != Item::GRAVITY_PARENT) {
// Comments to forums are directed to the forum
// But comments to forums aren't directed to the followers collection
// This rule is only valid when the actor isn't the forum.
// The forum needs to transmit their content to their followers.
// Comments to groups are directed to the group
// But comments to groups aren't directed to the followers collection
// This rule is only valid when the actor isn't the group.
// The group needs to transmit their content to their followers.
if (($profile['type'] == 'Group') && ($profile['url'] != ($actor_profile['url'] ?? ''))) {
$data['to'][] = $profile['url'];
} else {
$data['cc'][] = $profile['url'];
if (($item['private'] != Item::PRIVATE) && !empty($actor_profile['followers']) && (!$exclusive || !$is_forum_thread)) {
if (($item['private'] != Item::PRIVATE) && !empty($actor_profile['followers']) && (!$exclusive || !$is_group_thread)) {
$data['cc'][] = $actor_profile['followers'];
}
}
} elseif (!$exclusive && !$is_forum_thread) {
} elseif (!$exclusive && !$is_group_thread) {
// Public thread parent post always are directed to the followers.
if ($item['private'] != Item::PRIVATE) {
$data['cc'][] = $actor_profile['followers'];
@ -885,12 +885,11 @@ class Transmitter
{
$inboxes = [];
$isforum = false;
$isGroup = false;
if (!empty($item['uid'])) {
$profile = User::getOwnerDataById($item['uid']);
if (!empty($profile)) {
$isforum = $profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY;
$isGroup = $profile['account-type'] == User::ACCOUNT_TYPE_COMMUNITY;
}
}
@ -920,7 +919,7 @@ class Transmitter
continue;
}
if ($isforum && ($contact['network'] == Protocol::DFRN)) {
if ($isGroup && ($contact['network'] == Protocol::DFRN)) {
continue;
}

View file

@ -2220,8 +2220,8 @@ class DFRN
GServer::setProtocol($importer['gsid'], Post\DeliveryData::DFRN);
}
// is it a public forum? Private forums aren't exposed with this method
$forum = intval(XML::getFirstNodeValue($xpath, '/atom:feed/dfrn:community/text()'));
// is it a public group? Private groups aren't exposed with this method
$group = intval(XML::getFirstNodeValue($xpath, '/atom:feed/dfrn:community/text()'));
// The account type is new since 3.5.1
if ($xpath->query('/atom:feed/dfrn:account_type')->length > 0) {
@ -2235,17 +2235,17 @@ class DFRN
// Updating the public contact as well
Contact::update(['contact-type' => $accounttype], ['uid' => 0, 'nurl' => $importer['nurl']]);
}
// A forum contact can either have set "forum" or "prv" - but not both
// A group contact can either have set "forum" or "prv" - but not both
if ($accounttype == User::ACCOUNT_TYPE_COMMUNITY) {
// It's a forum, so either set the public or private forum flag
$condition = ['(`forum` != ? OR `prv` != ?) AND `id` = ?', $forum, !$forum, $importer['id']];
Contact::update(['forum' => $forum, 'prv' => !$forum], $condition);
// It's a group, so either set the public or private forum flag
$condition = ['(`forum` != ? OR `prv` != ?) AND `id` = ?', $group, !$group, $importer['id']];
Contact::update(['forum' => $group, 'prv' => !$group], $condition);
// Updating the public contact as well
$condition = ['(`forum` != ? OR `prv` != ?) AND `uid` = 0 AND `nurl` = ?', $forum, !$forum, $importer['nurl']];
Contact::update(['forum' => $forum, 'prv' => !$forum], $condition);
$condition = ['(`forum` != ? OR `prv` != ?) AND `uid` = 0 AND `nurl` = ?', $group, !$group, $importer['nurl']];
Contact::update(['forum' => $group, 'prv' => !$group], $condition);
} else {
// It's not a forum, so remove the flags
// It's not a group, so remove the flags
$condition = ['(`forum` OR `prv`) AND `id` = ?', $importer['id']];
Contact::update(['forum' => false, 'prv' => false], $condition);
@ -2253,13 +2253,13 @@ class DFRN
$condition = ['(`forum` OR `prv`) AND `uid` = 0 AND `nurl` = ?', $importer['nurl']];
Contact::update(['forum' => false, 'prv' => false], $condition);
}
} elseif ($forum != $importer['forum']) { // Deprecated since 3.5.1
$condition = ['`forum` != ? AND `id` = ?', $forum, $importer['id']];
Contact::update(['forum' => $forum], $condition);
} elseif ($group != $importer['forum']) { // Deprecated since 3.5.1
$condition = ['`forum` != ? AND `id` = ?', $group, $importer['id']];
Contact::update(['forum' => $group], $condition);
// Updating the public contact as well
$condition = ['`forum` != ? AND `uid` = 0 AND `nurl` = ?', $forum, $importer['nurl']];
Contact::update(['forum' => $forum], $condition);
$condition = ['`forum` != ? AND `uid` = 0 AND `nurl` = ?', $group, $importer['nurl']];
Contact::update(['forum' => $group], $condition);
}

View file

@ -404,7 +404,7 @@ class Delivery
*/
private static function deliverDiaspora(string $cmd, array $contact, array $owner, array $items, array $target_item, bool $public_message, bool $top_level, bool $followup): bool
{
// We don't treat Forum posts as "wall-to-wall" to be able to post them via Diaspora
// We don't treat group posts as "wall-to-wall" to be able to post them via Diaspora
$walltowall = $top_level && ($owner['id'] != $items[0]['contact-id']) & ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY);
if ($public_message) {