Added the option to only receive top level posts from people you follow

This commit is contained in:
Michael 2019-07-17 21:37:13 +00:00
parent a80a6bec74
commit e247a14d2b
6 changed files with 89 additions and 5 deletions

View file

@ -174,6 +174,73 @@ class Contact extends BaseObject
return DBA::exists('contact', $condition);
}
/**
* @brief Tests if the given contact url is a follower
*
* @param string $url Contact URL
* @param int $uid User ID
*
* @return boolean is the contact id a follower?
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function isFollowerByURL($url, $uid)
{
$cid = self::getIdForURL($url, $uid, true);
if (empty($cid)) {
return false;
}
return self::isFollower($cid, $uid);
}
/**
* @brief Tests if the given user follow the given contact
*
* @param int $cid Either public contact id or user's contact id
* @param int $uid User ID
*
* @return boolean is the contact url being followed?
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function isSharing($cid, $uid)
{
if (self::isBlockedByUser($cid, $uid)) {
return false;
}
$cdata = self::getPublicAndUserContacID($cid, $uid);
if (empty($cdata['user'])) {
return false;
}
$condition = ['id' => $cdata['user'], 'rel' => [self::SHARING, self::FRIEND]];
return DBA::exists('contact', $condition);
}
/**
* @brief Tests if the given user follow the given contact url
*
* @param string $url Contact URL
* @param int $uid User ID
*
* @return boolean is the contact url being followed?
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function isSharingByURL($url, $uid)
{
$cid = self::getIdForURL($url, $uid, true);
if (empty($cid)) {
return false;
}
return self::isSharing($cid, $uid);
}
/**
* @brief Get the basepath for a given contact link
*

View file

@ -627,7 +627,7 @@ class Site extends BaseAdminModule
'$community_page_style' => ['community_page_style', L10n::t('Community pages for visitors'), Config::get('system', 'community_page_style'), L10n::t('Which community pages should be available for visitors. Local users always see both pages.'), $community_page_style_choices],
'$max_author_posts_community_page' => ['max_author_posts_community_page', L10n::t('Posts per user on community page'), Config::get('system', 'max_author_posts_community_page'), L10n::t('The maximum number of posts per user on the community page. (Not valid for "Global Community")')],
'$ostatus_disabled' => ['ostatus_disabled', L10n::t('Disable OStatus support'), Config::get('system', 'ostatus_disabled'), L10n::t('Disable built-in OStatus (StatusNet, GNU Social etc.) compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.')],
'$ostatus_full_threads' => ['ostatus_full_threads', L10n::t('Only import OStatus/ActivityPub threads from our contacts'), Config::get('system', 'ostatus_full_threads'), L10n::t('Normally we import every content from our OStatus and ActivityPub contacts. With this option we only store threads that are started by a contact that is known on our system.')],
'$ostatus_full_threads' => ['ostatus_full_threads', L10n::t('Only import OStatus threads from our contacts'), Config::get('system', 'ostatus_full_threads'), L10n::t('Normally we import every content from our OStatus contacts. With this option we only store threads that are started by a contact that is known on our system.')],
'$ostatus_not_able' => L10n::t('OStatus support can only be enabled if threading is enabled.'),
'$diaspora_able' => $diaspora_able,
'$diaspora_not_able' => L10n::t('Diaspora support can\'t be enabled because Friendica was installed into a sub directory.'),

View file

@ -425,6 +425,21 @@ class Processor
continue;
}
if (PConfig::get($receiver, 'system', 'accept_only_sharer', false) && ($receiver != 0) && ($item['gravity'] == GRAVITY_PARENT)) {
$skip = !Contact::isSharingByURL($activity['author'], $receiver);
if ($skip && (($activity['type'] == 'as:Announce') || $isForum)) {
$skip = !Contact::isSharingByURL($activity['actor'], $receiver);
}
if ($skip) {
Logger::info('Skipping post', ['uid' => $receiver, 'url' => $item['uri']]);
continue;
}
Logger::info('Accepting post', ['uid' => $receiver, 'url' => $item['uri']]);
}
if ($activity['object_type'] == 'as:Event') {
self::createEvent($activity, $item);
}
@ -524,10 +539,6 @@ class Processor
*/
public static function fetchMissingActivity($url, $child = [])
{
if (Config::get('system', 'ostatus_full_threads')) {
return;
}
if (!empty($child['receiver'])) {
$uid = ActivityPub\Receiver::getFirstUserFromReceivers($child['receiver']);
} else {