added events to event system
This commit is contained in:
@@ -3,7 +3,7 @@ from flask_login import login_required, current_user
|
||||
from models import db, Conversation, User, Message, MessageAttachment
|
||||
from forms import ConversationForm
|
||||
from routes.auth import require_password_change
|
||||
from utils import log_event
|
||||
from utils import log_event, create_notification
|
||||
import os
|
||||
from werkzeug.utils import secure_filename
|
||||
from datetime import datetime
|
||||
@@ -177,6 +177,20 @@ def add_member(conversation_id):
|
||||
conversation.members.append(user)
|
||||
db.session.commit()
|
||||
|
||||
# Create notification for the invited user
|
||||
create_notification(
|
||||
notif_type='conversation_invite',
|
||||
user_id=user.id,
|
||||
sender_id=current_user.id,
|
||||
details={
|
||||
'message': f'You have been invited to join conversation "{conversation.name}"',
|
||||
'conversation_id': conversation.id,
|
||||
'conversation_name': conversation.name,
|
||||
'invited_by': f"{current_user.username} {current_user.last_name}",
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
)
|
||||
|
||||
# Log member addition
|
||||
log_event(
|
||||
event_type='conversation_member_add',
|
||||
@@ -186,7 +200,7 @@ def add_member(conversation_id):
|
||||
'added_by': current_user.id,
|
||||
'added_by_name': f"{current_user.username} {current_user.last_name}",
|
||||
'added_user_id': user.id,
|
||||
'added_by_name': f"{current_user.username} {current_user.last_name}",
|
||||
'added_user_name': f"{user.username} {user.last_name}",
|
||||
'added_user_email': user.email
|
||||
}
|
||||
)
|
||||
@@ -215,6 +229,20 @@ def remove_member(conversation_id, user_id):
|
||||
conversation.members.remove(user)
|
||||
db.session.commit()
|
||||
|
||||
# Create notification for the removed user
|
||||
create_notification(
|
||||
notif_type='conversation_invite_removed',
|
||||
user_id=user.id,
|
||||
sender_id=current_user.id,
|
||||
details={
|
||||
'message': f'You have been removed from conversation "{conversation.name}"',
|
||||
'conversation_id': conversation.id,
|
||||
'conversation_name': conversation.name,
|
||||
'removed_by': f"{current_user.username} {current_user.last_name}",
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
)
|
||||
|
||||
# Log member removal
|
||||
log_event(
|
||||
event_type='conversation_member_remove',
|
||||
@@ -437,6 +465,25 @@ def send_message(conversation_id):
|
||||
|
||||
db.session.commit()
|
||||
|
||||
# Create notifications for all conversation members except the sender
|
||||
for member in conversation.members:
|
||||
if member.id != current_user.id:
|
||||
create_notification(
|
||||
notif_type='conversation_message',
|
||||
user_id=member.id,
|
||||
sender_id=current_user.id,
|
||||
details={
|
||||
'message': f'New message in conversation "{conversation.name}"',
|
||||
'conversation_id': conversation.id,
|
||||
'conversation_name': conversation.name,
|
||||
'sender': f"{current_user.username} {current_user.last_name}",
|
||||
'message_preview': message_content[:100] + ('...' if len(message_content) > 100 else ''),
|
||||
'has_attachments': len(attachments) > 0,
|
||||
'attachment_count': len(attachments),
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
)
|
||||
|
||||
# Log message creation
|
||||
log_event(
|
||||
event_type='message_create',
|
||||
|
||||
Reference in New Issue
Block a user