diff --git a/CHANGELOG.md b/CHANGELOG.md index f5b6c18c76..78f7f77654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ HumHub Changelog - Enh #7243: Server time zone - Enh #7188: Helper for detecting a current path by module/controller/action - Enh #7265: Profile "About" page: don't display the menu if only one entry +- Enh #7269: Remove desktop notifications 1.16.3 (Unreleased) -------------------------- diff --git a/protected/humhub/config/assets-prod.php b/protected/humhub/config/assets-prod.php index e9f67d45ce..4ea987705b 100644 --- a/protected/humhub/config/assets-prod.php +++ b/protected/humhub/config/assets-prod.php @@ -2,7 +2,7 @@ /** * This file is generated by the "yii asset" command. * DO NOT MODIFY THIS FILE DIRECTLY. - * @version 2024-10-08 08:21:19 + * @version 2024-10-22 08:54:08 */ return [ 'app' => [ diff --git a/protected/humhub/modules/installer/libs/InitialData.php b/protected/humhub/modules/installer/libs/InitialData.php index b4ee9a8632..e37d7326c7 100644 --- a/protected/humhub/modules/installer/libs/InitialData.php +++ b/protected/humhub/modules/installer/libs/InitialData.php @@ -73,13 +73,9 @@ class InitialData // Basic Yii::$app->getModule('tour')->settings->set('enable', 1); - // Notification - Yii::$app->getModule('notification')->settings->set('enable_html5_desktop_notifications', 0); - // Avoid warning direct after installation Yii::$app->settings->set('cronLastRun', time()); - // Add Categories $cGeneral = new ProfileFieldCategory(); $cGeneral->title = "General"; diff --git a/protected/humhub/modules/notification/components/NotificationManager.php b/protected/humhub/modules/notification/components/NotificationManager.php index 1a5b88e964..5f68e7a74b 100644 --- a/protected/humhub/modules/notification/components/NotificationManager.php +++ b/protected/humhub/modules/notification/components/NotificationManager.php @@ -381,35 +381,6 @@ class NotificationManager Follow::updateAll(['send_notifications' => 0], ['object_model' => Space::class]); } - /** - * Defines the enable_html5_desktop_notifications setting for the given user or global if no user is given. - * - * @param int $value - * @param User $user - */ - public function setDesktopNoficationSettings($value = 0, User $user = null) - { - /** @var Module $module */ - $module = Yii::$app->getModule('notification'); - $settingManager = ($user) ? $module->settings->user($user) : $module->settings; - $settingManager->set('enable_html5_desktop_notifications', $value); - } - - /** - * Determines the enable_html5_desktop_notifications setting either for the given user or global if no user is given. - * By default the setting is enabled. - * @param User $user - * @return int - */ - public function getDesktopNoficationSettings(User $user = null) - { - if ($user) { - return Yii::$app->getModule('notification')->settings->user($user)->getInherit('enable_html5_desktop_notifications', 1); - } else { - return Yii::$app->getModule('notification')->settings->get('enable_html5_desktop_notifications', 1); - } - } - /** * Sets the send_notifications settings for the given space and user. * diff --git a/protected/humhub/modules/notification/controllers/ListController.php b/protected/humhub/modules/notification/controllers/ListController.php index 141bb02bff..9ee5a73ebc 100644 --- a/protected/humhub/modules/notification/controllers/ListController.php +++ b/protected/humhub/modules/notification/controllers/ListController.php @@ -15,7 +15,6 @@ use humhub\modules\notification\models\Notification; use Throwable; use Yii; use yii\db\IntegrityException; -use yii\db\StaleObjectException; use yii\web\HttpException; /** @@ -55,7 +54,6 @@ class ListController extends Controller $output .= $baseModel->render(); $lastEntryId = $notification->id; - $notification->desktop_notified = 1; $notification->update(); } catch (IntegrityException $ie) { $notification->delete(); @@ -90,52 +88,14 @@ class ListController extends Controller } /** - * Returns new notifications - * - * @deprecated since version 1.2 - */ - public function actionGetUpdateJson() - { - return $this->asJson(self::getUpdates()); - } - - /** - * Returns a JSON which contains + * Returns a JSON array which contains * - Number of new / unread notification - * - Notification Output for new HTML5 Notifications * - * @param bool $includeContent weather or not to include the actual notification content - * @return string JSON String + * @return array JSON array * @throws Throwable - * @throws StaleObjectException */ - public static function getUpdates($includeContent = true) + public static function getUpdates(): array { - $update['newNotifications'] = Notification::findUnseen()->count(); - - $unnotified = Notification::findUnnotifiedInFrontend()->all(); - - $update['notifications'] = []; - foreach ($unnotified as $notification) { - if ($includeContent && Yii::$app->getModule('notification')->settings->user()->getInherit('enable_html5_desktop_notifications', true)) { - try { - $baseModel = $notification->getBaseModel(); - - if ($baseModel->validate()) { - $update['notifications'][] = $baseModel; - } else { - throw new IntegrityException('Invalid base model found for notification'); - } - } catch (IntegrityException $ex) { - $notification->delete(); - Yii::warning('Deleted inconsistent notification with id ' . $notification->id . '. ' . $ex->getMessage()); - continue; - } - } - $notification->desktop_notified = 1; - $notification->update(); - } - - return $update; + return ['newNotifications' => Notification::findUnseen()->count()]; } } diff --git a/protected/humhub/modules/notification/migrations/m241022_084028_delete_desktop_notified.php b/protected/humhub/modules/notification/migrations/m241022_084028_delete_desktop_notified.php new file mode 100644 index 0000000000..2c9aba0d06 --- /dev/null +++ b/protected/humhub/modules/notification/migrations/m241022_084028_delete_desktop_notified.php @@ -0,0 +1,31 @@ +safeDropColumn('notification', 'desktop_notified'); + $this->delete('contentcontainer_setting', [ + 'name' => 'enable_html5_desktop_notifications', + 'module_id' => 'notification', + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + echo "m241022_084028_delete_desktop_notified cannot be reverted.\n"; + + return false; + } +} diff --git a/protected/humhub/modules/notification/models/Notification.php b/protected/humhub/modules/notification/models/Notification.php index 1bbcddf668..70228bdd82 100644 --- a/protected/humhub/modules/notification/models/Notification.php +++ b/protected/humhub/modules/notification/models/Notification.php @@ -29,7 +29,6 @@ use yii\db\Query; * @property int $emailed * @property string module * @property string $created_at - * @property int $desktop_notified * @property int $originator_user_id * @property int $send_web_notifications * @property string $payload @@ -97,7 +96,7 @@ class Notification extends ActiveRecord return [ [['class', 'user_id'], 'required'], [ - ['user_id', 'seen', 'source_pk', 'space_id', 'emailed', 'desktop_notified', 'originator_user_id'], + ['user_id', 'seen', 'source_pk', 'space_id', 'emailed', 'originator_user_id'], 'integer', ], [['class', 'source_class'], 'string', 'max' => 100], @@ -290,17 +289,4 @@ class Notification extends ActiveRecord ->andWhere(['notification.seen' => 0]) ->orWhere(['IS', 'notification.seen', new Expression('NULL')]); } - - /** - * Finds all grouped unseen notifications which were not already sent to the frontend. - * - * @param User $user - * @return ActiveQuery - * @throws Throwable - * @since 1.2 - */ - public static function findUnnotifiedInFrontend(User $user = null) - { - return self::findUnseen($user)->andWhere(['notification.desktop_notified' => 0]); - } } diff --git a/protected/humhub/modules/notification/models/forms/NotificationSettings.php b/protected/humhub/modules/notification/models/forms/NotificationSettings.php index 2e81fa73dd..0296c9b087 100644 --- a/protected/humhub/modules/notification/models/forms/NotificationSettings.php +++ b/protected/humhub/modules/notification/models/forms/NotificationSettings.php @@ -45,11 +45,6 @@ class NotificationSettings extends Model */ public $user; - /** - * @var bool manage if the user/users should receive desktop notifications. - */ - public $desktopNotifications; - /** * @var BaseTarget[] */ @@ -70,8 +65,6 @@ class NotificationSettings extends Model $this->spaceGuids = Yii::$app->getModule('notification')->settings->getSerialized('sendNotificationSpaces'); } - $this->desktopNotifications = Yii::$app->notification->getDesktopNoficationSettings($this->user); - $module = Yii::$app->getModule('notification'); return ($this->user) ? $module->settings->user($this->user) : $module->settings; @@ -83,7 +76,6 @@ class NotificationSettings extends Model public function rules() { return [ - ['desktopNotifications', 'integer'], [['settings', 'spaceGuids'], 'safe'], ]; } @@ -93,14 +85,8 @@ class NotificationSettings extends Model */ public function attributeLabels() { - if ($this->user) { - $desktopNotificationLabel = Yii::t('NotificationModule.base', 'Receive desktop notifications when you are online.'); - } else { - $desktopNotificationLabel = Yii::t('NotificationModule.base', 'Allow desktop notifications by default.'); - } return [ 'spaceGuids' => Yii::t('NotificationModule.base', 'Receive \'New Content\' Notifications for the following spaces'), - 'desktopNotifications' => $desktopNotificationLabel, ]; } @@ -166,7 +152,6 @@ class NotificationSettings extends Model } $this->saveSpaceSettings(); - Yii::$app->notification->setDesktopNoficationSettings($this->desktopNotifications, $this->user); Yii::$app->notification->setSpaces($this->spaceGuids, $this->user); $settings = $this->getSettings(); @@ -251,7 +236,6 @@ class NotificationSettings extends Model $settings = $this->getSettings(); $settings?->delete(NotificationManager::IS_TOUCHED_SETTINGS); - $settings?->delete('enable_html5_desktop_notifications'); foreach ($this->targets() as $target) { foreach ($this->categories() as $category) { $settings->delete($target->getSettingKey($category)); @@ -276,7 +260,7 @@ class NotificationSettings extends Model */ public function resetAllUserSettings() { - $notificationSettings = [NotificationManager::IS_TOUCHED_SETTINGS, 'enable_html5_desktop_notifications']; + $notificationSettings = [NotificationManager::IS_TOUCHED_SETTINGS]; foreach ($this->targets() as $target) { foreach ($this->categories() as $category) { $notificationSettings[] = $target->getSettingKey($category); diff --git a/protected/humhub/modules/notification/resources/js/humhub.notification.js b/protected/humhub/modules/notification/resources/js/humhub.notification.js index a7df0e1f35..2476493093 100644 --- a/protected/humhub/modules/notification/resources/js/humhub.notification.js +++ b/protected/humhub/modules/notification/resources/js/humhub.notification.js @@ -47,14 +47,12 @@ humhub.module('notification', function (module, require, $) { this.originalTitle = document.title; this.initDropdown(); this.handleResult(update); - // this.sendDesktopNotifications(update); var that = this; event.on('humhub:modules:notification:live:NewNotification', function (evt, events, update) { var filteredEvents = that.filterEvents(events); var count = (that.$.data('notification-count')) ? parseInt(that.$.data('notification-count')) + filteredEvents.length : filteredEvents.length; that.updateCount(count); - that.sendDesktopNotifications(events, update.lastSessionTime); }); // e.g. Mail module can fire this to `updateTitle`. @@ -196,48 +194,11 @@ humhub.module('notification', function (module, require, $) { this.$.data('notification-count', $count); }; - NotificationDropDown.prototype.sendDesktopNotifications = function (response, lastSessionTime) { - if (!response) { - return; - } - - if (!module.config.sendDesktopNotifications) { - return; - } - - if (response.text) { // Single Notification - module.sendDesktopNotifiaction(response.text); - } else if (response.notifications) { // Multiple Notifications - var $notifications = response.notifications; - for (var i = 0; i < $notifications.length; i++) { - module.sendDesktopNotifiaction($notifications[i]); - } - } else if (object.isArray(response)) { // Live events - $.each(response, function (i, liveEvent) { - if (lastSessionTime && lastSessionTime > liveEvent.data.ts) { - return; // continue - } - - if (liveEvent.data && liveEvent.data.text) { - module.sendDesktopNotifiaction(liveEvent.data.text); - } - }); - } - - }; - var getNotificationCount = function () { var widget = NotificationDropDown.instance('#notification_widget'); return widget.$.data('notification-count'); }; - var sendDesktopNotifiaction = function (body, icon) { - icon = icon || module.config.icon; - if (body && body.length) { - notify.createNotification("Notification", {body: body, icon: icon}); - } - }; - var _errorHandler = function (e) { module.log.error(e, true); }; @@ -350,7 +311,6 @@ humhub.module('notification', function (module, require, $) { module.export({ init: init, markAsSeen: markAsSeen, - sendDesktopNotifiaction: sendDesktopNotifiaction, getNotificationCount: getNotificationCount, NotificationDropDown: NotificationDropDown, OverviewWidget: OverviewWidget diff --git a/protected/humhub/modules/notification/widgets/Overview.php b/protected/humhub/modules/notification/widgets/Overview.php index f07c654d18..a89c9457d6 100644 --- a/protected/humhub/modules/notification/widgets/Overview.php +++ b/protected/humhub/modules/notification/widgets/Overview.php @@ -28,9 +28,7 @@ class Overview extends JsWidget public function init() { $this->view->registerJsConfig('notification', [ - 'icon' => $this->view->theme->getBaseUrl() . '/ico/notification-o.png', 'loadEntriesUrl' => Url::to(['/notification/list']), - 'sendDesktopNotifications' => boolval(Yii::$app->notification->getDesktopNoficationSettings(Yii::$app->user->getIdentity())), 'text' => [ 'placeholder' => Yii::t('NotificationModule.base', 'There are no notifications yet.'), ], diff --git a/protected/humhub/modules/notification/widgets/views/notificationSettingsForm.php b/protected/humhub/modules/notification/widgets/views/notificationSettingsForm.php index 9364b4bfb6..55b2f6bdc5 100644 --- a/protected/humhub/modules/notification/widgets/views/notificationSettingsForm.php +++ b/protected/humhub/modules/notification/widgets/views/notificationSettingsForm.php @@ -13,7 +13,6 @@ use yii\bootstrap\Html; ?>
-field($model, 'desktopNotifications')->checkbox(); ?> - diff --git a/themes/HumHub/ico/notification-o.png b/themes/HumHub/ico/notification-o.png deleted file mode 100644 index 956af81201..0000000000 Binary files a/themes/HumHub/ico/notification-o.png and /dev/null differ diff --git a/themes/HumHub/ico/notification.png b/themes/HumHub/ico/notification.png deleted file mode 100644 index e35a5f4043..0000000000 Binary files a/themes/HumHub/ico/notification.png and /dev/null differ