Skip to content

Commit

Permalink
fix: add buttons to tg subscriptions + URL for rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
vas3k committed Dec 7, 2024
1 parent a3c4ea1 commit d239170
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
6 changes: 6 additions & 0 deletions frontend/html/rooms/widgets/feed_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
{{ room.description | markdown }}
</span>

{% if room.url %}
<span class="feed-topic-header-footer">
<i class="fas fa-link"></i>&nbsp;<strong>URL:</strong> <a href="{{ room.url }}" rel="noreferrer" target="_blank">{{ room.url }}</a>
</span>
{% endif %}

{% if room.chat_url and room.chat_name %}
<span class="feed-topic-header-footer">
<i class="fab fa-telegram-plane"></i>&nbsp;<strong>Чат:</strong> <a href="{{ room.get_private_url }}" rel="noreferrer" target="_blank">{{ room.chat_name }}</a>
Expand Down
33 changes: 19 additions & 14 deletions notifications/telegram/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,14 @@ def announce_in_club_channel(post, announce_text=None, image=None):


def announce_in_club_chats(post):
post_url = settings.APP_HOST + reverse("show_post", kwargs={
"post_type": post.type,
"post_slug": post.slug
})
post_reply_markup = telegram.InlineKeyboardMarkup([
[
telegram.InlineKeyboardButton("👍", callback_data=f"upvote_post:{post.id}"),
telegram.InlineKeyboardButton("🔗", url=post_url),
telegram.InlineKeyboardButton("🔔", callback_data=f"subscribe:{post.id}"),
],
])

# announce to public chat
if post.is_visible_in_feeds or not post.room or not post.room.chat_id:
send_telegram_message(
chat=CLUB_CHAT,
text=render_html_message("channel_post_announce.html", post=post),
parse_mode=telegram.ParseMode.HTML,
disable_preview=True,
reply_markup=post_reply_markup,
reply_markup=post_reply_markup(post),
)

if post.room and post.room.chat_id and post.room.send_new_posts_to_chat:
Expand All @@ -57,7 +45,7 @@ def announce_in_club_chats(post):
text=render_html_message("channel_post_announce.html", post=post),
parse_mode=telegram.ParseMode.HTML,
disable_preview=True,
reply_markup=post_reply_markup,
reply_markup=post_reply_markup(post),
)


Expand Down Expand Up @@ -95,6 +83,7 @@ def notify_post_collectible_tag_owners(post):
chat=Chat(id=tag_user.user.telegram_id),
text=render_html_message("post_collectible_tag.html", post=post, tag=tag),
parse_mode=telegram.ParseMode.HTML,
reply_markup=post_reply_markup(post),
)


Expand All @@ -107,4 +96,20 @@ def notify_post_room_subscribers(post):
chat=Chat(id=subscriber.user.telegram_id),
text=render_html_message("post_room_subscriber.html", post=post, room=post.room),
parse_mode=telegram.ParseMode.HTML,
reply_markup=post_reply_markup(post),
)


def post_reply_markup(post):
post_url = settings.APP_HOST + reverse("show_post", kwargs={
"post_type": post.type,
"post_slug": post.slug
})

return telegram.InlineKeyboardMarkup([
[
telegram.InlineKeyboardButton("👍", callback_data=f"upvote_post:{post.id}"),
telegram.InlineKeyboardButton("🔗", url=post_url),
telegram.InlineKeyboardButton("🔔", callback_data=f"subscribe:{post.id}"),
],
])
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
🏷 Кто-то написал новый пост по теме <b>{{ tag.name }}</b>. Вы добавили этот коллекционный тег к себе в профиль, так что мы уведомляем вас о нём.
🏷 Новый пост с тегом <b>{{ tag.name }}</b>:

{% if post.emoji %}{{ post.emoji }} {% endif %}<b>{% if post.prefix %}{{ post.prefix }} {% endif %}<a href="{{ settings.APP_HOST }}{% url "show_post" post.type post.slug %}">{{ post.title }}</a> {% if post.room %} [{{ post.room.title }}]{% endif %}</b>
{% load posts %}{% render_tg post 350 %}

<i>Если вы больше не хотите получать уведомления по данному тегу — удалите его из своего профиля.</i>
<i>Если вы больше не хотите получать уведомления по данному тегу — просто удалите его из своего профиля.</i>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
🏷 Новый пост в комнате <b>«<a href="{{ settings.APP_HOST }}{% url "feed_room" room.slug %}">{{ room.title }}</a>»</b>. Вы подписались на эту комнату, так что мы уведомляем вас о нём.
🏷 Новый пост в комнате <b>«<a href="{{ settings.APP_HOST }}{% url "feed_room" room.slug %}">{{ room.title }}</a>»</b>:

{% if post.emoji %}{{ post.emoji }} {% endif %}<b>{% if post.prefix %}{{ post.prefix }} {% endif %}<a href="{{ settings.APP_HOST }}{% url "show_post" post.type post.slug %}">{{ post.title }}</a></b>
{% load posts %}{% render_tg post 350 %}

0 comments on commit d239170

Please sign in to comment.