Skip to content

Commit

Permalink
feat: boolean flag to send comments to rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
vas3k committed Sep 25, 2023
1 parent 98ee636 commit d51f92e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
10 changes: 9 additions & 1 deletion notifications/signals/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ def async_create_or_update_comment(comment):
)
notified_user_ids.add(thread_author.id)

# post top level comments to online channel
# post top level comments to "online" channel
if not comment.reply_to and comment.post.is_visible and comment.post.is_visible_in_feeds:
send_telegram_message(
chat=CLUB_ONLINE,
text=render_html_message("channel_comment_announce.html", comment=comment),
)

# post top level comments to "rooms" (if necessary)
if not comment.reply_to and comment.post.is_visible:
if comment.post.room_id and comment.post.room.chat_id and comment.post.room.send_new_comments_to_chat:
send_telegram_message(
chat=Chat(id=comment.post.room.chat_id),
text=render_html_message("channel_comment_announce.html", comment=comment),
)

# notify friends about your comments (not replies)
if not comment.reply_to:
friends = Friend.friends_for_user(comment.author)
Expand Down
2 changes: 1 addition & 1 deletion notifications/telegram/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def announce_in_club_chats(post):
reply_markup=post_reply_markup,
)

if post.room and post.room.chat_id:
if post.room and post.room.chat_id and post.room.send_new_posts_to_chat:
# announce to the room chat
send_telegram_message(
chat=Chat(id=post.room.chat_id),
Expand Down
3 changes: 2 additions & 1 deletion rooms/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ class RoomsAdmin(admin.ModelAdmin):
"icon",
"color",
"chat_name",
"send_new_posts_to_chat",
"send_new_comments_to_chat",
"network_group",
"last_activity_at",
"is_visible",
"is_open_for_posting",
"is_bot_active",
"index",
)
ordering = ("title",)
Expand Down
23 changes: 23 additions & 0 deletions rooms/migrations/0003_auto_20230925_1239.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.13 on 2023-09-25 12:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('rooms', '0002_auto_20230731_1419'),
]

operations = [
migrations.RenameField(
model_name='room',
old_name='is_bot_active',
new_name='send_new_posts_to_chat',
),
migrations.AddField(
model_name='room',
name='send_new_comments_to_chat',
field=models.BooleanField(default=False),
),
]
3 changes: 2 additions & 1 deletion rooms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Room(models.Model):
chat_name = models.CharField(max_length=128, null=True, blank=True)
chat_url = models.URLField(null=True, blank=True)
chat_id = models.CharField(max_length=32, null=True, blank=True)
send_new_posts_to_chat = models.BooleanField(default=True)
send_new_comments_to_chat = models.BooleanField(default=False)

network_group = models.ForeignKey(
"misc.NetworkGroup",
Expand All @@ -31,7 +33,6 @@ class Room(models.Model):

is_visible = models.BooleanField(default=True)
is_open_for_posting = models.BooleanField(default=True)
is_bot_active = models.BooleanField(default=True)

index = models.PositiveIntegerField(default=0)

Expand Down

0 comments on commit d51f92e

Please sign in to comment.