Merge pull request #7399 from annando/only-sharer

Added the option to only receive top level posts from people you follow
This commit is contained in:
Hypolite Petovan 2019-07-17 20:53:28 -04:00 committed by GitHub
commit 9b927fa333
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 5 deletions

View file

@ -234,6 +234,7 @@ function settings_post(App $a)
BaseModule::checkFormSecurityTokenRedirectOnError('/settings/connectors', 'settings_connectors');
if (!empty($_POST['general-submit'])) {
PConfig::set(local_user(), 'system', 'accept_only_sharer', intval($_POST['accept_only_sharer']));
PConfig::set(local_user(), 'system', 'disable_cw', intval($_POST['disable_cw']));
PConfig::set(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening']));
PConfig::set(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow']));
@ -786,6 +787,7 @@ function settings_content(App $a)
}
if (($a->argc > 1) && ($a->argv[1] === 'connectors')) {
$accept_only_sharer = intval(PConfig::get(local_user(), 'system', 'accept_only_sharer'));
$disable_cw = intval(PConfig::get(local_user(), 'system', 'disable_cw'));
$no_intelligent_shortening = intval(PConfig::get(local_user(), 'system', 'no_intelligent_shortening'));
$ostatus_autofriend = intval(PConfig::get(local_user(), 'system', 'ostatus_autofriend'));
@ -844,6 +846,7 @@ function settings_content(App $a)
'$ostat_enabled' => $ostat_enabled,
'$general_settings' => L10n::t('General Social Media Settings'),
'$accept_only_sharer' => ['accept_only_sharer', L10n::t('Accept only top level posts by contacts you follow'), $accept_only_sharer, L10n::t('The system does an auto completion of threads when a comment arrives. This has got the side effect that can you receive posts that had been started by a non-follower but had been commented by someone you follow. This setting deactivates this behaviour. When activated, you strictly only will receive posts from people you really do follow.')],
'$disable_cw' => ['disable_cw', L10n::t('Disable Content Warning'), $disable_cw, L10n::t('Users on networks like Mastodon or Pleroma are able to set a content warning field which collapse their post by default. This disables the automatic collapsing and sets the content warning as the post title. Doesn\'t affect any other content filtering you eventually set up.')],
'$no_intelligent_shortening' => ['no_intelligent_shortening', L10n::t('Disable intelligent shortening'), $no_intelligent_shortening, L10n::t('Normally the system tries to find the best link to add to shortened posts. If this option is enabled then every shortened post will always point to the original friendica post.')],
'$ostatus_autofriend' => ['snautofollow', L10n::t("Automatically follow any GNU Social \x28OStatus\x29 followers/mentioners"), $ostatus_autofriend, L10n::t('If you receive a message from an unknown OStatus user, this option decides what to do. If it is checked, a new contact will be created for every unknown user.')],

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 {

View file

@ -11,6 +11,7 @@
<div id="settings_general_expanded" class="settings-block" style="display: none;">
{{include file="field_checkbox.tpl" field=$accept_only_sharer}}
{{include file="field_checkbox.tpl" field=$disable_cw}}
{{include file="field_checkbox.tpl" field=$no_intelligent_shortening}}
{{include file="field_checkbox.tpl" field=$ostatus_autofriend}}

View file

@ -20,6 +20,8 @@
<div id="content-settings-content" class="panel-collapse collapse" role="tabpanel" aria-labelledby="content-settings">
<div class="section-content-wrapper">
{{include file="field_checkbox.tpl" field=$accept_only_sharer}}
{{include file="field_checkbox.tpl" field=$disable_cw}}
{{include file="field_checkbox.tpl" field=$no_intelligent_shortening}}