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

Convert subscriber notification signal into regular function call from the view #195

Closed
wants to merge 20 commits into from

Conversation

skolsuper
Copy link
Contributor

The previous method of using the post_save signal to call notify_topic_subscribers meant that the function was called without the request available, creating an undocumented dependency on the django.contrib.sites app.

Moving the notify_topic_subscribers call into the view enables the use of the get_current_site shortcut which removes the dependency. It has the added benefit of ensuring that subscribers are only notified when a post is successfully added or edited in a thread, and not in any of the other possible scenarios where the post_save signal is sent.

…views.

The previous method of using the post_save signal to notify subscribers meant that the function was called without the request available, creating an undocumented dependency on the django.contrib.sites app.  Moving the method call into the view enables the use of the get_current_site shortcut which removes the dependency.  It has the added benefit of ensuring that subscribers are only notified when a post is successfully added or edited in a thread, and not in any of the other possible scenarios where the post_save signal is sent.
@DylannCordel
Copy link
Contributor

Hi @skolsuper

I think signals are better because third party apps can remove existing listeners and/or add new listeners to have custom notification process for exemple.
Furthermore, if you move this in a view, we won't be able to use api to add / edit posts (in tests, in some specific commands etc.).

But you right : post_save is not the good signal. We should have a custom signal like "post_content_updated" which must be triggered only when a post has its content really updated.
We could test the old body html version and the new one to know if updates are enough to notify again subscribers. For exemple, if I post with a typo, then edit to correct the typo : we should not send 2 notifications to users because the update is not meanful.

What do you think about it ?

@skolsuper
Copy link
Contributor Author

Hmm, food for thought definitely. I have added a method call to notify_subscribers so that people can subclass the view and override it.

This is firmly in the realm of opinion, but I'm not a big fan of using signals and slots in python, I don't like the possibility of action occurring at a distance, without appearing in the code that triggers it. However, using a custom signal means it will always be explicitly thrown, and we can include the request in the kwargs, so it solves the dependency issue too. That would also mean it could be an override in the settings, which is easier for non-technical users to change.

On the subject of multiple notifications, in my experience as a user of other forums, once I get a notification that a thread has been updated, I won't get another until I have checked the thread. I think for a busy forum it will be essential to have this functionality in pybb. Maybe it is better to make another pull request for that though.

…isable notifications for edits.

Imho, notifications for post edits will be confusing to users the majority of the time, when they visit the thread and see no new posts.  The fraction of the time where they understand what has happened, the edit will be of no material value (typo fix, spelling/grammar) a lot of the time too.
@skolsuper
Copy link
Contributor Author

@GeyseR I would appreciate your thoughts on this PR. A summary of the changes:

  • Creates a custom signal topic_updated sent by AddPostView and EditPostView.
  • It does nothing if notifications are disabled.
  • It isn't sent by EditPostView unless user sets PYBB_NOTIFY_ON_EDIT = True
  • It passes the request with the signal, removing an undocumented dependency of pybbm on the django.contrib.sites app
  • I also added an ImproperlyConfigured exception if PYBB_USE_DJANGO_MAILER is True but django-mailer is not installed

@DylannCordel your thoughts would be appreciated too.

@@ -113,6 +113,7 @@ def getsetting_with_deprecation_check(all_settings, setting_name):

PYBB_DISABLE_SUBSCRIPTIONS = getattr(settings, 'PYBB_DISABLE_SUBSCRIPTIONS', False)
PYBB_DISABLE_NOTIFICATIONS = getattr(settings, 'PYBB_DISABLE_NOTIFICATIONS', False)
PYBB_NOTIFY_ON_EDIT = getattr(settings, 'PYBB_NOTIFY_ON_EDIT', False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should have True as default value to stay fully backward compatible as in current version we are notified each time a post is updated.

@DylannCordel
Copy link
Contributor

Hi @skolsuper

Sorry for this tardive answer. I add some comments on your code. About the topic_updated signal wich requires the request, I continue to think this is not a good idea because you won't be able to use this signal "out of a view", for batch processing for exemple.

Else, GJ ;-)

…. Move notifications signal dispatch into form_valid method to allow for overriding post method in view. Change default value for PYBB_NOTIFY_ON_EDIT to True
@skolsuper
Copy link
Contributor Author

Hi @DylannCordel, thanks for the feedback, I have incorporated most if not all of it 👍

skolsuper and others added 12 commits September 25, 2015 19:57
…views.

The previous method of using the post_save signal to notify subscribers meant that the function was called without the request available, creating an undocumented dependency on the django.contrib.sites app.  Moving the method call into the view enables the use of the get_current_site shortcut which removes the dependency.  It has the added benefit of ensuring that subscribers are only notified when a post is successfully added or edited in a thread, and not in any of the other possible scenarios where the post_save signal is sent.
…isable notifications for edits.

Imho, notifications for post edits will be confusing to users the majority of the time, when they visit the thread and see no new posts.  The fraction of the time where they understand what has happened, the edit will be of no material value (typo fix, spelling/grammar) a lot of the time too.
…. Move notifications signal dispatch into form_valid method to allow for overriding post method in view. Change default value for PYBB_NOTIFY_ON_EDIT to True
@skolsuper skolsuper closed this Nov 14, 2018
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

Successfully merging this pull request may close these issues.

None yet

3 participants