Make #879 optional

This commit is contained in:
the-djmaze 2023-01-26 22:53:12 +01:00
parent dc6674af4a
commit 82a1f4d781
2 changed files with 19 additions and 4 deletions

View file

@ -7,6 +7,13 @@ class NextcloudContactsSuggestions implements \RainLoop\Providers\Suggestions\IS
*/ */
private $oLogger = null; private $oLogger = null;
private bool $ignoreSystemAddressbook;
function __construct(bool $ignoreSystemAddressbook = true)
{
$this->ignoreSystemAddressbook = $ignoreSystemAddressbook;
}
public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20): array public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20): array
{ {
try try
@ -22,11 +29,14 @@ class NextcloudContactsSuggestions implements \RainLoop\Providers\Suggestions\IS
} }
// Unregister system addressbook so as to return only contacts in user's addressbooks // Unregister system addressbook so as to return only contacts in user's addressbooks
if ($this->ignoreSystemAddressbook) {
foreach($cm->getUserAddressBooks() as $addressBook) { foreach($cm->getUserAddressBooks() as $addressBook) {
if($addressBook->isSystemAddressBook()) { if($addressBook->isSystemAddressBook()) {
$cm->unregisterAddressBook($addressBook); $cm->unregisterAddressBook($addressBook);
} }
} }
}
$aSearchResult = $cm->search($sQuery, array('FN', 'NICKNAME', 'TITLE', 'EMAIL')); $aSearchResult = $cm->search($sQuery, array('FN', 'NICKNAME', 'TITLE', 'EMAIL'));
//$this->oLogger->WriteDump($aSearchResult); //$this->oLogger->WriteDump($aSearchResult);

View file

@ -202,7 +202,9 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
$mResult = array(); $mResult = array();
} }
include_once __DIR__ . '/NextcloudContactsSuggestions.php'; include_once __DIR__ . '/NextcloudContactsSuggestions.php';
$mResult[] = new NextcloudContactsSuggestions(); $mResult[] = new NextcloudContactsSuggestions(
$this->Config()->Get('plugin', 'ignoreSystemAddressbook', true)
);
} }
} }
} }
@ -213,6 +215,9 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
\RainLoop\Plugins\Property::NewInstance('suggestions')->SetLabel('Suggestions') \RainLoop\Plugins\Property::NewInstance('suggestions')->SetLabel('Suggestions')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetDefaultValue(true), ->SetDefaultValue(true),
\RainLoop\Plugins\Property::NewInstance('ignoreSystemAddressbook')->SetLabel('Ignore system addressbook')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetDefaultValue(true),
\RainLoop\Plugins\Property::NewInstance('calendar')->SetLabel('Enable "Put ICS in calendar"') \RainLoop\Plugins\Property::NewInstance('calendar')->SetLabel('Enable "Put ICS in calendar"')
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
->SetDefaultValue(false) ->SetDefaultValue(false)