mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +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));
|
$this->Plugins()->RunHook('json.suggestions-input-parameters', array(&$sQuery, &$iLimit, $oAccount));
|
||||||
|
|
||||||
$iLimit = \max(5, (int) $iLimit);
|
|
||||||
|
|
||||||
$aResult = array();
|
$aResult = array();
|
||||||
|
|
||||||
if (\strlen($sQuery)) {
|
if ($oSuggestionsProvider = $this->SuggestionsProvider()) {
|
||||||
try
|
$aResult = $oSuggestionsProvider->Process($oAccount, $sQuery, $iLimit);
|
||||||
{
|
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->DefaultResponse($aResult);
|
return $this->DefaultResponse($aResult);
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
|
||||||
/**
|
/**
|
||||||
* @var \RainLoop\Providers\Suggestions\ISuggestions[]
|
* @var \RainLoop\Providers\Suggestions\ISuggestions[]
|
||||||
*/
|
*/
|
||||||
private ?array $aDrivers;
|
private array $aDrivers = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \RainLoop\Providers\Suggestions\ISuggestions[]|null $aDriver = null
|
* @param \RainLoop\Providers\Suggestions\ISuggestions[]|null $aDriver = null
|
||||||
|
|
@ -15,44 +15,67 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
|
||||||
public function __construct(?array $aDriver = null)
|
public function __construct(?array $aDriver = null)
|
||||||
{
|
{
|
||||||
if (\is_array($aDriver)) {
|
if (\is_array($aDriver)) {
|
||||||
$aDriver = \array_filter($aDriver, function ($oDriver) {
|
$this->aDrivers = \array_filter($aDriver, function ($oDriver) {
|
||||||
return $oDriver instanceof \RainLoop\Providers\Suggestions\ISuggestions;
|
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
|
public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20) : array
|
||||||
{
|
{
|
||||||
$aResult = array();
|
if (!\strlen($sQuery)) {
|
||||||
if (\strlen($sQuery) && $this->IsActive()) {
|
return [];
|
||||||
foreach ($this->aDrivers as $oDriver) {
|
}
|
||||||
if ($oDriver) try {
|
|
||||||
$aSubs = $oDriver->Process($oAccount, $sQuery, $iLimit);
|
$iLimit = \max(5, (int) $iLimit);
|
||||||
if ($aSubs) {
|
$aResult = [];
|
||||||
foreach ($aSubs as $aItem) {
|
|
||||||
// Unique email address
|
// Address Book
|
||||||
$sLine = \mb_strtolower($aItem[0]);
|
try
|
||||||
if (!isset($aResult[$sLine])) {
|
{
|
||||||
$aResult[$sLine] = $aItem;
|
$oAddressBookProvider = \RainLoop\Api::Actions()->AddressBookProvider($oAccount);
|
||||||
}
|
if ($oAddressBookProvider && $oAddressBookProvider->IsActive()) {
|
||||||
}
|
$aSuggestions = $oAddressBookProvider->GetSuggestions($sQuery, $iLimit);
|
||||||
if ($iLimit < \count($aResult)) {
|
foreach ($aSuggestions as $aItem) {
|
||||||
break;
|
// 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
|
public function IsActive() : bool
|
||||||
{
|
{
|
||||||
return \is_array($this->aDrivers) && \count($this->aDrivers);
|
return \count($this->aDrivers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label data-i18n="TAB_CONTACTS/SUGGESTIONS_LIMIT"></label>
|
<label data-i18n="TAB_CONTACTS/SUGGESTIONS_LIMIT"></label>
|
||||||
<div>
|
<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>
|
<span data-bind="saveTrigger: contactsSuggestionsLimitTrigger"></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue