Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to reset some notification settings to all users without resetting "Like" notifications by email #6950

Open
marc-farre opened this issue Apr 15, 2024 · 6 comments

Comments

@marc-farre
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

I want to reset Space notifications only.
In a custom module, I do the following:

Yii::$app->notification->resetSpaces();

Problem: for each user, to know if the notification settings have been reset (to use the default settings), we use NotificationManager::isUntouchedSettings($user): https://github.com/humhub/humhub/blob/master/protected/humhub/modules/notification/components/NotificationManager.php#L291C5-L294C6
This method looks if notification.like_email is null for the user or not.

So we also need to reset "Like" notifications by email.

Describe the solution you'd like

I think that for each notification type we should distinguish the null from other values (0, false or empty string or array).
When a notification if null, then we use the default settings.

Describe alternatives you've considered

    public const IS_UNTOUCHED_SETTINGS = 'is_untouched_settings';
    private function isUntouchedSettings(User $user)
    {
        return (bool)Yii::$app->getModule('notification')->settings->user($user)->get(self::IS_UNTOUCHED_SETTINGS);
    }
@luke-
Copy link
Contributor

luke- commented Apr 15, 2024

To sum up: The current situation is that the Notification Settings are considered as a whole set. As soon as a user has changed at least one notification setting, these are used, regardless of whether the default settings are still used for some types.

We currently use the "Like" notification as an indicator, but we could use also other standard notifications here as well.

If I understand you correctly, you would prefer it to be similar to the permission system, where there is always a default value and then overwritten values for each notification type.

@marc-farre
Copy link
Collaborator Author

@luke- yes, exactly. What do you suggest for a start?

Maybe we could first implement the alternative I suggested above, with a migration such as:

foreach (User::find()->each() as $user) {
    $isUntouchedSettings = Yii::$app->getModule('notification')->settings->user($user)->get('notification.like_email') === null;
    Yii::$app->getModule('notification')->settings->user($user)->set(self::IS_UNTOUCHED_SETTINGS, $isUntouchedSettings);
}

And later refactor the hole notification settings to have the "Default value"?

An idea to avoid changing the UI: when the user selects the same value as the default one, instead of saving true or falseor other value, we save null.

@luke-
Copy link
Contributor

luke- commented Apr 19, 2024

@marc-farre I'm a little unsure whether I like it that much without redesigning the UI.

If I understand your suggestion correctly, we only save the user's value that differs from the default.

However, this also means that theoretically, users who have already decided against a notification (which was the default before) would still receive it if the admin adjusts the default.

It's not a big deal, but we should be aware of it.

For me, the current implementation is somehow clearer here.

@marc-farre
Copy link
Collaborator Author

@luke- OK. Could we use is_untouched_settings instead of notification.like_email?
This will have no consequences on the current behavior (if we have the above suggested migration), and:

  • will allow resetting the space settings without having to reset the like by email notifications
  • will make it clearer to use a dedicated const (it took me a wile to understand why I could not reset the space notifications only...)

@luke-
Copy link
Contributor

luke- commented Apr 22, 2024

@marc-farre Yes, the current implementation with notification.like_email is really not optimal. You are welcome to improve it as suggested.

@marc-farre
Copy link
Collaborator Author

@luke- PR #6964

I've created NotificationManager::IS_TOUCHED_SETTINGS (and not ...UNTOUCHED...) because we have fewer users having touched settings than untouched, so it reduces the records in the DB.

This PR also fixes a bug when the like module is disabled (via config/common.php file or the Reaction module), because when disabled, there are no "Like" notification settings, so the is NotificationManager::isUntouchedSettings($user) could not work.

github-merge-queue bot pushed a commit that referenced this issue Apr 24, 2024
#6964)

* Enh #6950: Ability to reset some notification settings to all users without resetting "Like" notifications by email

* #6964 (comment)

---------

Co-authored-by: Lucas Bartholemy <luke-@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants