diff options
-rw-r--r-- | lib/Controller/PageController.php | 45 | ||||
-rw-r--r-- | src/services/isContactsInteractionEnabled.js | 26 | ||||
-rw-r--r-- | src/views/Contacts.vue | 35 |
3 files changed, 77 insertions, 29 deletions
diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 60fd2e8b..95fca90b 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -24,7 +24,7 @@ namespace OCA\Contacts\Controller; -use OCA\Contacts\Service\SocialApiService; +use OCP\App\IAppManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; @@ -52,20 +52,24 @@ class PageController extends Controller { /** @var SocialApiService */ private $socialApiService; + /** @var IAppManager */ + private $appManager; + public function __construct(IRequest $request, IConfig $config, IInitialStateService $initialStateService, IFactory $languageFactory, IUserSession $userSession, - SocialApiService $socialApiService) { + SocialApiService $socialApiService, + IAppManager $appManager) { parent::__construct(Application::APP_ID, $request); - $this->appName = Application::APP_ID; $this->config = $config; $this->initialStateService = $initialStateService; $this->languageFactory = $languageFactory; $this->userSession = $userSession; $this->socialApiService = $socialApiService; + $this->appManager = $appManager; } /** @@ -82,23 +86,24 @@ class PageController extends Controller { } $locales = $this->languageFactory->findAvailableLocales(); - $defaultProfile = $this->config->getAppValue($this->appName, 'defaultProfile', 'HOME'); + $defaultProfile = $this->config->getAppValue(Application::APP_ID, 'defaultProfile', 'HOME'); $supportedNetworks = $this->socialApiService->getSupportedNetworks(); - $syncAllowedByAdmin = $this->config->getAppValue($this->appName, 'allowSocialSync', 'yes'); // allow users to retrieve avatars from social networks (default: yes) - $bgSyncEnabledByUser = $this->config->getUserValue($userId, $this->appName, 'enableSocialSync', 'no'); // automated background syncs for social avatars (default: no) - - $this->initialStateService->provideInitialState($this->appName, 'locales', $locales); - $this->initialStateService->provideInitialState($this->appName, 'defaultProfile', $defaultProfile); - $this->initialStateService->provideInitialState($this->appName, 'supportedNetworks', $supportedNetworks); - $this->initialStateService->provideInitialState($this->appName, 'locales', $locales); - $this->initialStateService->provideInitialState($this->appName, 'defaultProfile', $defaultProfile); - $this->initialStateService->provideInitialState($this->appName, 'supportedNetworks', $supportedNetworks); - $this->initialStateService->provideInitialState($this->appName, 'allowSocialSync', $syncAllowedByAdmin); - $this->initialStateService->provideInitialState($this->appName, 'enableSocialSync', $bgSyncEnabledByUser); - - Util::addScript($this->appName, 'contacts'); - Util::addStyle($this->appName, 'contacts'); - - return new TemplateResponse($this->appName, 'main'); + $syncAllowedByAdmin = $this->config->getAppValue(Application::APP_ID, 'allowSocialSync', 'yes'); // allow users to retrieve avatars from social networks (default: yes) + $bgSyncEnabledByUser = $this->config->getUserValue($userId, Application::APP_ID, 'enableSocialSync', 'no'); // automated background syncs for social avatars (default: no) + + $this->initialStateService->provideInitialState(Application::APP_ID, 'locales', $locales); + $this->initialStateService->provideInitialState(Application::APP_ID, 'defaultProfile', $defaultProfile); + $this->initialStateService->provideInitialState(Application::APP_ID, 'supportedNetworks', $supportedNetworks); + $this->initialStateService->provideInitialState(Application::APP_ID, 'locales', $locales); + $this->initialStateService->provideInitialState(Application::APP_ID, 'defaultProfile', $defaultProfile); + $this->initialStateService->provideInitialState(Application::APP_ID, 'supportedNetworks', $supportedNetworks); + $this->initialStateService->provideInitialState(Application::APP_ID, 'allowSocialSync', $syncAllowedByAdmin); + $this->initialStateService->provideInitialState(Application::APP_ID, 'enableSocialSync', $bgSyncEnabledByUser); + $this->initialStateService->provideInitialState(Application::APP_ID, 'contactsinteraction', $this->appManager->isEnabledForUser('contactsinteraction') === true); + + Util::addScript(Application::APP_ID, 'contacts'); + Util::addStyle(Application::APP_ID, 'contacts'); + + return new TemplateResponse(Application::APP_ID, 'main'); } } diff --git a/src/services/isContactsInteractionEnabled.js b/src/services/isContactsInteractionEnabled.js new file mode 100644 index 00000000..f6434245 --- /dev/null +++ b/src/services/isContactsInteractionEnabled.js @@ -0,0 +1,26 @@ +/** + * @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com> + * + * @author John Molakvoæ <skjnldsv@protonmail.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +import { loadState } from '@nextcloud/initial-state' + +const contactsinteraction = loadState('contacts', 'contactsinteraction') +export default contactsinteraction diff --git a/src/views/Contacts.vue b/src/views/Contacts.vue index 082f42be..23b1a500 100644 --- a/src/views/Contacts.vue +++ b/src/views/Contacts.vue @@ -63,6 +63,21 @@ </AppNavigationCounter> </AppNavigationItem> + <!-- Recently contacted group --> + <AppNavigationItem + v-if="isContactsInteractionEnabled && recentlyContactedContacts.contacts.length > 0" + id="recentlycontacted" + :title="t('contactsinteraction', 'Recently contacted')" + :to="{ + name: 'group', + params: { selectedGroup: t('contactsinteraction', 'Recently contacted') }, + }" + icon="icon-recent-actors"> + <AppNavigationCounter slot="counter"> + {{ recentlyContactedContacts.contacts.length }} + </AppNavigationCounter> + </AppNavigationItem> + <AppNavigationSpacer /> <!-- Custom groups --> @@ -75,7 +90,7 @@ <ActionButton icon="icon-add" @click="addContactsToGroup(group)"> - {{ t('contacts', 'Add contacts to this group') }} + {{ t('contacts', 'Add contacts') }} </ActionButton> <ActionButton icon="icon-download" @@ -197,6 +212,7 @@ import rfcProps from '../models/rfcProps' import client from '../services/cdav' import appendContactToGroup from '../services/appendContactToGroup' +import isContactsInteractionEnabled from '../services/isContactsInteractionEnabled' const GROUP_ALL_CONTACTS = t('contacts', 'All contacts') const GROUP_NO_GROUP_CONTACTS = t('contacts', 'Not grouped') @@ -245,6 +261,7 @@ export default { return { GROUP_ALL_CONTACTS, GROUP_NO_GROUP_CONTACTS, + isContactsInteractionEnabled, isCreatingGroup: false, isNewGroupMenuOpen: false, loading: true, @@ -338,25 +355,25 @@ export default { name: 'group', params: { selectedGroup: group.name }, }, - icon: group.name === t('contactsinteraction', 'Recently contacted') - ? 'icon-recent-actors' - : '', toString: () => group.name, }) }) menu.sort() - // Find the Recently Contacted group, delete it from array and put it at first place of the array - const recentlyIndex = menu.findIndex( - group => group.text === t('contactsinteraction', 'Recently contacted') - ) + // Find the Recently Contacted group, delete it from array + const recentlyIndex = menu.findIndex(group => group.name === t('contactsinteraction', 'Recently contacted')) if (recentlyIndex >= 0) { - menu.unshift(menu.splice(recentlyIndex, 1)[0]) + menu.splice(recentlyIndex, 1) } return menu }, + // Recently contacted data + recentlyContactedContacts() { + return this.groups.find(group => group.name === t('contactsinteraction', 'Recently contacted')) + }, + /** * Contacts formatted for the EntityPicker * @returns {Array} |