def notify_listeners(content):
"""Send out to listening consumers."""
data = json.dumps({"event": "new", "id": content.id})
if content.content_type == ContentType.REPLY:
# Content reply
StreamConsumer.group_send("streams_content__%s" % content.parent.channel_group_name, data)
elif content.content_type == ContentType.SHARE:
# Share
# TODO do we need to do much?
pass
else:
# Public stream
if content.visibility == Visibility.PUBLIC:
StreamConsumer.group_send("streams_public", data)
# Tag streams
for tag in content.tags.all():
StreamConsumer.group_send("streams_tag__%s" % tag.channel_group_name, data)
# Profile streams
StreamConsumer.group_send("streams_profile__%s" % content.author.id, data)
StreamConsumer.group_send("streams_profile_all__%s" % content.author.id, data)
# Followed stream
followed_qs = Profile.objects.followers(content.author).filter(user__isnull=False)
for username in followed_qs.values_list("user__username", flat=True):
StreamConsumer.group_send("streams_followed__%s" % username, data)
评论列表
文章目录