Skip to content

Commit

Permalink
fix: comment counters not updated when posting via bot
Browse files Browse the repository at this point in the history
  • Loading branch information
vas3k committed Sep 2, 2024
1 parent 26e934d commit 6c41dc4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 22 additions & 2 deletions bot/handlers/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from comments.models import Comment
from posts.models.post import Post
from posts.models.linked import LinkedPost
from posts.models.views import PostView
from search.models import SearchIndex

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -73,6 +75,16 @@ def reply_to_comment(update: Update, context: CallbackContext) -> None:
"telegram": update.to_dict()
}
)
Comment.update_post_counters(comment.post)
PostView.increment_unread_comments(comment)
PostView.register_view(
request=None,
user=user,
post=comment.post,
)
SearchIndex.update_comment_index(comment)
LinkedPost.create_links_from_text(comment.post, text)

new_comment_url = settings.APP_HOST + reverse("show_comment", kwargs={
"post_slug": reply.post.slug,
"comment_id": reply.id
Expand Down Expand Up @@ -108,11 +120,11 @@ def comment_to_post(update: Update, context: CallbackContext) -> None:
f"😣 Сорян, я пока умею только в текстовые реплаи"
)
return None

for skip_word in ("/skip","#skip","#ignore"):
if skip_word in text:
return None

if len(text) < MIN_COMMENT_LEN:
update.message.reply_text(
f"😋 Твой коммент слишком короткий. Не буду постить его в Клуб, пускай остается в чате"
Expand All @@ -128,6 +140,14 @@ def comment_to_post(update: Update, context: CallbackContext) -> None:
"telegram": update.to_dict()
}
)
Comment.update_post_counters(post)
PostView.increment_unread_comments(comment)
PostView.register_view(
request=None,
user=user,
post=post,
)
SearchIndex.update_comment_index(comment)
LinkedPost.create_links_from_text(post, text)

new_comment_url = settings.APP_HOST + reverse("show_comment", kwargs={
Expand Down
4 changes: 2 additions & 2 deletions frontend/html/misc/mass_note.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{% if not achievement and not users %}
<form action="." method="get">
<span class="block-header">
Выберите ачивку:
Возьмите всех юзеров с ачивкой:
</span>
<span class="form-row form-row-center">
<select name="achievement_code" onchange="this.form.submit()">
Expand All @@ -41,7 +41,7 @@
</select>
</span>
<span class="block-header">
или впишите никнеймы через запятую:
или впишите их никнеймы через запятую:
</span>
<span class="form-row form-row-center">
<textarea name="handpicked_users" placeholder="vas3k,huyastrik,pivastrik"></textarea>
Expand Down

0 comments on commit 6c41dc4

Please sign in to comment.