[TheFreeNetwork] Use config + module settings for initialization and online lookup

The Census event is now replaced with module settings for populating the
protocols array. With this we can shutdown some plugins and still make
them be checked by TFN.

The performance:high config is now added when deciding whether or not to
do online lookup after the offline lookup fails.

default:
- Add default values for the TFN protocol setting

EVENTS:
- Remove Cencus event

TheFreeNetworkModule
- Remove Census event handler, update protocols array to use module's settings
- Use performance:high config when deciding to do online lookup
This commit is contained in:
tenma 2020-04-07 02:36:50 +01:00 committed by Diogo Cordeiro
parent cfba91ea43
commit 01dcaefcfb
3 changed files with 20 additions and 16 deletions

View File

@ -337,7 +337,9 @@ $default =
'Favorite' => [],
'HTMLPurifierSchemes' => [],
'Share' => [],
'TheFreeNetwork' => [],
'TheFreeNetwork' => [
'protocols' => ['ActivityPub' => 'Activitypub_profile', 'OStatus' => 'Ostatus_profile']
],
],
'default' => [
'AccountManager' => [],

View File

@ -1,6 +1,3 @@
StartTFNCensus: when all plugins have been initialized; federation plugins must populate this event's array with their profile class name
@param array $free_network
StartTFNLookup: tries to locate a duplicated remote profile by URI; federation plugins must trigger this event before profile insertion
@param string $uri URI of the remote profile to be inserted
@param string $class profile class of the federation protocol that triggered the event

View File

@ -41,23 +41,27 @@ class TheFreeNetworkModule extends Module
{
const MODULE_VERSION = '0.1.0alpha0';
private $free_network = []; // name of the profile classes of the active federation protocols
private $lrdd = false; // whether LRDD plugin is active or not
public $protocols = null; // protocols TFN should handle
private $lrdd = false; // whether LRDD plugin is active or not
/**
* Called when all plugins have been initialized
* We'll populate our variables here
* Initialize TFN
*
* @return bool hook value
*/
public function onInitializePlugin(): bool
{
// $free_network array
Event::handle('StartTFNCensus', [&$this->free_network]);
// some protocol plugins can be unactivated,
// require needed classes
$plugin_dir = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins';
foreach ($this->protocols as $protocol => $class) {
require_once $plugin_dir . DIRECTORY_SEPARATOR . $protocol . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $class . '.php';
}
// $lrdd flag
$this->lrdd = PluginList::isPluginActive("LRDD");
$this->log(LOG_INFO, 'LRDD IS ' . ($this->lrdd ? 'ON' : 'OFF'));
return true;
}
@ -75,13 +79,14 @@ class TheFreeNetworkModule extends Module
{
$profile_id = $this->lookup($uri, $class);
if ($profile_id == null && $this->lrdd) {
$perf = common_config('performance', 'high');
if (is_null($profile_id) && !$perf && $this->lrdd) {
// Force lookup with online resources
// TODO: Add settings to control whether we do this or not
$profile_id = $this->lookup($uri, $class, true);
}
return ($profile_id == null);
return is_null($profile_id);
}
/**
@ -94,7 +99,7 @@ class TheFreeNetworkModule extends Module
*/
public function onEndTFNLookup(string $class, int $profile_id): bool
{
foreach ($this->free_network as $cls) {
foreach ($this->protocols as $p => $cls) {
if ($cls != $class) {
$profile = $cls::getKV('profile_id', $profile_id);
if ($profile instanceof $cls) {
@ -156,7 +161,7 @@ class TheFreeNetworkModule extends Module
return null;
}
foreach ($this->free_network as $cls) {
foreach ($this->protocols as $p => $cls) {
if ($cls != $class) {
foreach ($all_ids as $alias) {
$profile = $cls::getKV('uri', $alias);