mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Reduce amount of avatar requests based on config settings
This commit is contained in:
parent
60b72ed981
commit
c27e231f53
2 changed files with 51 additions and 30 deletions
|
|
@ -67,8 +67,10 @@
|
||||||
),
|
),
|
||||||
addQueue = (msg, fn) => {
|
addQueue = (msg, fn) => {
|
||||||
setIdenticon(msg.from[0], fn);
|
setIdenticon(msg.from[0], fn);
|
||||||
queue.push([msg, fn]);
|
if (rl.pluginSettingsGet('avatars', 'delay')) {
|
||||||
runQueue();
|
queue.push([msg, fn]);
|
||||||
|
runQueue();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
runQueue = (() => {
|
runQueue = (() => {
|
||||||
let item = queue.shift();
|
let item = queue.shift();
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ class AvatarsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
NAME = 'Avatars',
|
NAME = 'Avatars',
|
||||||
AUTHOR = 'SnappyMail',
|
AUTHOR = 'SnappyMail',
|
||||||
URL = 'https://snappymail.eu/',
|
URL = 'https://snappymail.eu/',
|
||||||
VERSION = '1.4',
|
VERSION = '1.5',
|
||||||
RELEASE = '2022-12-08',
|
RELEASE = '2022-12-12',
|
||||||
REQUIRED = '2.23',
|
REQUIRED = '2.23',
|
||||||
CATEGORY = 'Contacts',
|
CATEGORY = 'Contacts',
|
||||||
LICENSE = 'MIT',
|
LICENSE = 'MIT',
|
||||||
|
|
@ -32,36 +32,46 @@ class AvatarsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
|
|
||||||
public function JsonMessage(array &$aResponse)
|
public function JsonMessage(array &$aResponse)
|
||||||
{
|
{
|
||||||
if (!empty($aResponse['Result']['From'])) {
|
if ($icon = $this->JsonAvatar($aResponse['Result'])) {
|
||||||
$aResponse['Result']['Avatar'] = $this->encryptFrom($aResponse['Result']['From'][0]);
|
$aResponse['Result']['Avatar'] = $icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function JsonMessageList(array &$aResponse)
|
public function JsonMessageList(array &$aResponse)
|
||||||
{
|
{
|
||||||
if (!empty($aResponse['Result']['@Collection'])) {
|
if (!empty($aResponse['Result']['@Collection'])) {
|
||||||
foreach ($aResponse['Result']['@Collection'] as $id => $message) {
|
foreach ($aResponse['Result']['@Collection'] as &$message) {
|
||||||
if (!empty($message['From'])) {
|
if ($icon = $this->JsonAvatar($message)) {
|
||||||
$aResponse['Result']['@Collection'][$id]['Avatar'] = $this->encryptFrom($message['From'][0]);
|
$message['Avatar'] = $icon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function encryptFrom($mFrom)
|
private function JsonAvatar($message) : ?string
|
||||||
{
|
{
|
||||||
|
$mFrom = empty($message['From'][0]) ? null : $message['From'][0];
|
||||||
if ($mFrom instanceof \MailSo\Mime\Email) {
|
if ($mFrom instanceof \MailSo\Mime\Email) {
|
||||||
$mFrom = $mFrom->jsonSerialize();
|
$mFrom = $mFrom->jsonSerialize();
|
||||||
}
|
}
|
||||||
if (!\is_array($mFrom)) {
|
if (\is_array($mFrom)) {
|
||||||
return null;
|
if ('pass' == $mFrom['DkimStatus'] && $this->Config()->Get('plugin', 'service', true)) {
|
||||||
|
// 'data:image/png;base64,[a-zA-Z0-9+/=]'
|
||||||
|
return static::getServiceIcon($mFrom['Email']);
|
||||||
|
}
|
||||||
|
if (!$this->Config()->Get('plugin', 'delay', true)
|
||||||
|
&& ($this->Config()->Get('plugin', 'gravatar', false)
|
||||||
|
|| ($this->Config()->Get('plugin', 'bimi', false) && 'pass' == $mFrom['DkimStatus'])
|
||||||
|
|| !$this->Config()->Get('plugin', 'service', true)
|
||||||
|
)
|
||||||
|
) try {
|
||||||
|
// Base64Url
|
||||||
|
return \SnappyMail\Crypt::EncryptUrlSafe($mFrom['Email']);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
\SnappyMail\Log::error('Crypt', $e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ('pass' == $mFrom['DkimStatus'] && $this->Config()->Get('plugin', 'service', true) && ($sIcon = static::getServiceIcon($mFrom['Email']))) {
|
return null;
|
||||||
return $sIcon;
|
|
||||||
}
|
|
||||||
return $this->Config()->Get('plugin', 'delay', true)
|
|
||||||
? null
|
|
||||||
: \SnappyMail\Crypt::EncryptUrlSafe($mFrom['Email']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -100,6 +110,23 @@ class AvatarsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
|
|
||||||
protected function configMapping() : array
|
protected function configMapping() : array
|
||||||
{
|
{
|
||||||
|
$group = new \RainLoop\Plugins\PropertyCollection('Lookup');
|
||||||
|
$group->exchangeArray([
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('delay')->SetLabel('Delay lookup')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
|
->SetAllowedInJs(true)
|
||||||
|
->SetDefaultValue(true),
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('bimi')->SetLabel('BIMI')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
|
// ->SetAllowedInJs(true)
|
||||||
|
->SetDefaultValue(false)
|
||||||
|
->SetDescription('https://bimigroup.org/ (DKIM header must be valid)'),
|
||||||
|
\RainLoop\Plugins\Property::NewInstance('gravatar')->SetLabel('Gravatar')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
|
// ->SetAllowedInJs(true)
|
||||||
|
->SetDefaultValue(false)
|
||||||
|
->SetDescription('https://wikipedia.org/wiki/Gravatar'),
|
||||||
|
]);
|
||||||
$aResult = array(
|
$aResult = array(
|
||||||
defined('RainLoop\\Enumerations\\PluginPropertyType::SELECT')
|
defined('RainLoop\\Enumerations\\PluginPropertyType::SELECT')
|
||||||
? \RainLoop\Plugins\Property::NewInstance('identicon')->SetLabel('Identicon')
|
? \RainLoop\Plugins\Property::NewInstance('identicon')->SetLabel('Identicon')
|
||||||
|
|
@ -119,18 +146,10 @@ class AvatarsPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
,
|
,
|
||||||
\RainLoop\Plugins\Property::NewInstance('service')->SetLabel('Preload valid domain icons')
|
\RainLoop\Plugins\Property::NewInstance('service')->SetLabel('Preload valid domain icons')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
->SetDefaultValue(true),
|
->SetAllowedInJs(true)
|
||||||
\RainLoop\Plugins\Property::NewInstance('bimi')->SetLabel('Lookup BIMI')
|
->SetDefaultValue(true)
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetDescription('DKIM header must be valid and icon is found in avatars/images/services directory'),
|
||||||
->SetDefaultValue(false)
|
$group
|
||||||
->SetDescription('https://bimigroup.org/'),
|
|
||||||
\RainLoop\Plugins\Property::NewInstance('gravatar')->SetLabel('Lookup Gravatar')
|
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
|
||||||
->SetDefaultValue(false)
|
|
||||||
->SetDescription('https://wikipedia.org/wiki/Gravatar'),
|
|
||||||
\RainLoop\Plugins\Property::NewInstance('delay')->SetLabel('Delay lookup loading')
|
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
|
||||||
->SetDefaultValue(true),
|
|
||||||
);
|
);
|
||||||
/*
|
/*
|
||||||
if (\class_exists('OC') && isset(\OC::$server)) {
|
if (\class_exists('OC') && isset(\OC::$server)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue