diff --git a/templates/forum/topic.html b/templates/forum/topic.html index 2e0f86a..65933ff 100755 --- a/templates/forum/topic.html +++ b/templates/forum/topic.html @@ -200,6 +200,13 @@ font-weight: 500; } + .forum-mention-self { + background: #fde68a; + color: #78350f; + font-weight: 700; + box-shadow: 0 0 0 1px #f59e0b; + } + /* User stats tooltip */ .user-stats-trigger { cursor: pointer; @@ -1105,7 +1112,7 @@ -
{{ topic.content|forum_markdown }}
+
{{ topic.content|forum_markdown(current_user.name if current_user.is_authenticated else None) }}
@@ -1235,7 +1242,7 @@ {% if reply.is_deleted %}
[Ta odpowiedź została usunięta]
{% else %} -
{{ reply.content|forum_markdown }}
+
{{ reply.content|forum_markdown(current_user.name if current_user.is_authenticated else None) }}
{% if reply.attachments %}
diff --git a/utils/markdown.py b/utils/markdown.py index 3e8aa18..5184528 100644 --- a/utils/markdown.py +++ b/utils/markdown.py @@ -19,7 +19,7 @@ def _autolink(text): ) -def parse_forum_markdown(text): +def parse_forum_markdown(text, current_user_name=None): """ Convert markdown text to safe HTML. @@ -81,12 +81,18 @@ def parse_forum_markdown(text): text ) - # @mentions - highlight them - text = re.sub( - r'@([\w.\-]+)', - r'@\1', - text - ) + # @mentions - highlight them; mark self-mentions with extra class + self_variants = set() + if current_user_name: + norm = current_user_name.strip().lower() + self_variants = {norm.replace(' ', '.'), norm.replace(' ', '_'), norm.replace(' ', '')} + + def _render_mention(m): + handle = m.group(1).lower() + cls = 'forum-mention forum-mention-self' if handle in self_variants else 'forum-mention' + return f'@{m.group(1)}' + + text = re.sub(r'@([\w.\-]+)', _render_mention, text) # Now process block structure (lists, quotes, paragraphs) lines = text.split('\n') diff --git a/utils/notifications.py b/utils/notifications.py index 7d971df..9bfb5db 100644 --- a/utils/notifications.py +++ b/utils/notifications.py @@ -621,6 +621,7 @@ def parse_mentions_and_notify(content, author_id, author_name, topic_id, content if user: mentioned_user_ids.append(user.id) + action_url = f'/forum/{topic_id}{"#reply-" + str(content_id) if content_type == "reply" else ""}' create_notification( user_id=user.id, title=f"@{author_name} wspomniał o Tobie", @@ -628,9 +629,53 @@ def parse_mentions_and_notify(content, author_id, author_name, topic_id, content notification_type='message', related_type=f'forum_{content_type}', related_id=content_id, - action_url=f'/forum/{topic_id}{"#reply-" + str(content_id) if content_type == "reply" else ""}' + action_url=action_url ) + # Send email notification to mentioned user + try: + from email_service import send_email, _email_v3_wrap + base_url = "https://nordabiznes.pl" + full_url = base_url + action_url + preview = (content[:200] + '...') if len(content) > 200 else content + where = 'odpowiedzi' if content_type == 'reply' else 'temacie' + subject = f"{author_name} wspomniał o Tobie na forum" + body_text = f"""{author_name} wspomniał o Tobie w {where} na forum Norda Biznes. + +"{preview}" + +Zobacz: {full_url} + +--- +Norda Biznes Partner - https://nordabiznes.pl +""" + html_content = f''' +

Cześć {user.name or ''}!

+

{author_name} wspomniał o Tobie w {where} na forum:

+ + + +
+

{preview}

+
+ + + +
+ Zobacz na forum → +
''' + body_html = _email_v3_wrap('Wspomniano o Tobie', 'Norda Biznes Partner', html_content) + send_email( + to=[user.email], + subject=subject, + body_text=body_text, + body_html=body_html, + email_type='forum_mention', + recipient_name=user.name or '' + ) + except Exception as e: + logger.error(f"Failed to send mention email to {user.email}: {e}") + return mentioned_user_ids except Exception as e: