Browse Source

Notify user in app about being added to private thread

Rafał Pitoń 10 years ago
parent
commit
6f5aa5272d
2 changed files with 20 additions and 3 deletions
  1. 7 0
      misago/readtracker/threadstracker.py
  2. 13 3
      misago/threads/participants.py

+ 7 - 0
misago/readtracker/threadstracker.py

@@ -1,6 +1,8 @@
 from django.db.transaction import atomic
 from django.utils import timezone
 
+from misago.notifications import read_user_notifications
+
 from misago.readtracker import forumstracker, signals
 from misago.readtracker.dates import is_date_tracked
 from misago.readtracker.models import ForumRead, ThreadRead
@@ -159,6 +161,8 @@ def read_thread(user, thread, last_read_reply):
 
 @atomic
 def sync_record(user, thread, last_read_reply):
+    notification_triggers = ['read_thread_%s' % thread.pk]
+
     read_replies = count_read_replies(user, thread, last_read_reply)
     if thread.read_record:
         thread.read_record.read_replies = read_replies
@@ -171,11 +175,14 @@ def sync_record(user, thread, last_read_reply):
             read_replies=read_replies,
             last_read_on=last_read_reply.posted_on)
         signals.thread_tracked.send(sender=user, thread=thread)
+        notification_triggers.append('see_thread_%s' % thread.pk)
 
     if last_read_reply.posted_on == thread.last_post_on:
         signals.thread_read.send(sender=user, thread=thread)
         forumstracker.sync_record(user, thread.forum)
 
+    read_user_notifications(user, notification_triggers, False)
+
 
 def count_read_replies(user, thread, last_read_reply):
     last_reply_date = last_read_reply.posted_on

+ 13 - 3
misago/threads/participants.py

@@ -1,3 +1,5 @@
+from django.utils.translation import ugettext as _
+from misago.notifications import notify_user
 from misago.threads.models import ThreadParticipant
 
 
@@ -28,14 +30,22 @@ def set_user_unread_private_threads_sync(user):
     user.save(update_fields=['sync_unread_private_threads'])
 
 
-def add_participant(request, thread, user, is_owner=False):
+def add_participant(request, thread, user):
     """
     Add participant to thread, set "recound private threads" flag on user,
     notify user about being added to thread and mail him about it
     """
-    ThreadParticipant.objects.add_participant(thread, user, is_owner)
-    set_user_unread_private_threads_sync(user)
+    ThreadParticipant.objects.add_participant(thread, user)
+
+    notify_user(
+        user,
+        _("%(user)s added you to %(thread)s private thread."),
+        thread.get_new_reply_url(),
+        'see_thread_%s' % thread.pk,
+        {'user': request.user.username, 'thread': thread.title},
+        request.user)
 
+    set_user_unread_private_threads_sync(user)
 
 def add_owner(thread, user):
     """