Closed jdbit closed 2 years ago
Hi @jdbit, I am afraid not, it's not implemented.
I would do it connecting to comment_was_posted
, and I would verify that the email address of the user that posted the object is not among the email addresses of the users that already have sent comments, to avoid sending more than one email to the same email address.
It would be a nice feature addition.
I'll do it through signals then. Thank you!
Hi @danirus,
Could you please give me a hint on how to check if the email of the user that created the object is not among emails that already got an email notification?
Is it as simple as a query request below or I miss something?
followup = XtdComment.objects.filter(object_pk=comment.content_object.pk, user=comment.content_object.createdby, followup=True)
My signals look like this:
@receiver(comment_was_posted)
def comment_was_posted_handler(sender, comment, **kwargs):
if comment.parent_id == 0:
message = render_to_string('django_comments_xtd/email_followup_comment.html', {'comment': comment})
send_mail(
subject="Someone replied to your post",
message=message,
from_email=settings.SERVER_EMAIL,
recipient_list=[comment.content_object.createdby.email],
)
Also, could you please clarify, the followup checkbox means that the user gets notifications only to replies to their comments or notifications about all the comments posted under the post, even replies to other users? Let's say an article has 300 comments and all the users enabled followup checkbox, does it mean that when someone creates a new comment under the post, they will wait while the server sends all the 300 emails which might take a few seconds I guess? Or is there an email queue handled by Django so it sends all the emails in the background?
Hi @jdbit, yes you missed something about the first question. Comments may be sent by registered users but they eventually could send them when they are not logged in. Imagine you send a comment from someone else's computer, and you don't want to login there. In such a case you would be requested to confirm the comment by email, and your email would be recorded in the user_email
field of the comment. It sounds less likely to happen but it could. So in summary you need to check whether the user=comment.content_object.createdby
or user_email=comment.content_object.createdby.email
.
About the 2nd question, a commenter that ticked the follow-up box would receive notifications on every new comment sent to the same object. No matter whether the comment is in the same comment's thread_id
or not.
About the 3rd question, you can avoid blocking Django when sending mails in several ways:
COMMENTS_XTD_THREADED_EMAILS
to True
. By doing so every email sent by django-comments-xtd will be handled in a separate thread. send_email
calls. To improve that so the 300 calls happen in a deferred way we would need to make improvements in the app. The simplest thing would be to define a new customizable setting to allow the user define a replacement for the django_comments_xtd.views.notify_comment_followers
, so that the function runs non-blocking. The easiest thing would be to point to a user function that schedules a task to do that very same thing but within a celery worker.Thank you very much! Good point regarding the first question, I'll keep it in mind. So far I disabled the ability to comment for non-authorized users so it should not be an issue. Regarding the 3rd question, I'll take a look at the second and third approaches (maybe I can rewrite that function for my needs).
Hi, I added comments to an object (post) created by a user. Is there a way to send follow-up notifications about new comments to the user who created this post? Probably I can do this through signals, but just curious if it has been already implemented in django-comments-xtd.