mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-08 22:18:28 +03:00
Improved contacts suggestions limit handling #849
This commit is contained in:
parent
51f250cc78
commit
d41f9d8eee
3 changed files with 50 additions and 61 deletions
|
|
@ -236,44 +236,10 @@ trait User
|
|||
|
||||
$this->Plugins()->RunHook('json.suggestions-input-parameters', array(&$sQuery, &$iLimit, $oAccount));
|
||||
|
||||
$iLimit = \max(5, (int) $iLimit);
|
||||
|
||||
$aResult = array();
|
||||
|
||||
if (\strlen($sQuery)) {
|
||||
try
|
||||
{
|
||||
// Address Book
|
||||
$oAddressBookProvider = $this->AddressBookProvider($oAccount);
|
||||
if ($oAddressBookProvider && $oAddressBookProvider->IsActive()) {
|
||||
$aSuggestions = $oAddressBookProvider->GetSuggestions($sQuery, $iLimit);
|
||||
foreach ($aSuggestions as $aItem) {
|
||||
// Unique email address
|
||||
$sLine = \mb_strtolower($aItem[0]);
|
||||
if (!isset($aResult[$sLine])) {
|
||||
$aResult[$sLine] = $aItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
$this->Logger()->WriteException($oException);
|
||||
}
|
||||
|
||||
if ($iLimit > \count($aResult)) {
|
||||
$oSuggestionsProvider = $this->SuggestionsProvider();
|
||||
if ($oSuggestionsProvider && $oSuggestionsProvider->IsActive()) {
|
||||
$aSuggestions = $oSuggestionsProvider->Process($oAccount, $sQuery, $iLimit);
|
||||
foreach ($aSuggestions as $sLine => $aItem) {
|
||||
if (!isset($aResult[$sLine])) {
|
||||
$aResult[$sLine] = $aItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aResult = \array_slice(\array_values($aResult), 0, $iLimit);
|
||||
if ($oSuggestionsProvider = $this->SuggestionsProvider()) {
|
||||
$aResult = $oSuggestionsProvider->Process($oAccount, $sQuery, $iLimit);
|
||||
}
|
||||
|
||||
return $this->DefaultResponse($aResult);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
|
|||
/**
|
||||
* @var \RainLoop\Providers\Suggestions\ISuggestions[]
|
||||
*/
|
||||
private ?array $aDrivers;
|
||||
private array $aDrivers = [];
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Providers\Suggestions\ISuggestions[]|null $aDriver = null
|
||||
|
|
@ -15,44 +15,67 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
|
|||
public function __construct(?array $aDriver = null)
|
||||
{
|
||||
if (\is_array($aDriver)) {
|
||||
$aDriver = \array_filter($aDriver, function ($oDriver) {
|
||||
$this->aDrivers = \array_filter($aDriver, function ($oDriver) {
|
||||
return $oDriver instanceof \RainLoop\Providers\Suggestions\ISuggestions;
|
||||
});
|
||||
}
|
||||
|
||||
$this->aDrivers = \is_array($aDriver) && \count($aDriver) ? $aDriver : null;
|
||||
}
|
||||
|
||||
public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20) : array
|
||||
{
|
||||
$aResult = array();
|
||||
if (\strlen($sQuery) && $this->IsActive()) {
|
||||
foreach ($this->aDrivers as $oDriver) {
|
||||
if ($oDriver) try {
|
||||
$aSubs = $oDriver->Process($oAccount, $sQuery, $iLimit);
|
||||
if ($aSubs) {
|
||||
foreach ($aSubs as $aItem) {
|
||||
// Unique email address
|
||||
$sLine = \mb_strtolower($aItem[0]);
|
||||
if (!isset($aResult[$sLine])) {
|
||||
$aResult[$sLine] = $aItem;
|
||||
}
|
||||
}
|
||||
if ($iLimit < \count($aResult)) {
|
||||
break;
|
||||
}
|
||||
if (!\strlen($sQuery)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$iLimit = \max(5, (int) $iLimit);
|
||||
$aResult = [];
|
||||
|
||||
// Address Book
|
||||
try
|
||||
{
|
||||
$oAddressBookProvider = \RainLoop\Api::Actions()->AddressBookProvider($oAccount);
|
||||
if ($oAddressBookProvider && $oAddressBookProvider->IsActive()) {
|
||||
$aSuggestions = $oAddressBookProvider->GetSuggestions($sQuery, $iLimit);
|
||||
foreach ($aSuggestions as $aItem) {
|
||||
// Unique email address
|
||||
$sLine = \mb_strtolower($aItem[0]);
|
||||
if (!isset($aResult[$sLine])) {
|
||||
$aResult[$sLine] = $aItem;
|
||||
}
|
||||
} catch (\Throwable $oException) {
|
||||
$this->oLogger && $this->oLogger->WriteException($oException);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
$this->oLogger && $this->oLogger->WriteException($oException);
|
||||
}
|
||||
|
||||
return \array_slice($aResult, 0, $iLimit);
|
||||
// Extensions/Plugins
|
||||
foreach ($this->aDrivers as $oDriver) {
|
||||
if ($oDriver) try {
|
||||
$aSuggestions = $oDriver->Process($oAccount, $sQuery, $iLimit);
|
||||
if ($aSuggestions) {
|
||||
foreach ($aSuggestions as $aItem) {
|
||||
// Unique email address
|
||||
$sLine = \mb_strtolower($aItem[0]);
|
||||
if (!isset($aResult[$sLine])) {
|
||||
$aResult[$sLine] = $aItem;
|
||||
}
|
||||
}
|
||||
if ($iLimit < \count($aResult)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $oException) {
|
||||
$this->oLogger && $this->oLogger->WriteException($oException);
|
||||
}
|
||||
}
|
||||
|
||||
return \array_slice(\array_values($aResult), 0, $iLimit);
|
||||
}
|
||||
|
||||
public function IsActive() : bool
|
||||
{
|
||||
return \is_array($this->aDrivers) && \count($this->aDrivers);
|
||||
return \count($this->aDrivers);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
<div class="control-group">
|
||||
<label data-i18n="TAB_CONTACTS/SUGGESTIONS_LIMIT"></label>
|
||||
<div>
|
||||
<input type="number" min="10" max="50" step="1" class="span1" data-bind="textInput: contactsSuggestionsLimit">
|
||||
<input type="number" min="5" max="50" step="1" class="span1" data-bind="textInput: contactsSuggestionsLimit">
|
||||
|
||||
<span data-bind="saveTrigger: contactsSuggestionsLimitTrigger"></span>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue