Merge pull request #9604 from annando/remote-self-reshare

New "remote self" option: Native Reshare
This commit is contained in:
Hypolite Petovan 2020-11-28 22:40:06 -05:00 committed by GitHub
commit dd4a656dec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 6 deletions

View file

@ -139,7 +139,12 @@ class Contact
* @}
*/
/**
const MIRROR_DEACTIVATED = 0;
const MIRROR_FORWARDED = 1;
const MIRROR_OWN_POST = 2;
const MIRROR_NATIVE_RESHARE = 3;
/**
* @param array $fields Array of selected fields, empty for all
* @param array $condition Array of fields for condition
* @param array $params Array of several parameters

View file

@ -1181,7 +1181,7 @@ class Item
}
// Is it our comment and/or our thread?
if ($item['origin'] || $parent['origin']) {
if (($item['origin'] || $parent['origin']) && ($item['uid'] != 0)) {
// When we delete the original post we will delete all existing copies on the server as well
self::markForDeletion(['uri' => $item['uri'], 'deleted' => false], $priority);
@ -1979,6 +1979,9 @@ class Item
// Distribute items to users who subscribed to their tags
self::distributeByTags($item);
// Automatically reshare the item if the "remote_self" option is selected
self::autoReshare($item);
$transmit = $notify || ($item['visible'] && ($parent_origin || $item['origin']));
if ($transmit) {
@ -2783,6 +2786,31 @@ class Item
return false;
}
/**
* Automatically reshare the item if the "remote_self" option is selected
*
* @param array $item
* @return void
*/
private static function autoReshare(array $item)
{
if ($item['gravity'] != GRAVITY_PARENT) {
return;
}
if (!DBA::exists('contact', ['id' => $item['contact-id'], 'remote_self' => Contact::MIRROR_NATIVE_RESHARE])) {
return;
}
if (!in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) {
return;
}
Logger::info('Automatically reshare item', ['uid' => $item['uid'], 'id' => $item['id'], 'guid' => $item['guid'], 'uri-id' => $item['uri-id']]);
Item::performActivity($item['id'], 'announce', $item['uid']);
}
public static function isRemoteSelf($contact, &$datarray)
{
if (!$contact['remote_self']) {
@ -2814,7 +2842,7 @@ class Item
$datarray2 = $datarray;
Logger::info('remote-self start', ['contact' => $contact['url'], 'remote_self'=> $contact['remote_self'], 'item' => $datarray]);
if ($contact['remote_self'] == 2) {
if ($contact['remote_self'] == Contact::MIRROR_OWN_POST) {
$self = DBA::selectFirst('contact', ['id', 'name', 'url', 'thumb'],
['uid' => $contact['uid'], 'self' => true]);
if (DBA::isResult($self)) {

View file

@ -560,13 +560,23 @@ class Contact extends BaseModule
// Disable remote self for everything except feeds.
// There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
// Problem is, you couldn't reply to both networks.
$allow_remote_self = in_array($contact['network'], [Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])
$allow_remote_self = in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::FEED, Protocol::DFRN, Protocol::DIASPORA, Protocol::TWITTER])
&& DI::config()->get('system', 'allow_users_remote_self');
if ($contact['network'] == Protocol::FEED) {
$remote_self_options = ['0' => DI::l10n()->t('No mirroring'), '1' => DI::l10n()->t('Mirror as forwarded posting'), '2' => DI::l10n()->t('Mirror as my own posting')];
$remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
Model\Contact::MIRROR_FORWARDED => DI::l10n()->t('Mirror as forwarded posting'),
Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting')];
} elseif (in_array($contact['network'], [Protocol::ACTIVITYPUB])) {
$remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
Model\Contact::MIRROR_NATIVE_RESHARE => DI::l10n()->t('Native reshare')];
} elseif (in_array($contact['network'], [Protocol::DFRN])) {
$remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting'),
Model\Contact::MIRROR_NATIVE_RESHARE => DI::l10n()->t('Native reshare')];
} else {
$remote_self_options = ['0' => DI::l10n()->t('No mirroring'), '2' => DI::l10n()->t('Mirror as my own posting')];
$remote_self_options = [Model\Contact::MIRROR_DEACTIVATED => DI::l10n()->t('No mirroring'),
Model\Contact::MIRROR_OWN_POST => DI::l10n()->t('Mirror as my own posting')];
}
$poll_interval = null;