feat(messages): add email notification and in-app notification for replies
This commit is contained in:
parent
c926290a72
commit
446ee1c94a
@ -340,6 +340,49 @@ def messages_reply(message_id):
|
||||
parent_id=message_id
|
||||
)
|
||||
db.add(reply)
|
||||
db.flush() # Get reply.id for notification link
|
||||
|
||||
# Create in-app notification
|
||||
sender_name = current_user.name or current_user.email.split('@')[0]
|
||||
notification = UserNotification(
|
||||
user_id=recipient_id,
|
||||
title=f'Nowa odpowiedź od {sender_name}',
|
||||
message=f'{sender_name} odpowiedział(a) na wiadomość' + (f': {original.subject}' if original.subject else ''),
|
||||
notification_type='message',
|
||||
related_type='message',
|
||||
related_id=reply.id,
|
||||
action_url=url_for('.messages_view', message_id=message_id)
|
||||
)
|
||||
db.add(notification)
|
||||
|
||||
# Send email notification
|
||||
if recipient and recipient.notify_email_messages != False and recipient.email:
|
||||
try:
|
||||
message_url = url_for('.messages_view', message_id=message_id, _external=True)
|
||||
settings_url = url_for('auth.konto_prywatnosc', _external=True)
|
||||
preview = (content[:200] + '...') if len(content) > 200 else content
|
||||
subject_line = f'Nowa odpowiedź od {sender_name} — Norda Biznes'
|
||||
|
||||
email_html, email_text = build_message_notification_email(
|
||||
sender_name=sender_name,
|
||||
subject=f"Re: {original.subject}" if original.subject else None,
|
||||
content_preview=preview,
|
||||
message_url=message_url,
|
||||
settings_url=settings_url
|
||||
)
|
||||
send_email(
|
||||
to=[recipient.email],
|
||||
subject=subject_line,
|
||||
body_text=email_text,
|
||||
body_html=email_html,
|
||||
email_type='message_notification',
|
||||
user_id=recipient_id,
|
||||
recipient_name=recipient.name
|
||||
)
|
||||
except Exception as e:
|
||||
import logging
|
||||
logging.getLogger(__name__).warning(f"Failed to send reply email notification: {e}")
|
||||
|
||||
db.commit()
|
||||
|
||||
if recipient and recipient.notify_email_messages != False and recipient.email:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user