fix conversations subscribers for system message

This commit is contained in:
Élie Bouttier 2016-07-07 19:46:19 +02:00
parent 774a7c3a43
commit dbe5972634
3 changed files with 25 additions and 4 deletions

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-07-07 16:49
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('conversations', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='message',
name='system',
field=models.BooleanField(default=False),
),
]

View File

@ -21,6 +21,7 @@ class Message(PonyConfModel):
author = models.ForeignKey(User)
content = models.TextField()
system = models.BooleanField(default=False)
class Meta:
ordering = ['created']
@ -103,6 +104,8 @@ class ConversationAboutTalk(Conversation):
def new_message(self, message):
site = self.get_site()
first = self.messages.first()
if not message.system and message.author not in self.subscribers.all():
self.subscribers.add(message.author)
recipients = self.subscribers.all()
data = {
'uri': site.domain + reverse('show-talk', args=[self.talk.slug]),
@ -117,8 +120,6 @@ class ConversationAboutTalk(Conversation):
'proposer_uri': site.domain + reverse('show-speaker', args=[message.author.username])
})
else:
if message.author not in self.subscribers.all():
self.subscribers.add(message.author)
subject = 'Re: [%s] Talk: %s' % (site.name, self.talk.title)
template = 'message'
ref = first.token

View File

@ -38,7 +38,7 @@ def check_talk(talk):
def notify_talk_added(sender, instance, author, **kwargs):
check_talk(instance)
message = Message(conversation=instance.conversation, author=author,
content='The talk has been proposed.')
content='The talk has been proposed.', system=True)
message.save()
@ -46,7 +46,7 @@ def notify_talk_added(sender, instance, author, **kwargs):
def notify_talk_edited(sender, instance, author, **kwargs):
check_talk(instance)
message = Message(conversation=instance.conversation, author=author,
content='The talk has been modified.')
content='The talk has been modified.', system=True)
message.save()