diff --git a/plugins/nextcloud/NextcloudAddressBook.php b/plugins/nextcloud/NextcloudAddressBook.php index 7c8e4afb6..90a8331fe 100644 --- a/plugins/nextcloud/NextcloudAddressBook.php +++ b/plugins/nextcloud/NextcloudAddressBook.php @@ -5,15 +5,15 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInterface { use RainLoop\Providers\AddressBook\CardDAV; - private $contactsManager; - private const SETTINGS_KEY = 'nextCloudAddressBookUri'; + private const SETTINGS_KEY = 'nextcloudAddressBookUri'; private string $defaultUri = 'webmail'; private string $defaultName = 'WebMail'; private string $defaultDescription = 'Recipients from snappymail'; private bool $ignoreSystemAddressBook = true; + private $contactsManager; function __construct(string $defaultUri = 'webmail', string $defaultName = 'WebMail', string $defaultDescription = 'Recipients from snappymail', bool $ignoreSystemAddressBook = true) { @@ -25,14 +25,21 @@ function __construct(string $defaultUri = 'webmail', string $defaultName = 'WebM $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) { - foreach ($this->contactsManager->getUserAddressBooks() as $addressBook) { + foreach ($this->getContactsManager()->getUserAddressBooks() as $addressBook) { if ($addressBook->isSystemAddressBook()) { - $this->contactsManager->unregisterAddressBook($addressBook); + $this->getContactsManager()->unregisterAddressBook($addressBook); } } } @@ -53,63 +60,63 @@ private function GetSavedAddressBookKey(): string return $addressBookId['id']; } - public function IsSupported(): bool + public function IsSupported() : bool { // Maybe just return true, contacts app is just a frontend - //return \OC::$server->getAppManager()->isEnabledForUser('contacts'); - return true; + return \OC::$server->getAppManager()->isEnabledForUser('contacts'); } - public function SetEmail(string $sEmail) : bool { + public function SetEmail(string $sEmail) : bool + { return true; } - public function Sync(): bool + public function Sync() : bool { return false; } - public function Export(string $sType = 'vcf'): bool + public function Export(string $sType = 'vcf') : bool { return false; } - public function ContactSave(Contact $oContact): bool + public function ContactSave(Contact $oContact) : bool { return false; } - public function DeleteContacts(array $aContactIds): bool + public function DeleteContacts(array $aContactIds) : bool { return false; } - public function DeleteAllContacts(string $sEmail): bool + public function DeleteAllContacts(string $sEmail) : bool { 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 []; } - public function GetContactByEmail(string $sEmail): ?Contact + public function GetContactByEmail(string $sEmail) : ?Contact { return null; } - public function GetContactByID($mID, bool $bIsStrID = false): ?Contact + public function GetContactByID($mID, bool $bIsStrID = false) : ?Contact { return null; } - public function GetSuggestions(string $sSearch, int $iLimit = 20): array + public function GetSuggestions(string $sSearch, int $iLimit = 20) : array { return []; } - private function GetEmailObjects(array $aEmails): array + private function GetEmailObjects(array $aEmails) : array { $aEmailsObjects = \array_map(function ($mItem) { $oResult = null; @@ -131,7 +138,7 @@ private function GetEmailObjects(array $aEmails): array * Add/increment email address usage * 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) { $aEmailsObjects = $this->GetEmailObjects($aEmails); @@ -139,53 +146,61 @@ public function IncFrec(array $aEmails, bool $bCreateAuto = true): bool if (!count($aEmailsObjects)) { return false; } - foreach ($aEmailsObjects as $oEmail) { - if ('' === \trim($oEmail->GetEmail())) { - 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()); + foreach ($aEmailsObjects as $oEmail) { + $this->createOrUpdateContact($oEmail); } + return true; } + 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 ''; } - private function Account(): \RainLoop\Model\Account + private function Account() : \RainLoop\Model\Account { return \RainLoop\Api::Actions()->getAccountFromToken(); } - private function SettingsProvider(): \RainLoop\Providers\Settings + private function SettingsProvider() : \RainLoop\Providers\Settings { return \RainLoop\Api::Actions()->SettingsProvider(true); } - private function Settings(): \RainLoop\Settings + private function Settings() : \RainLoop\Settings { return $this->SettingsProvider()->Load($this->Account()); } - private function GetSavedUri(): string + private function GetSavedUri() : string { return $this->Settings()->GetConf(self::SETTINGS_KEY, $this->defaultUri); } diff --git a/plugins/nextcloud/index.php b/plugins/nextcloud/index.php index 229e534bd..28adf35fb 100644 --- a/plugins/nextcloud/index.php +++ b/plugins/nextcloud/index.php @@ -10,13 +10,27 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin DESCRIPTION = 'Integrate with Nextcloud v20+', REQUIRED = '2.36.2'; + private const IGNORE_SYSTEM_ADDRESSBOOK_KEY = 'ignoreSystemAddressbook'; + private const IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE = true; + private const ENABLE_NC_ADDRESSBOOK_KEY = 'enableNcAddressbook'; + 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_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 DEFAULT_ADDRESSBOOK_URI = 'webmail'; - private const ADDRESSBOOK_SETTINGS_KEY = 'nextCloudAddressBookUri'; - public function Init(): void + private const ADDRESSBOOK_SETTINGS_KEY = 'nextcloudAddressBookUri'; + + public function Init() : void { if (static::IsIntegrated()) { \SnappyMail\Log::debug('Nextcloud', 'integrated'); @@ -42,19 +56,19 @@ public function Init(): void $this->addTemplate('templates/PopupsNextcloudFiles.html'); $this->addTemplate('templates/PopupsNextcloudCalendars.html'); - // $this->addHook('login.credentials.step-2', 'loginCredentials2'); - // $this->addHook('login.credentials', 'loginCredentials'); +// $this->addHook('login.credentials.step-2', 'loginCredentials2'); +// $this->addHook('login.credentials', 'loginCredentials'); $this->addHook('imap.before-login', 'beforeLogin'); $this->addHook('smtp.before-login', 'beforeLogin'); $this->addHook('sieve.before-login', 'beforeLogin'); - if ($this->Config()->Get('plugin', 'enableNcAddressbook', false)) { - $this->addJs('js/addressbook.js'); + if ($this->Config()->Get('plugin', self::ENABLE_NC_ADDRESSBOOK_KEY, self::ENABLE_NC_ADDRESSBOOK_DEFAULT_VALUE)) { + $this->addJs('js/nextcloudAddressbook.js'); $this->addJsonHook('NextcloudGetAddressBooks', 'GetAddressBooks'); $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'); } } else { @@ -70,9 +84,9 @@ public function GetAddressBooks() $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); - $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) { if ($ignoreSystemAddressbook && $addressBook->isSystemAddressBook()) { @@ -96,7 +110,7 @@ public function GetAddressBooks() )); } - public function UpdateAddressBook(): array + public function UpdateAddressBook() : array { $uri = $this->jsonParam('uri'); $oSettings = $this->UserSettings(); @@ -115,7 +129,7 @@ public function ContentSecurityPolicy(\SnappyMail\HTTP\CSP $CSP) } } - public function Supported(): string + public function Supported() : string { return static::IsIntegrated() ? '' : 'Nextcloud not found to use this plugin'; } @@ -130,24 +144,24 @@ public static function 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. * When user changes email address, all settings are gone as the new * _data_/_default_/storage/{domain}/{local-part} is used */ - // $ocUser = \OC::$server->getUserSession()->getUser(); - // $sEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress() ?: $sEmail; +// $ocUser = \OC::$server->getUserSession()->getUser(); +// $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(); $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 $config = \OC::$server->getConfig(); @@ -164,12 +178,11 @@ public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetCl // Only login with OIDC access token if // 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 - if ( - \OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-autologin-oidc', false) - && \OC::$server->getSession()->get('is_oidc') - && $sNcEmail === $oSettings->username - && !$bAccountDefinedExplicitly - // && $oClient->supportsAuthType('OAUTHBEARER') // v2.28 + if (\OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-autologin-oidc', false) + && \OC::$server->getSession()->get('is_oidc') + && $sNcEmail === $oSettings->username + && !$bAccountDefinedExplicitly +// && $oClient->supportsAuthType('OAUTHBEARER') // v2.28 ) { $sAccessToken = \OC::$server->getSession()->get('oidc_access_token'); if ($sAccessToken) { @@ -184,7 +197,7 @@ public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetCl \OC::$server->getLDAPProvider(); */ - public function NextcloudAttachFile(): array + public function NextcloudAttachFile() : array { $aResult = [ 'success' => false, @@ -208,10 +221,10 @@ public function NextcloudAttachFile(): array return $this->jsonResponse(__FUNCTION__, $aResult); } - public function NextcloudSaveMsg(): array + public function NextcloudSaveMsg() : array { $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', ''); $aValues = \json_decode(\MailSo\Base\Utils::UrlSafeBase64Decode($msgHash), true); $aResult = [ @@ -265,14 +278,14 @@ public function DoAttachmentsActions(\SnappyMail\AttachmentsAction $data) foreach ($data->items as $aItem) { $sSavedFileName = empty($aItem['fileName']) ? 'file.dat' : $aItem['fileName']; if (!empty($aItem['data'])) { - $sSavedFileNameFull = static::SmartFileExists($sSaveFolder . '/' . $sSavedFileName, $oFiles); + $sSavedFileNameFull = static::SmartFileExists($sSaveFolder.'/'.$sSavedFileName, $oFiles); if (!$oFiles->file_put_contents($sSavedFileNameFull, $aItem['data'])) { $data->result = false; } } else if (!empty($aItem['fileHash'])) { $fFile = $data->filesProvider->GetFile($data->account, $aItem['fileHash'], 'rb'); if (\is_resource($fFile)) { - $sSavedFileNameFull = static::SmartFileExists($sSaveFolder . '/' . $sSavedFileName, $oFiles); + $sSavedFileNameFull = static::SmartFileExists($sSaveFolder.'/'.$sSavedFileName, $oFiles); if (!$oFiles->file_put_contents($sSavedFileNameFull, $fFile)) { $data->result = false; } @@ -286,19 +299,19 @@ public function DoAttachmentsActions(\SnappyMail\AttachmentsAction $data) } } - public function FilterAppData($bAdmin, &$aResult): void + public function FilterAppData($bAdmin, &$aResult) : void { if (!$bAdmin && \is_array($aResult)) { $ocUser = \OC::$server->getUserSession()->getUser(); $sUID = $ocUser->getUID(); $oUrlGen = \OC::$server->getURLGenerator(); $sWebDAV = $oUrlGen->getAbsoluteURL($oUrlGen->linkTo('', 'remote.php') . '/dav'); - // $sWebDAV = \OCP\Util::linkToRemote('dav'); +// $sWebDAV = \OCP\Util::linkToRemote('dav'); $aResult['Nextcloud'] = [ 'UID' => $sUID, 'WebDAV' => $sWebDAV, 'CalDAV' => $this->Config()->Get('plugin', 'calendar', false) - // 'WebDAV_files' => $sWebDAV . '/files/' . $sUID +// 'WebDAV_files' => $sWebDAV . '/files/' . $sUID ]; if (empty($aResult['Auth'])) { $config = \OC::$server->getConfig(); @@ -320,9 +333,9 @@ public function FilterAppData($bAdmin, &$aResult): void } if (!$sEmail) { $sEmail = $ocUser->getEMailAddress(); - // ?: $ocUser->getPrimaryEMailAddress(); +// ?: $ocUser->getPrimaryEMailAddress(); } - /* +/* if ($config->getAppValue('snappymail', 'snappymail-autologin-oidc', false)) { if (\OC::$server->getSession()->get('is_oidc')) { $sEmail = "{$sUID}@nextcloud"; @@ -369,7 +382,7 @@ public function FilterAppData($bAdmin, &$aResult): void } } - public function FilterLanguage(&$sLanguage, $bAdmin): void + public function FilterLanguage(&$sLanguage, $bAdmin) : void { if (!\RainLoop\Api::Config()->Get('webmail', 'allow_languages_on_settings', true)) { $aResultLang = \SnappyMail\L10n::getLanguages($bAdmin); @@ -392,7 +405,7 @@ public function FilterLanguage(&$sLanguage, $bAdmin): void * * @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 if (\in_array($langCode, $languagesArray)) { @@ -429,20 +442,20 @@ public function MainFabrica(string $sName, &$mResult) } include_once __DIR__ . '/NextcloudContactsSuggestions.php'; $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)) { $mResult = array(); } include_once __DIR__ . '/NextcloudAddressBook.php'; - $ignoreSystemAddressbook = $this->Config()->Get('plugin', 'ignoreSystemAddressbook', true); - $defaultName = $this->Config()->Get('plugin', 'defaultNCAddressbookName', self::DEFAULT_ADDRESSBOOK_NAME); - $defaultDescription = $this->Config()->Get('plugin', 'defaultNCAddressbookDescription', self::DEFAULT_ADDRESSBOOK_DESCRIPTION); - $defaultUri = $this->Config()->Get('plugin', 'defaultNCAddressbookUri', self::DEFAULT_ADDRESSBOOK_URI); + $ignoreSystemAddressbook = $this->Config()->Get('plugin', self::IGNORE_SYSTEM_ADDRESSBOOK_KEY, self::IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE); + $defaultName = $this->Config()->Get('plugin', self::DEFAULT_ADDRESSBOOK_NAME_KEY, self::DEFAULT_ADDRESSBOOK_NAME); + $defaultDescription = $this->Config()->Get('plugin', self::DEFAULT_ADDRESSBOOK_DESCRIPTION_KEY, self::DEFAULT_ADDRESSBOOK_DESCRIPTION); + $defaultUri = $this->Config()->Get('plugin', self::DEFAULT_ADDRESSBOOK_URI_KEY, self::DEFAULT_ADDRESSBOOK_URI); $mResult = new NextcloudAddressBook( $defaultUri, @@ -460,16 +473,16 @@ public function MainFabrica(string $sName, &$mResult) } } - protected function configMapping(): array + protected function configMapping() : array { return array( \RainLoop\Plugins\Property::NewInstance('suggestions')->SetLabel('Suggestions') ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) ->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) - ->SetDefaultValue(true), - /* + ->SetDefaultValue(self::IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE), +/* \RainLoop\Plugins\Property::NewInstance('storage')->SetLabel('Use Nextcloud user ID in config storage path') ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) ->SetDefaultValue(false) @@ -478,29 +491,29 @@ protected function configMapping(): array ->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL) ->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) - ->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) - ->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) ->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) ->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) - ->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)); @@ -514,10 +527,11 @@ private static function SmartFileExists(string $sFilePath, $oFiles): string while (true) { ++$iIndex; - $sFilePathNew = $aFileInfo['dirname'] . '/' . - \preg_replace('/\(\d{1,2}\)$/', '', $aFileInfo['filename']) . - ' (' . $iIndex . ')' . - (empty($aFileInfo['extension']) ? '' : '.' . $aFileInfo['extension']); + $sFilePathNew = $aFileInfo['dirname'].'/'. + \preg_replace('/\(\d{1,2}\)$/', '', $aFileInfo['filename']). + ' ('.$iIndex.')'. + (empty($aFileInfo['extension']) ? '' : '.'.$aFileInfo['extension']) + ; if (!$oFiles->file_exists($sFilePathNew)) { return $sFilePathNew; } @@ -528,17 +542,17 @@ private static function SmartFileExists(string $sFilePath, $oFiles): string return $sFilePath; } - private function Account(): \RainLoop\Model\Account + private function Account() : \RainLoop\Model\Account { return \RainLoop\Api::Actions()->getAccountFromToken(); } - private function SettingsProvider(): \RainLoop\Providers\Settings + private function SettingsProvider() : \RainLoop\Providers\Settings { return \RainLoop\Api::Actions()->SettingsProvider(true); } - private function UserSettings(): \RainLoop\Settings + private function UserSettings() : \RainLoop\Settings { return $this->SettingsProvider()->Load($this->Account()); } diff --git a/plugins/nextcloud/js/addressbook.js b/plugins/nextcloud/js/addressbook.js deleted file mode 100644 index c871c0928..000000000 --- a/plugins/nextcloud/js/addressbook.js +++ /dev/null @@ -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('
' - + '' - + '
'); - - const selectElement = Element.fromHTML(''); - - const books = JSON.parse(oData.Result.addressbooks); - books.forEach(book => { - if (book.selected) { - selectElement.append(Element.fromHTML('')); - } else { - selectElement.append(Element.fromHTML('')); - } - }); - - selectElement.onchange = function() { - rl.pluginRemoteRequest(() => { }, 'NextcloudUpdateAddressBook', { - uri: selectElement.value - }); - } - - mainDivElement.append(selectElement); - container.append(mainDivElement); - } - }, "NextcloudGetAddressBooks"); - } - } - }); - } -})(window.rl); diff --git a/plugins/nextcloud/js/hideInhouseAddressbook.js b/plugins/nextcloud/js/hideInhouseAddressbook.js index ed8197e18..37feb7dc9 100644 --- a/plugins/nextcloud/js/hideInhouseAddressbook.js +++ b/plugins/nextcloud/js/hideInhouseAddressbook.js @@ -13,14 +13,16 @@ addEventListener('rl-view-model', e => { if ('SystemDropDown' === e.detail.viewModelTemplateID) { const container = e.detail.viewModelDom.querySelector('.dropdown-menu'); - if (container) { - for (i = 0; i < container.children.length; i++) { - const element = container.children[i]; - const attr = element.getAttribute("data-bind"); - if (attr && attr.includes("visible: allowContacts")) { - element.remove(); - break; - } + if (!container) { + return; + } + + for (i = 0; i < container.children.length; i++) { + const element = container.children[i]; + const attr = element.getAttribute("data-bind"); + if (attr && attr.includes("visible: allowContacts")) { + element.remove(); + break; } } } @@ -29,14 +31,16 @@ addEventListener('rl-view-model', e => { if ('PopupsCompose' === e.detail.viewModelTemplateID) { const container = e.detail.viewModelDom.querySelector('.pull-right'); - if (container) { - for (i = 0; i < container.children.length; i++) { - const element = container.children[i]; - const attr = element.getAttribute("data-bind"); - if (attr && attr.includes("visible: allowContacts")) { - element.remove(); - break; - } + if(!container) { + return; + } + + for (i = 0; i < container.children.length; i++) { + const element = container.children[i]; + const attr = element.getAttribute("data-bind"); + if (attr && attr.includes("visible: allowContacts")) { + element.remove(); + break; } } } diff --git a/plugins/nextcloud/js/nextcloudAddressbook.js b/plugins/nextcloud/js/nextcloudAddressbook.js new file mode 100644 index 000000000..0c3684ce0 --- /dev/null +++ b/plugins/nextcloud/js/nextcloudAddressbook.js @@ -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('
' + + '' + + '
'); + + const selectElement = Element.fromHTML(''); + + const addressbooks = JSON.parse(oData.Result.addressbooks); + addressbooks.forEach(addressbook => { + if (addressbook.selected) { + selectElement.append(Element.fromHTML('')); + } else { + selectElement.append(Element.fromHTML('')); + } + }); + + selectElement.onchange = function() { + rl.pluginRemoteRequest(() => { }, 'NextcloudUpdateAddressBook', { + uri: selectElement.value + }); + } + + mainDivElement.append(selectElement); + container.append(mainDivElement); + }, "NextcloudGetAddressBooks"); + } + }); + } +})(window.rl);