mirror of
https://github.com/humhub/humhub.git
synced 2025-01-16 21:58:17 +01:00
Remove desktop notifications (#7269)
* Remove desktop notifications * Autocommit PHP CS Fixer
This commit is contained in:
parent
0e7dc7da79
commit
8d1a95df0f
@ -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)
|
||||
--------------------------
|
||||
|
@ -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' => [
|
||||
|
@ -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";
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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()];
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use humhub\components\Migration;
|
||||
|
||||
/**
|
||||
* Class m241022_084028_delete_desktop_notified
|
||||
*/
|
||||
class m241022_084028_delete_desktop_notified extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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.'),
|
||||
],
|
||||
|
@ -13,7 +13,6 @@ use yii\bootstrap\Html;
|
||||
?>
|
||||
|
||||
<br/>
|
||||
<?= $form->field($model, 'desktopNotifications')->checkbox(); ?>
|
||||
|
||||
<?php if ($showSpaces): ?>
|
||||
<?= humhub\modules\space\widgets\SpacePickerField::widget([
|
||||
@ -57,4 +56,3 @@ use yii\bootstrap\Html;
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 766 B |
Binary file not shown.
Before Width: | Height: | Size: 604 B |
Loading…
x
Reference in New Issue
Block a user