Extract hasRestrictions() into ItemInserter
This commit is contained in:
parent
3c51af78a2
commit
0e054cd4a0
2 changed files with 31 additions and 30 deletions
|
@ -757,7 +757,7 @@ class Item
|
|||
* @return array item array with parent data
|
||||
* @throws \Exception
|
||||
*/
|
||||
private static function getTopLevelParent(array $item): array
|
||||
private static function getTopLevelParent(array $item, ItemInserter $itemInserter): array
|
||||
{
|
||||
$fields = [
|
||||
'uid', 'uri', 'parent-uri', 'id', 'deleted',
|
||||
|
@ -785,7 +785,7 @@ class Item
|
|||
return [];
|
||||
}
|
||||
|
||||
if (self::hasRestrictions($item, $parent['author-id'], $parent['restrictions'])) {
|
||||
if ($itemInserter->hasRestrictions($item, $parent['author-id'], $parent['restrictions'])) {
|
||||
DI::logger()->notice('Restrictions apply - ignoring item', ['restrictions' => $parent['restrictions'], 'verb' => $parent['verb'], 'uri-id' => $item['uri-id'], 'thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
|
||||
return [];
|
||||
}
|
||||
|
@ -916,7 +916,7 @@ class Item
|
|||
}
|
||||
|
||||
if ($item['gravity'] !== self::GRAVITY_PARENT) {
|
||||
$toplevel_parent = self::getTopLevelParent($item);
|
||||
$toplevel_parent = self::getTopLevelParent($item, $itemInserter);
|
||||
if (empty($toplevel_parent)) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -1390,33 +1390,6 @@ class Item
|
|||
return $item;
|
||||
}
|
||||
|
||||
private static function hasRestrictions(array $item, int $author_id, int $restrictions = null): bool
|
||||
{
|
||||
if (empty($restrictions) || ($author_id == $item['author-id'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We only have to apply restrictions if the post originates from our server or is federated.
|
||||
// Every other time we can trust the remote system.
|
||||
if (!in_array($item['network'], Protocol::FEDERATED) && !$item['origin']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($restrictions & self::CANT_REPLY) && ($item['verb'] == Activity::POST)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (($restrictions & self::CANT_ANNOUNCE) && ($item['verb'] == Activity::ANNOUNCE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (($restrictions & self::CANT_LIKE) && in_array($item['verb'], [Activity::LIKE, Activity::DISLIKE, Activity::ATTEND, Activity::ATTENDMAYBE, Activity::ATTENDNO])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static function reshareChannelPost(int $uri_id, int $reshare_id = 0)
|
||||
{
|
||||
if (!DI::config()->get('system', 'allow_relay_channels')) {
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Friendica\Model;
|
|||
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\Content\Item as ItemContent;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
@ -147,6 +148,33 @@ final class ItemInserter
|
|||
return $item;
|
||||
}
|
||||
|
||||
public function hasRestrictions(array $item, int $author_id, int $restrictions = null): bool
|
||||
{
|
||||
if (empty($restrictions) || ($author_id == $item['author-id'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// We only have to apply restrictions if the post originates from our server or is federated.
|
||||
// Every other time we can trust the remote system.
|
||||
if (!in_array($item['network'], Protocol::FEDERATED) && !$item['origin']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (($restrictions & Item::CANT_REPLY) && ($item['verb'] == Activity::POST)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (($restrictions & Item::CANT_ANNOUNCE) && ($item['verb'] == Activity::ANNOUNCE)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (($restrictions & Item::CANT_LIKE) && in_array($item['verb'], [Activity::LIKE, Activity::DISLIKE, Activity::ATTEND, Activity::ATTENDMAYBE, Activity::ATTENDNO])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the gravity for the given item array
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue