mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 18:19:22 +03:00
chore: refactor nexcloud plugin- related to NC-addressbook
This commit is contained in:
parent
2e3fbe0a12
commit
552a91acc2
5 changed files with 200 additions and 163 deletions
|
|
@ -5,15 +5,15 @@ use RainLoop\Providers\AddressBook\Classes\Contact;
|
||||||
class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInterface
|
class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInterface
|
||||||
{
|
{
|
||||||
use RainLoop\Providers\AddressBook\CardDAV;
|
use RainLoop\Providers\AddressBook\CardDAV;
|
||||||
private $contactsManager;
|
|
||||||
|
|
||||||
private const SETTINGS_KEY = 'nextCloudAddressBookUri';
|
private const SETTINGS_KEY = 'nextcloudAddressBookUri';
|
||||||
|
|
||||||
private string $defaultUri = 'webmail';
|
private string $defaultUri = 'webmail';
|
||||||
private string $defaultName = 'WebMail';
|
private string $defaultName = 'WebMail';
|
||||||
private string $defaultDescription = 'Recipients from snappymail';
|
private string $defaultDescription = 'Recipients from snappymail';
|
||||||
private bool $ignoreSystemAddressBook = true;
|
private bool $ignoreSystemAddressBook = true;
|
||||||
|
|
||||||
|
private $contactsManager;
|
||||||
|
|
||||||
function __construct(string $defaultUri = 'webmail', string $defaultName = 'WebMail', string $defaultDescription = 'Recipients from snappymail', bool $ignoreSystemAddressBook = true)
|
function __construct(string $defaultUri = 'webmail', string $defaultName = 'WebMail', string $defaultDescription = 'Recipients from snappymail', bool $ignoreSystemAddressBook = true)
|
||||||
{
|
{
|
||||||
|
|
@ -25,14 +25,21 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
||||||
$this->GetSavedAddressBookKey();
|
$this->GetSavedAddressBookKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetSavedAddressBookKey(): string
|
private function getContactsManager()
|
||||||
{
|
{
|
||||||
$this->contactsManager = \OC::$server->getContactsManager();
|
if ($this->contactsManager == null) {
|
||||||
|
$this->contactsManager = \OC::$server->getContactsManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->contactsManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetSavedAddressBookKey() : string
|
||||||
|
{
|
||||||
if ($this->ignoreSystemAddressBook) {
|
if ($this->ignoreSystemAddressBook) {
|
||||||
foreach ($this->contactsManager->getUserAddressBooks() as $addressBook) {
|
foreach ($this->getContactsManager()->getUserAddressBooks() as $addressBook) {
|
||||||
if ($addressBook->isSystemAddressBook()) {
|
if ($addressBook->isSystemAddressBook()) {
|
||||||
$this->contactsManager->unregisterAddressBook($addressBook);
|
$this->getContactsManager()->unregisterAddressBook($addressBook);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,63 +60,63 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
||||||
return $addressBookId['id'];
|
return $addressBookId['id'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function IsSupported(): bool
|
public function IsSupported() : bool
|
||||||
{
|
{
|
||||||
// Maybe just return true, contacts app is just a frontend
|
// Maybe just return true, contacts app is just a frontend
|
||||||
//return \OC::$server->getAppManager()->isEnabledForUser('contacts');
|
return \OC::$server->getAppManager()->isEnabledForUser('contacts');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function SetEmail(string $sEmail) : bool
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetEmail(string $sEmail) : bool {
|
public function Sync() : bool
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Sync(): bool
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Export(string $sType = 'vcf'): bool
|
public function Export(string $sType = 'vcf') : bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ContactSave(Contact $oContact): bool
|
public function ContactSave(Contact $oContact) : bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DeleteContacts(array $aContactIds): bool
|
public function DeleteContacts(array $aContactIds) : bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DeleteAllContacts(string $sEmail): bool
|
public function DeleteAllContacts(string $sEmail) : bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetContacts(int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0): array
|
public function GetContacts(int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0) : array
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetContactByEmail(string $sEmail): ?Contact
|
public function GetContactByEmail(string $sEmail) : ?Contact
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetContactByID($mID, bool $bIsStrID = false): ?Contact
|
public function GetContactByID($mID, bool $bIsStrID = false) : ?Contact
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetSuggestions(string $sSearch, int $iLimit = 20): array
|
public function GetSuggestions(string $sSearch, int $iLimit = 20) : array
|
||||||
{
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetEmailObjects(array $aEmails): array
|
private function GetEmailObjects(array $aEmails) : array
|
||||||
{
|
{
|
||||||
$aEmailsObjects = \array_map(function ($mItem) {
|
$aEmailsObjects = \array_map(function ($mItem) {
|
||||||
$oResult = null;
|
$oResult = null;
|
||||||
|
|
@ -131,7 +138,7 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
||||||
* Add/increment email address usage
|
* Add/increment email address usage
|
||||||
* Handy for "most used" sorting suggestions in PdoAddressBook
|
* Handy for "most used" sorting suggestions in PdoAddressBook
|
||||||
*/
|
*/
|
||||||
public function IncFrec(array $aEmails, bool $bCreateAuto = true): bool
|
public function IncFrec(array $aEmails, bool $bCreateAuto = true) : bool
|
||||||
{
|
{
|
||||||
if ($bCreateAuto) {
|
if ($bCreateAuto) {
|
||||||
$aEmailsObjects = $this->GetEmailObjects($aEmails);
|
$aEmailsObjects = $this->GetEmailObjects($aEmails);
|
||||||
|
|
@ -139,53 +146,61 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
||||||
if (!count($aEmailsObjects)) {
|
if (!count($aEmailsObjects)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($aEmailsObjects as $oEmail) {
|
foreach ($aEmailsObjects as $oEmail) {
|
||||||
if ('' === \trim($oEmail->GetEmail())) {
|
$this->createOrUpdateContact($oEmail);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$sEmail = \trim($oEmail->GetEmail(true));
|
|
||||||
$existingResults = $this->contactsManager->search($sEmail, ['EMAIL'], ['strict_search' => true]);
|
|
||||||
|
|
||||||
if (!empty($existingResults)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$properties = [
|
|
||||||
'EMAIL' => $sEmail,
|
|
||||||
'FN' => $sEmail
|
|
||||||
];
|
|
||||||
|
|
||||||
if ('' !== \trim($oEmail->GetDisplayName())) {
|
|
||||||
$properties['FN'] = $oEmail->GetDisplayName();
|
|
||||||
}
|
|
||||||
$this->contactsManager->createOrUpdate($properties, $this->GetSavedAddressBookKey());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Test(): string
|
private function createOrUpdateContact($oEmail)
|
||||||
|
{
|
||||||
|
if ('' === \trim($oEmail->GetEmail())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$sEmail = \trim($oEmail->GetEmail(true));
|
||||||
|
$existingResults = $this->getContactsManager()->search($sEmail, ['EMAIL'], ['strict_search' => true]);
|
||||||
|
|
||||||
|
if (!empty($existingResults)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$properties = [
|
||||||
|
'EMAIL' => $sEmail,
|
||||||
|
'FN' => $sEmail
|
||||||
|
];
|
||||||
|
|
||||||
|
if ('' !== \trim($oEmail->GetDisplayName())) {
|
||||||
|
$properties['FN'] = $oEmail->GetDisplayName();
|
||||||
|
}
|
||||||
|
$this->getContactsManager()->createOrUpdate($properties, $this->GetSavedAddressBookKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Test() : string
|
||||||
{
|
{
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function Account(): \RainLoop\Model\Account
|
private function Account() : \RainLoop\Model\Account
|
||||||
{
|
{
|
||||||
return \RainLoop\Api::Actions()->getAccountFromToken();
|
return \RainLoop\Api::Actions()->getAccountFromToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function SettingsProvider(): \RainLoop\Providers\Settings
|
private function SettingsProvider() : \RainLoop\Providers\Settings
|
||||||
{
|
{
|
||||||
return \RainLoop\Api::Actions()->SettingsProvider(true);
|
return \RainLoop\Api::Actions()->SettingsProvider(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function Settings(): \RainLoop\Settings
|
private function Settings() : \RainLoop\Settings
|
||||||
{
|
{
|
||||||
return $this->SettingsProvider()->Load($this->Account());
|
return $this->SettingsProvider()->Load($this->Account());
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetSavedUri(): string
|
private function GetSavedUri() : string
|
||||||
{
|
{
|
||||||
return $this->Settings()->GetConf(self::SETTINGS_KEY, $this->defaultUri);
|
return $this->Settings()->GetConf(self::SETTINGS_KEY, $this->defaultUri);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,27 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
DESCRIPTION = 'Integrate with Nextcloud v20+',
|
DESCRIPTION = 'Integrate with Nextcloud v20+',
|
||||||
REQUIRED = '2.36.2';
|
REQUIRED = '2.36.2';
|
||||||
|
|
||||||
|
private const IGNORE_SYSTEM_ADDRESSBOOK_KEY = 'ignoreSystemAddressbook';
|
||||||
|
private const IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE = true;
|
||||||
|
|
||||||
private const DEFAULT_ADDRESSBOOK_NAME = 'WebMail';
|
private const ENABLE_NC_ADDRESSBOOK_KEY = 'enableNcAddressbook';
|
||||||
private const DEFAULT_ADDRESSBOOK_DESCRIPTION = 'Recipients from snappymail';
|
private const ENABLE_NC_ADDRESSBOOK_DEFAULT_VALUE = false;
|
||||||
|
|
||||||
|
private const DISABLE_INHOUSE_ADDRESSBOOK_KEY = 'disableSnappymailContactsUI';
|
||||||
|
private const DISABLE_INHOUSE_ADDRESSBOOK_DEFAULT_VALUE = false;
|
||||||
|
|
||||||
|
private const DEFAULT_ADDRESSBOOK_URI_KEY = 'defaultNCAddressbookUri';
|
||||||
private const DEFAULT_ADDRESSBOOK_URI = 'webmail';
|
private const DEFAULT_ADDRESSBOOK_URI = 'webmail';
|
||||||
private const ADDRESSBOOK_SETTINGS_KEY = 'nextCloudAddressBookUri';
|
|
||||||
|
|
||||||
public function Init(): void
|
private const DEFAULT_ADDRESSBOOK_NAME_KEY = 'defaultNCAddressbookName';
|
||||||
|
private const DEFAULT_ADDRESSBOOK_NAME = 'WebMail';
|
||||||
|
|
||||||
|
private const DEFAULT_ADDRESSBOOK_DESCRIPTION_KEY = 'defaultNCAddressbookDescription';
|
||||||
|
private const DEFAULT_ADDRESSBOOK_DESCRIPTION = 'Recipients from snappymail';
|
||||||
|
|
||||||
|
private const ADDRESSBOOK_SETTINGS_KEY = 'nextcloudAddressBookUri';
|
||||||
|
|
||||||
|
public function Init() : void
|
||||||
{
|
{
|
||||||
if (static::IsIntegrated()) {
|
if (static::IsIntegrated()) {
|
||||||
\SnappyMail\Log::debug('Nextcloud', 'integrated');
|
\SnappyMail\Log::debug('Nextcloud', 'integrated');
|
||||||
|
|
@ -42,19 +56,19 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
$this->addTemplate('templates/PopupsNextcloudFiles.html');
|
$this->addTemplate('templates/PopupsNextcloudFiles.html');
|
||||||
$this->addTemplate('templates/PopupsNextcloudCalendars.html');
|
$this->addTemplate('templates/PopupsNextcloudCalendars.html');
|
||||||
|
|
||||||
// $this->addHook('login.credentials.step-2', 'loginCredentials2');
|
// $this->addHook('login.credentials.step-2', 'loginCredentials2');
|
||||||
// $this->addHook('login.credentials', 'loginCredentials');
|
// $this->addHook('login.credentials', 'loginCredentials');
|
||||||
$this->addHook('imap.before-login', 'beforeLogin');
|
$this->addHook('imap.before-login', 'beforeLogin');
|
||||||
$this->addHook('smtp.before-login', 'beforeLogin');
|
$this->addHook('smtp.before-login', 'beforeLogin');
|
||||||
$this->addHook('sieve.before-login', 'beforeLogin');
|
$this->addHook('sieve.before-login', 'beforeLogin');
|
||||||
|
|
||||||
if ($this->Config()->Get('plugin', 'enableNcAddressbook', false)) {
|
if ($this->Config()->Get('plugin', self::ENABLE_NC_ADDRESSBOOK_KEY, self::ENABLE_NC_ADDRESSBOOK_DEFAULT_VALUE)) {
|
||||||
$this->addJs('js/addressbook.js');
|
$this->addJs('js/nextcloudAddressbook.js');
|
||||||
$this->addJsonHook('NextcloudGetAddressBooks', 'GetAddressBooks');
|
$this->addJsonHook('NextcloudGetAddressBooks', 'GetAddressBooks');
|
||||||
$this->addJsonHook('NextcloudUpdateAddressBook', 'UpdateAddressBook');
|
$this->addJsonHook('NextcloudUpdateAddressBook', 'UpdateAddressBook');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->Config()->Get('plugin', 'disableInhouseAddressbook', false)) {
|
if ($this->Config()->Get('plugin', self::DISABLE_INHOUSE_ADDRESSBOOK_KEY, self::DISABLE_INHOUSE_ADDRESSBOOK_DEFAULT_VALUE)) {
|
||||||
$this->addJs('js/hideInhouseAddressbook.js');
|
$this->addJs('js/hideInhouseAddressbook.js');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -70,9 +84,9 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
|
|
||||||
$contactsManager = \OC::$server->getContactsManager();
|
$contactsManager = \OC::$server->getContactsManager();
|
||||||
|
|
||||||
$defaultUri = $this->Config()->Get('plugin', 'defaultNCAddressbookUri', self::DEFAULT_ADDRESSBOOK_URI);
|
$defaultUri = $this->Config()->Get('plugin', self::DEFAULT_ADDRESSBOOK_URI_KEY, self::DEFAULT_ADDRESSBOOK_URI);
|
||||||
$selectedUri = $this->UserSettings()->GetConf(self::ADDRESSBOOK_SETTINGS_KEY, $defaultUri);
|
$selectedUri = $this->UserSettings()->GetConf(self::ADDRESSBOOK_SETTINGS_KEY, $defaultUri);
|
||||||
$ignoreSystemAddressbook = $this->Config()->Get('plugin', 'ignoreSystemAddressbook', true);
|
$ignoreSystemAddressbook = $this->Config()->Get('plugin', self::IGNORE_SYSTEM_ADDRESSBOOK_KEY, self::IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE);
|
||||||
|
|
||||||
foreach ($contactsManager->getUserAddressBooks() as $addressBook) {
|
foreach ($contactsManager->getUserAddressBooks() as $addressBook) {
|
||||||
if ($ignoreSystemAddressbook && $addressBook->isSystemAddressBook()) {
|
if ($ignoreSystemAddressbook && $addressBook->isSystemAddressBook()) {
|
||||||
|
|
@ -96,7 +110,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function UpdateAddressBook(): array
|
public function UpdateAddressBook() : array
|
||||||
{
|
{
|
||||||
$uri = $this->jsonParam('uri');
|
$uri = $this->jsonParam('uri');
|
||||||
$oSettings = $this->UserSettings();
|
$oSettings = $this->UserSettings();
|
||||||
|
|
@ -115,7 +129,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Supported(): string
|
public function Supported() : string
|
||||||
{
|
{
|
||||||
return static::IsIntegrated() ? '' : 'Nextcloud not found to use this plugin';
|
return static::IsIntegrated() ? '' : 'Nextcloud not found to use this plugin';
|
||||||
}
|
}
|
||||||
|
|
@ -130,24 +144,24 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
return static::IsIntegrated() && \OC::$server->getUserSession()->isLoggedIn();
|
return static::IsIntegrated() && \OC::$server->getUserSession()->isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loginCredentials(string &$sEmail, string &$sLogin, ?string &$sPassword = null): void
|
public function loginCredentials(string &$sEmail, string &$sLogin, ?string &$sPassword = null) : void
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* This has an issue.
|
* This has an issue.
|
||||||
* When user changes email address, all settings are gone as the new
|
* When user changes email address, all settings are gone as the new
|
||||||
* _data_/_default_/storage/{domain}/{local-part} is used
|
* _data_/_default_/storage/{domain}/{local-part} is used
|
||||||
*/
|
*/
|
||||||
// $ocUser = \OC::$server->getUserSession()->getUser();
|
// $ocUser = \OC::$server->getUserSession()->getUser();
|
||||||
// $sEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress() ?: $sEmail;
|
// $sEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress() ?: $sEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loginCredentials2(string &$sEmail, ?string &$sPassword = null): void
|
public function loginCredentials2(string &$sEmail, ?string &$sPassword = null) : void
|
||||||
{
|
{
|
||||||
$ocUser = \OC::$server->getUserSession()->getUser();
|
$ocUser = \OC::$server->getUserSession()->getUser();
|
||||||
$sEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress() ?: $sEmail;
|
$sEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress() ?: $sEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetClient $oClient, \MailSo\Net\ConnectSettings $oSettings): void
|
public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetClient $oClient, \MailSo\Net\ConnectSettings $oSettings) : void
|
||||||
{
|
{
|
||||||
// https://apps.nextcloud.com/apps/oidc_login
|
// https://apps.nextcloud.com/apps/oidc_login
|
||||||
$config = \OC::$server->getConfig();
|
$config = \OC::$server->getConfig();
|
||||||
|
|
@ -164,12 +178,11 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
// Only login with OIDC access token if
|
// Only login with OIDC access token if
|
||||||
// it is enabled in config, the user is currently logged in with OIDC,
|
// it is enabled in config, the user is currently logged in with OIDC,
|
||||||
// the current snappymail account is the OIDC account and no account defined explicitly
|
// the current snappymail account is the OIDC account and no account defined explicitly
|
||||||
if (
|
if (\OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-autologin-oidc', false)
|
||||||
\OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-autologin-oidc', false)
|
&& \OC::$server->getSession()->get('is_oidc')
|
||||||
&& \OC::$server->getSession()->get('is_oidc')
|
&& $sNcEmail === $oSettings->username
|
||||||
&& $sNcEmail === $oSettings->username
|
&& !$bAccountDefinedExplicitly
|
||||||
&& !$bAccountDefinedExplicitly
|
// && $oClient->supportsAuthType('OAUTHBEARER') // v2.28
|
||||||
// && $oClient->supportsAuthType('OAUTHBEARER') // v2.28
|
|
||||||
) {
|
) {
|
||||||
$sAccessToken = \OC::$server->getSession()->get('oidc_access_token');
|
$sAccessToken = \OC::$server->getSession()->get('oidc_access_token');
|
||||||
if ($sAccessToken) {
|
if ($sAccessToken) {
|
||||||
|
|
@ -184,7 +197,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
\OC::$server->getLDAPProvider();
|
\OC::$server->getLDAPProvider();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function NextcloudAttachFile(): array
|
public function NextcloudAttachFile() : array
|
||||||
{
|
{
|
||||||
$aResult = [
|
$aResult = [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
|
|
@ -208,10 +221,10 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
return $this->jsonResponse(__FUNCTION__, $aResult);
|
return $this->jsonResponse(__FUNCTION__, $aResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function NextcloudSaveMsg(): array
|
public function NextcloudSaveMsg() : array
|
||||||
{
|
{
|
||||||
$sSaveFolder = \ltrim($this->jsonParam('folder', ''), '/');
|
$sSaveFolder = \ltrim($this->jsonParam('folder', ''), '/');
|
||||||
// $aValues = \RainLoop\Api::Actions()->decodeRawKey($this->jsonParam('msgHash', ''));
|
// $aValues = \RainLoop\Api::Actions()->decodeRawKey($this->jsonParam('msgHash', ''));
|
||||||
$msgHash = $this->jsonParam('msgHash', '');
|
$msgHash = $this->jsonParam('msgHash', '');
|
||||||
$aValues = \json_decode(\MailSo\Base\Utils::UrlSafeBase64Decode($msgHash), true);
|
$aValues = \json_decode(\MailSo\Base\Utils::UrlSafeBase64Decode($msgHash), true);
|
||||||
$aResult = [
|
$aResult = [
|
||||||
|
|
@ -265,14 +278,14 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
foreach ($data->items as $aItem) {
|
foreach ($data->items as $aItem) {
|
||||||
$sSavedFileName = empty($aItem['fileName']) ? 'file.dat' : $aItem['fileName'];
|
$sSavedFileName = empty($aItem['fileName']) ? 'file.dat' : $aItem['fileName'];
|
||||||
if (!empty($aItem['data'])) {
|
if (!empty($aItem['data'])) {
|
||||||
$sSavedFileNameFull = static::SmartFileExists($sSaveFolder . '/' . $sSavedFileName, $oFiles);
|
$sSavedFileNameFull = static::SmartFileExists($sSaveFolder.'/'.$sSavedFileName, $oFiles);
|
||||||
if (!$oFiles->file_put_contents($sSavedFileNameFull, $aItem['data'])) {
|
if (!$oFiles->file_put_contents($sSavedFileNameFull, $aItem['data'])) {
|
||||||
$data->result = false;
|
$data->result = false;
|
||||||
}
|
}
|
||||||
} else if (!empty($aItem['fileHash'])) {
|
} else if (!empty($aItem['fileHash'])) {
|
||||||
$fFile = $data->filesProvider->GetFile($data->account, $aItem['fileHash'], 'rb');
|
$fFile = $data->filesProvider->GetFile($data->account, $aItem['fileHash'], 'rb');
|
||||||
if (\is_resource($fFile)) {
|
if (\is_resource($fFile)) {
|
||||||
$sSavedFileNameFull = static::SmartFileExists($sSaveFolder . '/' . $sSavedFileName, $oFiles);
|
$sSavedFileNameFull = static::SmartFileExists($sSaveFolder.'/'.$sSavedFileName, $oFiles);
|
||||||
if (!$oFiles->file_put_contents($sSavedFileNameFull, $fFile)) {
|
if (!$oFiles->file_put_contents($sSavedFileNameFull, $fFile)) {
|
||||||
$data->result = false;
|
$data->result = false;
|
||||||
}
|
}
|
||||||
|
|
@ -286,19 +299,19 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function FilterAppData($bAdmin, &$aResult): void
|
public function FilterAppData($bAdmin, &$aResult) : void
|
||||||
{
|
{
|
||||||
if (!$bAdmin && \is_array($aResult)) {
|
if (!$bAdmin && \is_array($aResult)) {
|
||||||
$ocUser = \OC::$server->getUserSession()->getUser();
|
$ocUser = \OC::$server->getUserSession()->getUser();
|
||||||
$sUID = $ocUser->getUID();
|
$sUID = $ocUser->getUID();
|
||||||
$oUrlGen = \OC::$server->getURLGenerator();
|
$oUrlGen = \OC::$server->getURLGenerator();
|
||||||
$sWebDAV = $oUrlGen->getAbsoluteURL($oUrlGen->linkTo('', 'remote.php') . '/dav');
|
$sWebDAV = $oUrlGen->getAbsoluteURL($oUrlGen->linkTo('', 'remote.php') . '/dav');
|
||||||
// $sWebDAV = \OCP\Util::linkToRemote('dav');
|
// $sWebDAV = \OCP\Util::linkToRemote('dav');
|
||||||
$aResult['Nextcloud'] = [
|
$aResult['Nextcloud'] = [
|
||||||
'UID' => $sUID,
|
'UID' => $sUID,
|
||||||
'WebDAV' => $sWebDAV,
|
'WebDAV' => $sWebDAV,
|
||||||
'CalDAV' => $this->Config()->Get('plugin', 'calendar', false)
|
'CalDAV' => $this->Config()->Get('plugin', 'calendar', false)
|
||||||
// 'WebDAV_files' => $sWebDAV . '/files/' . $sUID
|
// 'WebDAV_files' => $sWebDAV . '/files/' . $sUID
|
||||||
];
|
];
|
||||||
if (empty($aResult['Auth'])) {
|
if (empty($aResult['Auth'])) {
|
||||||
$config = \OC::$server->getConfig();
|
$config = \OC::$server->getConfig();
|
||||||
|
|
@ -320,9 +333,9 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
if (!$sEmail) {
|
if (!$sEmail) {
|
||||||
$sEmail = $ocUser->getEMailAddress();
|
$sEmail = $ocUser->getEMailAddress();
|
||||||
// ?: $ocUser->getPrimaryEMailAddress();
|
// ?: $ocUser->getPrimaryEMailAddress();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if ($config->getAppValue('snappymail', 'snappymail-autologin-oidc', false)) {
|
if ($config->getAppValue('snappymail', 'snappymail-autologin-oidc', false)) {
|
||||||
if (\OC::$server->getSession()->get('is_oidc')) {
|
if (\OC::$server->getSession()->get('is_oidc')) {
|
||||||
$sEmail = "{$sUID}@nextcloud";
|
$sEmail = "{$sUID}@nextcloud";
|
||||||
|
|
@ -369,7 +382,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function FilterLanguage(&$sLanguage, $bAdmin): void
|
public function FilterLanguage(&$sLanguage, $bAdmin) : void
|
||||||
{
|
{
|
||||||
if (!\RainLoop\Api::Config()->Get('webmail', 'allow_languages_on_settings', true)) {
|
if (!\RainLoop\Api::Config()->Get('webmail', 'allow_languages_on_settings', true)) {
|
||||||
$aResultLang = \SnappyMail\L10n::getLanguages($bAdmin);
|
$aResultLang = \SnappyMail\L10n::getLanguages($bAdmin);
|
||||||
|
|
@ -392,7 +405,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
*
|
*
|
||||||
* @return string return locale
|
* @return string return locale
|
||||||
*/
|
*/
|
||||||
private function determineLocale(string $langCode, array $languagesArray): ?string
|
private function determineLocale(string $langCode, array $languagesArray) : ?string
|
||||||
{
|
{
|
||||||
// Direct check for the language code
|
// Direct check for the language code
|
||||||
if (\in_array($langCode, $languagesArray)) {
|
if (\in_array($langCode, $languagesArray)) {
|
||||||
|
|
@ -429,20 +442,20 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
include_once __DIR__ . '/NextcloudContactsSuggestions.php';
|
include_once __DIR__ . '/NextcloudContactsSuggestions.php';
|
||||||
$mResult[] = new NextcloudContactsSuggestions(
|
$mResult[] = new NextcloudContactsSuggestions(
|
||||||
$this->Config()->Get('plugin', 'ignoreSystemAddressbook', true)
|
$this->Config()->Get('plugin', self::IGNORE_SYSTEM_ADDRESSBOOK_KEY, self::IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('address-book' === $sName && $this->Config()->Get('plugin', 'enableNcAddressbook', false)) {
|
if ('address-book' === $sName && $this->Config()->Get('plugin', self::ENABLE_NC_ADDRESSBOOK_KEY, self::ENABLE_NC_ADDRESSBOOK_DEFAULT_VALUE)) {
|
||||||
if (!\is_array($mResult)) {
|
if (!\is_array($mResult)) {
|
||||||
$mResult = array();
|
$mResult = array();
|
||||||
}
|
}
|
||||||
include_once __DIR__ . '/NextcloudAddressBook.php';
|
include_once __DIR__ . '/NextcloudAddressBook.php';
|
||||||
|
|
||||||
$ignoreSystemAddressbook = $this->Config()->Get('plugin', 'ignoreSystemAddressbook', true);
|
$ignoreSystemAddressbook = $this->Config()->Get('plugin', self::IGNORE_SYSTEM_ADDRESSBOOK_KEY, self::IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE);
|
||||||
$defaultName = $this->Config()->Get('plugin', 'defaultNCAddressbookName', self::DEFAULT_ADDRESSBOOK_NAME);
|
$defaultName = $this->Config()->Get('plugin', self::DEFAULT_ADDRESSBOOK_NAME_KEY, self::DEFAULT_ADDRESSBOOK_NAME);
|
||||||
$defaultDescription = $this->Config()->Get('plugin', 'defaultNCAddressbookDescription', self::DEFAULT_ADDRESSBOOK_DESCRIPTION);
|
$defaultDescription = $this->Config()->Get('plugin', self::DEFAULT_ADDRESSBOOK_DESCRIPTION_KEY, self::DEFAULT_ADDRESSBOOK_DESCRIPTION);
|
||||||
$defaultUri = $this->Config()->Get('plugin', 'defaultNCAddressbookUri', self::DEFAULT_ADDRESSBOOK_URI);
|
$defaultUri = $this->Config()->Get('plugin', self::DEFAULT_ADDRESSBOOK_URI_KEY, self::DEFAULT_ADDRESSBOOK_URI);
|
||||||
|
|
||||||
$mResult = new NextcloudAddressBook(
|
$mResult = new NextcloudAddressBook(
|
||||||
$defaultUri,
|
$defaultUri,
|
||||||
|
|
@ -460,16 +473,16 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configMapping(): array
|
protected function configMapping() : array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
\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')
|
\RainLoop\Plugins\Property::NewInstance(self::IGNORE_SYSTEM_ADDRESSBOOK_KEY)->SetLabel('Ignore system addressbook')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
->SetDefaultValue(true),
|
->SetDefaultValue(self::IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE),
|
||||||
/*
|
/*
|
||||||
\RainLoop\Plugins\Property::NewInstance('storage')->SetLabel('Use Nextcloud user ID in config storage path')
|
\RainLoop\Plugins\Property::NewInstance('storage')->SetLabel('Use Nextcloud user ID in config storage path')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
->SetDefaultValue(false)
|
->SetDefaultValue(false)
|
||||||
|
|
@ -478,29 +491,29 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
->SetDefaultValue(false),
|
->SetDefaultValue(false),
|
||||||
|
|
||||||
\RainLoop\Plugins\Property::NewInstance('enableNcAddressbook')->SetLabel('Enable User to choose Nextcloud addressbook for recipients')
|
\RainLoop\Plugins\Property::NewInstance(self::ENABLE_NC_ADDRESSBOOK_KEY)->SetLabel('Enable User to choose Nextcloud addressbook for recipients')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
->SetDefaultValue(false),
|
->SetDefaultValue(self::ENABLE_NC_ADDRESSBOOK_DEFAULT_VALUE),
|
||||||
|
|
||||||
\RainLoop\Plugins\Property::NewInstance('defaultNCAddressbookUri')->SetLabel('Default nextcloud addressbook URI for recipinets')
|
\RainLoop\Plugins\Property::NewInstance(self::DEFAULT_ADDRESSBOOK_URI_KEY)->SetLabel('Default nextcloud addressbook URI for recipinets')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||||
->SetDefaultValue('webmail'),
|
->SetDefaultValue(self::DEFAULT_ADDRESSBOOK_URI),
|
||||||
|
|
||||||
\RainLoop\Plugins\Property::NewInstance('defaultNCAddressbookName')->SetLabel('Default nextcloud addressbook Name for recipinets')
|
\RainLoop\Plugins\Property::NewInstance(self::DEFAULT_ADDRESSBOOK_NAME_KEY)->SetLabel('Default nextcloud addressbook Name for recipinets')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||||
->SetDefaultValue(self::DEFAULT_ADDRESSBOOK_NAME),
|
->SetDefaultValue(self::DEFAULT_ADDRESSBOOK_NAME),
|
||||||
|
|
||||||
\RainLoop\Plugins\Property::NewInstance('defaultNCAddressbookDescription')->SetLabel('Default nextcloud addressbook description for recipinets')
|
\RainLoop\Plugins\Property::NewInstance(self::DEFAULT_ADDRESSBOOK_DESCRIPTION_KEY)->SetLabel('Default nextcloud addressbook description for recipinets')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||||
->SetDefaultValue(self::DEFAULT_ADDRESSBOOK_DESCRIPTION),
|
->SetDefaultValue(self::DEFAULT_ADDRESSBOOK_DESCRIPTION),
|
||||||
|
|
||||||
\RainLoop\Plugins\Property::NewInstance('disableInhouseAddressbook')->SetLabel('Disable SnappyMail internal addressbook. This is recomended if nextcloud addressbook is being used.')
|
\RainLoop\Plugins\Property::NewInstance(self::DISABLE_INHOUSE_ADDRESSBOOK_KEY)->SetLabel('Disable SnappyMail internal addressbook. This is recomended if nextcloud addressbook is being used.')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
->SetDefaultValue(false)
|
->SetDefaultValue(self::DISABLE_INHOUSE_ADDRESSBOOK_DEFAULT_VALUE)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function SmartFileExists(string $sFilePath, $oFiles): string
|
private static function SmartFileExists(string $sFilePath, $oFiles) : string
|
||||||
{
|
{
|
||||||
$sFilePath = \str_replace('\\', '/', \trim($sFilePath));
|
$sFilePath = \str_replace('\\', '/', \trim($sFilePath));
|
||||||
|
|
||||||
|
|
@ -514,10 +527,11 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
++$iIndex;
|
++$iIndex;
|
||||||
$sFilePathNew = $aFileInfo['dirname'] . '/' .
|
$sFilePathNew = $aFileInfo['dirname'].'/'.
|
||||||
\preg_replace('/\(\d{1,2}\)$/', '', $aFileInfo['filename']) .
|
\preg_replace('/\(\d{1,2}\)$/', '', $aFileInfo['filename']).
|
||||||
' (' . $iIndex . ')' .
|
' ('.$iIndex.')'.
|
||||||
(empty($aFileInfo['extension']) ? '' : '.' . $aFileInfo['extension']);
|
(empty($aFileInfo['extension']) ? '' : '.'.$aFileInfo['extension'])
|
||||||
|
;
|
||||||
if (!$oFiles->file_exists($sFilePathNew)) {
|
if (!$oFiles->file_exists($sFilePathNew)) {
|
||||||
return $sFilePathNew;
|
return $sFilePathNew;
|
||||||
}
|
}
|
||||||
|
|
@ -528,17 +542,17 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
return $sFilePath;
|
return $sFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function Account(): \RainLoop\Model\Account
|
private function Account() : \RainLoop\Model\Account
|
||||||
{
|
{
|
||||||
return \RainLoop\Api::Actions()->getAccountFromToken();
|
return \RainLoop\Api::Actions()->getAccountFromToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function SettingsProvider(): \RainLoop\Providers\Settings
|
private function SettingsProvider() : \RainLoop\Providers\Settings
|
||||||
{
|
{
|
||||||
return \RainLoop\Api::Actions()->SettingsProvider(true);
|
return \RainLoop\Api::Actions()->SettingsProvider(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function UserSettings(): \RainLoop\Settings
|
private function UserSettings() : \RainLoop\Settings
|
||||||
{
|
{
|
||||||
return $this->SettingsProvider()->Load($this->Account());
|
return $this->SettingsProvider()->Load($this->Account());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
(rl => {
|
|
||||||
if (rl) {
|
|
||||||
addEventListener('rl-view-model', e => {
|
|
||||||
if ('SettingsContacts' === e.detail.viewModelTemplateID) {
|
|
||||||
const container = e.detail.viewModelDom.querySelector('.form-horizontal');
|
|
||||||
if (container) {
|
|
||||||
rl.pluginRemoteRequest((iError, oData) => {
|
|
||||||
if (!iError) {
|
|
||||||
const mainDivElement = Element.fromHTML('<div class="control-group">'
|
|
||||||
+ '<label>' + rl.i18n("NEXTCLOUD/ADDRESS_BOOK") + '</label>'
|
|
||||||
+ '</div>');
|
|
||||||
|
|
||||||
const selectElement = Element.fromHTML('<select></select>');
|
|
||||||
|
|
||||||
const books = JSON.parse(oData.Result.addressbooks);
|
|
||||||
books.forEach(book => {
|
|
||||||
if (book.selected) {
|
|
||||||
selectElement.append(Element.fromHTML('<option value="' + book.uri + '" selected="selected">' + book.name + '</option>'));
|
|
||||||
} else {
|
|
||||||
selectElement.append(Element.fromHTML('<option value="' + book.uri + '">' + book.name + '</option>'));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
selectElement.onchange = function() {
|
|
||||||
rl.pluginRemoteRequest(() => { }, 'NextcloudUpdateAddressBook', {
|
|
||||||
uri: selectElement.value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
mainDivElement.append(selectElement);
|
|
||||||
container.append(mainDivElement);
|
|
||||||
}
|
|
||||||
}, "NextcloudGetAddressBooks");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})(window.rl);
|
|
||||||
|
|
@ -13,14 +13,16 @@
|
||||||
addEventListener('rl-view-model', e => {
|
addEventListener('rl-view-model', e => {
|
||||||
if ('SystemDropDown' === e.detail.viewModelTemplateID) {
|
if ('SystemDropDown' === e.detail.viewModelTemplateID) {
|
||||||
const container = e.detail.viewModelDom.querySelector('.dropdown-menu');
|
const container = e.detail.viewModelDom.querySelector('.dropdown-menu');
|
||||||
if (container) {
|
if (!container) {
|
||||||
for (i = 0; i < container.children.length; i++) {
|
return;
|
||||||
const element = container.children[i];
|
}
|
||||||
const attr = element.getAttribute("data-bind");
|
|
||||||
if (attr && attr.includes("visible: allowContacts")) {
|
for (i = 0; i < container.children.length; i++) {
|
||||||
element.remove();
|
const element = container.children[i];
|
||||||
break;
|
const attr = element.getAttribute("data-bind");
|
||||||
}
|
if (attr && attr.includes("visible: allowContacts")) {
|
||||||
|
element.remove();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -29,14 +31,16 @@
|
||||||
addEventListener('rl-view-model', e => {
|
addEventListener('rl-view-model', e => {
|
||||||
if ('PopupsCompose' === e.detail.viewModelTemplateID) {
|
if ('PopupsCompose' === e.detail.viewModelTemplateID) {
|
||||||
const container = e.detail.viewModelDom.querySelector('.pull-right');
|
const container = e.detail.viewModelDom.querySelector('.pull-right');
|
||||||
if (container) {
|
if(!container) {
|
||||||
for (i = 0; i < container.children.length; i++) {
|
return;
|
||||||
const element = container.children[i];
|
}
|
||||||
const attr = element.getAttribute("data-bind");
|
|
||||||
if (attr && attr.includes("visible: allowContacts")) {
|
for (i = 0; i < container.children.length; i++) {
|
||||||
element.remove();
|
const element = container.children[i];
|
||||||
break;
|
const attr = element.getAttribute("data-bind");
|
||||||
}
|
if (attr && attr.includes("visible: allowContacts")) {
|
||||||
|
element.remove();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
42
plugins/nextcloud/js/nextcloudAddressbook.js
Normal file
42
plugins/nextcloud/js/nextcloudAddressbook.js
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
(rl => {
|
||||||
|
if (rl) {
|
||||||
|
addEventListener('rl-view-model', e => {
|
||||||
|
if ('SettingsContacts' === e.detail.viewModelTemplateID) {
|
||||||
|
const container = e.detail.viewModelDom.querySelector('.form-horizontal');
|
||||||
|
if (!container) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.pluginRemoteRequest((iError, oData) => {
|
||||||
|
if (iError) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mainDivElement = Element.fromHTML('<div class="control-group">'
|
||||||
|
+ '<label>' + rl.i18n("NEXTCLOUD/ADDRESS_BOOK") + '</label>'
|
||||||
|
+ '</div>');
|
||||||
|
|
||||||
|
const selectElement = Element.fromHTML('<select></select>');
|
||||||
|
|
||||||
|
const addressbooks = JSON.parse(oData.Result.addressbooks);
|
||||||
|
addressbooks.forEach(addressbook => {
|
||||||
|
if (addressbook.selected) {
|
||||||
|
selectElement.append(Element.fromHTML('<option value="' + addressbook.uri + '" selected="selected">' + addressbook.name + '</option>'));
|
||||||
|
} else {
|
||||||
|
selectElement.append(Element.fromHTML('<option value="' + addressbook.uri + '">' + addressbook.name + '</option>'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
selectElement.onchange = function() {
|
||||||
|
rl.pluginRemoteRequest(() => { }, 'NextcloudUpdateAddressBook', {
|
||||||
|
uri: selectElement.value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
mainDivElement.append(selectElement);
|
||||||
|
container.append(mainDivElement);
|
||||||
|
}, "NextcloudGetAddressBooks");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})(window.rl);
|
||||||
Loading…
Add table
Add a link
Reference in a new issue