Mode depending control for the behaviour with blocked contacts

This commit is contained in:
Michael 2023-01-12 06:25:55 +00:00
parent ec54b303c5
commit f542211189
14 changed files with 100 additions and 85 deletions

View file

@ -23,6 +23,7 @@ namespace Friendica\Model;
use Friendica\Contact\Avatar;
use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException;
use Friendica\Content\Conversation;
use Friendica\Content\Pager;
use Friendica\Content\Text\HTML;
use Friendica\Core\Hook;
@ -1609,7 +1610,7 @@ class Contact
}
}
$o .= DI::conversation()->create($items, 'contacts', $update, false, 'pinned_commented', DI::userSession()->getLocalUserId());
$o .= DI::conversation()->create($items, Conversation::MODE_CONTACTS, $update, false, 'pinned_commented', DI::userSession()->getLocalUserId());
} else {
$fields = array_merge(Item::DISPLAY_FIELDLIST, ['featured']);
$items = Post::toArray(Post::selectForUser(DI::userSession()->getLocalUserId(), $fields, $condition, $params));
@ -1624,7 +1625,7 @@ class Contact
}
}
$o .= DI::conversation()->create($items, 'contact-posts', $update);
$o .= DI::conversation()->create($items, Conversation::MODE_CONTACT_POSTS, $update);
}
if (!$update) {

View file

@ -623,10 +623,6 @@ class Item
return false;
}
if (!empty($item['uid']) && !self::isAllowedByUser($item, $item['uid'])) {
return false;
}
if ($item['verb'] == Activity::FOLLOW) {
if (!$item['origin'] && ($item['author-id'] == Contact::getPublicIdByUserId($item['uid']))) {
// Our own follow request can be relayed to us. We don't store it to avoid notification chaos.
@ -988,13 +984,6 @@ class Item
return 0;
}
// If the thread originated from this node, we check the permission against the thread starter
$condition = ['uri-id' => $toplevel_parent['uri-id'], 'wall' => true];
$localTopLevelParent = Post::selectFirst(['uid'], $condition);
if (!empty($localTopLevelParent['uid']) && !self::isAllowedByUser($item, $localTopLevelParent['uid'])) {
return 0;
}
$parent_id = $toplevel_parent['id'];
$item['parent-uri'] = $toplevel_parent['uri'];
$item['parent-uri-id'] = $toplevel_parent['uri-id'];
@ -3065,7 +3054,11 @@ class Item
// Compile eventual content filter reasons
$filter_reasons = [];
if (!$is_preview && DI::userSession()->getPublicContactId() != $item['author-id']) {
if (Contact\User::isCollapsed($item['author-id'], $item['uid'])) {
if (!empty($item['user-blocked-author']) || !empty($item['user-blocked-owner'])) {
$filter_reasons[] = DI::l10n()->t('%s is blocked', $item['author-name']);
} elseif (!empty($item['user-ignored-author']) || !empty($item['user-ignored-owner'])) {
$filter_reasons[] = DI::l10n()->t('%s is ignored', $item['author-name']);
} elseif (!empty($item['user-collapsed-author']) || !empty($item['user-collapsed-owner'])) {
$filter_reasons[] = DI::l10n()->t('Content from %s is collapsed', $item['author-name']);
}
@ -3706,53 +3699,6 @@ class Item
return 0;
}
/**
* Check a prospective item array against user-level permissions
*
* @param array $item Expected keys: uri, gravity, and
* author-link if is author-id is set,
* owner-link if is owner-id is set,
* causer-link if is causer-id is set.
* @param int $user_id Local user ID
* @return bool
* @throws \Exception
*/
protected static function isAllowedByUser(array $item, int $user_id): bool
{
if (!empty($item['author-id']) && Contact\User::isBlocked($item['author-id'], $user_id)) {
Logger::notice('Author is blocked by user', ['author-link' => $item['author-link'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
return false;
}
if (!empty($item['owner-id']) && Contact\User::isBlocked($item['owner-id'], $user_id)) {
Logger::notice('Owner is blocked by user', ['owner-link' => $item['owner-link'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
return false;
}
// The causer is set during a thread completion, for example because of a reshare. It countains the responsible actor.
if (!empty($item['causer-id']) && Contact\User::isBlocked($item['causer-id'], $user_id)) {
Logger::notice('Causer is blocked by user', ['causer-link' => $item['causer-link'] ?? $item['causer-id'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
return false;
}
if (!empty($item['author-id']) && Contact\User::isIgnored($item['author-id'], $user_id)) {
Logger::notice('Author is ignored by user', ['author-link' => $item['author-link'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
return false;
}
if (!empty($item['owner-id']) && Contact\User::isIgnored($item['owner-id'], $user_id)) {
Logger::notice('Owner is ignored by user', ['owner-link' => $item['owner-link'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
return false;
}
if (!empty($item['causer-id']) && Contact\User::isIgnored($item['causer-id'], $user_id)) {
Logger::notice('Causer is ignored by user', ['causer-link' => $item['causer-link'] ?? $item['causer-id'], 'uid' => $user_id, 'item-uri' => $item['uri']]);
return false;
}
return true;
}
/**
* Fetch the uri-id of a quote
*