From a467946c5151074271887f886f2e267e9dae708f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Gomes=20da=20Silva=20Lisboa?= Date: Wed, 5 Sep 2018 15:23:23 -0300 Subject: [PATCH] New circles are treated as an "all user" activity - but no option for this being on/off #204 --- js/admin.js | 11 ++++++++- js/circles.app.elements.js | 6 ++++- js/circles.app.js | 1 + js/circles.app.settings.js | 4 ++++ lib/Controller/NavigationController.php | 1 + lib/Controller/SettingsController.php | 8 ++++++- lib/Service/ConfigService.php | 18 +++++++++++++- lib/Service/EventsService.php | 31 +++++++++++++++---------- templates/navigate.php | 5 ++++ templates/settings.admin.php | 5 ++++ 10 files changed, 74 insertions(+), 16 deletions(-) diff --git a/js/admin.js b/js/admin.js index cbfdcb19..d89b2fbf 100644 --- a/js/admin.js +++ b/js/admin.js @@ -33,7 +33,8 @@ var elements = { // test_async_wait: null, members_limit: null, allow_linked_groups: null, - allow_federated_circles: null + allow_federated_circles: null, + disable_notification_for_seen_users: null }; @@ -46,6 +47,7 @@ $(document).ready(function () { elements.members_limit = $('#members_limit'); elements.allow_linked_groups = $('#allow_linked_groups'); elements.allow_federated_circles = $('#allow_federated_circles'); + elements.disable_notification_for_seen_users = $('#disable_notification_for_seen_users'); // elements.test_async_wait.hide().on('click', function () { // self.refreshResult(); @@ -81,6 +83,10 @@ $(document).ready(function () { elements.allow_federated_circles.on('change', function () { saveChange(); }); + + elements.disable_notification_for_seen_users.on('change', function () { + saveChange(); + }); saveChange = function () { $.ajax({ @@ -91,12 +97,15 @@ $(document).ready(function () { allow_linked_groups: (elements.allow_linked_groups.is( ':checked')) ? '1' : '0', allow_federated_circles: (elements.allow_federated_circles.is( + ':checked')) ? '1' : '0', + disable_notification_for_seen_users: (elements.disable_notification_for_seen_users.is( ':checked')) ? '1' : '0' } }).done(function (res) { elements.members_limit.val(res.membersLimit); elements.allow_linked_groups.prop('checked', (res.allowLinkedGroups === '1')); elements.allow_federated_circles.prop('checked', (res.allowFederatedCircles === '1')); + elements.disable_notification_for_seen_users.prop('checked', (res.disableNotificationForSeenUsers === '1')); }); }; diff --git a/js/circles.app.elements.js b/js/circles.app.elements.js index 31d42df8..82f09328 100644 --- a/js/circles.app.elements.js +++ b/js/circles.app.elements.js @@ -71,13 +71,15 @@ var elements = { settingsName: null, settingsDesc: null, settingsLimit: null, - settingsEntryLimit: null, + settingsEntryLimit: null, settingsLink: null, settingsLinkAuto: null, settingsLinkFiles: null, + settingsNotification: null, settingsEntryLink: null, settingsEntryLinkAuto: null, settingsEntryLinkFiles: null, + settingsEntryNotification: null, settingsSave: null, addMember: null, @@ -139,9 +141,11 @@ var elements = { elements.settingsLink = $('#settings-link'); elements.settingsLinkAuto = $('#settings-link-auto'); elements.settingsLinkFiles = $('#settings-link-files'); + elements.settingsNotification = $('#settings-notification'); elements.settingsEntryLink = $('#settings-entry-link'); elements.settingsEntryLinkAuto = $('#settings-entry-link-auto'); elements.settingsEntryLinkFiles = $('#settings-entry-link-files'); + elements.settingsEntryNotification = $('#settings-entry-notification'); elements.settingsSave = $('#settings-submit'); elements.addMember = $('#addmember'); diff --git a/js/circles.app.js b/js/circles.app.js index 4f2c837a..ad72bf2f 100644 --- a/js/circles.app.js +++ b/js/circles.app.js @@ -60,6 +60,7 @@ var curr = { allowed_linked_groups: 0, allowed_federated_circles: 0, allowed_circles: 0, + disabled_notification_for_seen_users: 0, defineCircle: function (data) { curr.circle = data.circle_id; diff --git a/js/circles.app.settings.js b/js/circles.app.settings.js index 4de11d98..db65cf2e 100644 --- a/js/circles.app.settings.js +++ b/js/circles.app.settings.js @@ -61,6 +61,8 @@ var settings = { (curr.circleSettings['allow_links_auto'] === 'true')); elements.settingsLinkFiles.prop('checked', (curr.circleSettings['allow_links_files'] === 'true')); + elements.settingsNotification.prop('checked', + (curr.circleSettings['disable_notification_for_seen_users'] === 'true')); elements.settingsLink.on('change', function () { settings.interactUISettings(); @@ -86,6 +88,8 @@ var settings = { (elements.settingsLink.is(":checked"))); settings.enableSetting(elements.settingsEntryLinkFiles, elements.settingsLinkFiles, (elements.settingsLink.is(":checked"))); + settings.enableSetting(elements.settingsEntryNotification, elements.settingsNotification, + (elements.settingsNotification.is(":checked"))); }, enableSetting: function (entry, input, enable) { diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index fb14afb6..d7f5cb67 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -84,6 +84,7 @@ class NavigationController extends BaseController { 'members_list' => $this->configService->getAppValue(ConfigService::CIRCLES_MEMBERS_LIMIT), 'allowed_linked_groups' => $this->configService->getAppValue(ConfigService::CIRCLES_ALLOW_LINKED_GROUPS), 'allowed_federated_circles' => $this->configService->getAppValue(ConfigService::CIRCLES_ALLOW_FEDERATED_CIRCLES), + 'disabled_notification_for_seen_users' => $this->configService->getAppValue(ConfigService::CIRCLES_DISABLE_NOTIFICATION_FOR_SEEN_USERS), 'status' => 1 ]; diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 809bd52e..bfab8b02 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -48,6 +48,9 @@ class SettingsController extends Controller { ), 'allowFederatedCircles' => $this->configService->getAppValue( ConfigService::CIRCLES_ALLOW_FEDERATED_CIRCLES + ), + 'disableNotificationForSeenUsers' => $this->configService->getAppValue( + ConfigService::CIRCLES_DISABLE_NOTIFICATION_FOR_SEEN_USERS ) ]; @@ -55,7 +58,7 @@ class SettingsController extends Controller { } - public function setSettings($members_limit, $allow_linked_groups, $allow_federated_circles) { + public function setSettings($members_limit, $allow_linked_groups, $allow_federated_circles, $disable_notification_for_seen_users) { $this->configService->setAppValue( ConfigService::CIRCLES_MEMBERS_LIMIT, $members_limit ); @@ -65,6 +68,9 @@ class SettingsController extends Controller { $this->configService->setAppValue( ConfigService::CIRCLES_ALLOW_FEDERATED_CIRCLES, $allow_federated_circles ); + $this->configService->setAppValue( + ConfigService::CIRCLES_DISABLE_NOTIFICATION_FOR_SEEN_USERS, $disable_notification_for_seen_users + ); return $this->getSettings(); } diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 93eb703e..f4b37660 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -41,6 +41,7 @@ class ConfigService { const CIRCLES_ALLOW_LINKED_GROUPS = 'allow_linked_groups'; const CIRCLES_ALLOW_NON_SSL_LINKS = 'allow_non_ssl_links'; const CIRCLES_NON_SSL_LOCAL = 'local_is_non_ssl'; + const CIRCLES_DISABLE_NOTIFICATION_FOR_SEEN_USERS = 'disable_notification_for_seen_users'; const CIRCLES_TEST_ASYNC_LOCK = 'test_async_lock'; const CIRCLES_TEST_ASYNC_INIT = 'test_async_init'; @@ -55,7 +56,8 @@ class ConfigService { self::CIRCLES_ALLOW_LINKED_GROUPS => '0', self::CIRCLES_ALLOW_FEDERATED_CIRCLES => '0', self::CIRCLES_ALLOW_NON_SSL_LINKS => '0', - self::CIRCLES_NON_SSL_LOCAL => '0' + self::CIRCLES_NON_SSL_LOCAL => '0', + self::CIRCLES_DISABLE_NOTIFICATION_FOR_SEEN_USERS => '0', ]; /** @var string */ @@ -87,6 +89,9 @@ class ConfigService { /** @var int */ private $localNonSSL = -1; + + /** @var int */ + private $disabledNotificationForSeenUsers = -1; /** * ConfigService constructor. @@ -181,6 +186,17 @@ class ConfigService { return ($this->allowedNonSSLLinks === 1); } + /** + * @return bool + */ + public function isDisabledNotificationForSeenUsers() { + if ($this->disabledNotificationForSeenUsers === -1) { + $this->disabledNotificationForSeenUsers = + (int)$this->getAppValue(self::CIRCLES_DISABLE_NOTIFICATION_FOR_SEEN_USERS); + } + + return ($this->disabledNotificationForSeenUsers === 1); + } /** * @param string $remote diff --git a/lib/Service/EventsService.php b/lib/Service/EventsService.php index 4e491769..11820722 100644 --- a/lib/Service/EventsService.php +++ b/lib/Service/EventsService.php @@ -100,22 +100,29 @@ class EventsService { * @param Circle $circle */ public function onCircleCreation(Circle $circle) { - if ($circle->getType() !== Circle::CIRCLES_PUBLIC - && $circle->getType() !== Circle::CIRCLES_CLOSED - ) { - return; - } - $event = $this->generateEvent('circles_as_member'); $event->setSubject('circle_create', ['circle' => json_encode($circle)]); - $this->userManager->callForSeenUsers( - function($user) use ($event) { - /** @var IUser $user */ - $this->publishEvent($event, [$user]); - } - ); + if ($circle->getType() !== Circle::CIRCLES_PUBLIC + && $circle->getType() !== Circle::CIRCLES_CLOSED + ) { + $this->publishEvent($event, [\OC::$server->getUserSession()->getUser()]); + $this->dispatch('\OCA\Circles::onCircleCreation', ['circle' => $circle]); + return; + } + $disableNotificationForSeenUsers = \OC::$server->getAppConfig()->getValue('circles', 'disable_notification_for_seen_users', false); + if ($disableNotificationForSeenUsers) { + $this->publishEvent($event, [\OC::$server->getUserSession()->getUser()]); + } else { + $this->userManager->callForSeenUsers( + function($user) use ($event) { + /** @var IUser $user */ + $this->publishEvent($event, [$user]); + } + ); + } + $this->dispatch('\OCA\Circles::onCircleCreation', ['circle' => $circle]); } diff --git a/templates/navigate.php b/templates/navigate.php index 8eea3478..00dc5d70 100644 --- a/templates/navigate.php +++ b/templates/navigate.php @@ -407,6 +407,11 @@ style(Application::APP_NAME, 'navigation'); + + t('Disable notification for seen users.')); ?> + + + diff --git a/templates/settings.admin.php b/templates/settings.admin.php index c97834b2..2a65a802 100644 --- a/templates/settings.admin.php +++ b/templates/settings.admin.php @@ -25,4 +25,9 @@ style(Application::APP_NAME, 'admin'); t('Circles from different Nextclouds can be linked together.')); ?>

+

+ + + t('Disable notification for seen users.')); ?> +