fixed editing members
This commit is contained in:
Binary file not shown.
@@ -296,25 +296,57 @@ def edit_conversation(conversation_id):
|
||||
'member_ids': [member.id for member in conversation.members]
|
||||
}
|
||||
|
||||
# Get members from the form data
|
||||
member_ids = request.form.getlist('members')
|
||||
# Update name and description from form data
|
||||
conversation.name = form.name.data
|
||||
conversation.description = form.description.data
|
||||
|
||||
# Get members from the form data and convert to integers
|
||||
member_ids = [int(id) for id in request.form.getlist('members')]
|
||||
|
||||
# Update members
|
||||
current_member_ids = {str(user.id) for user in conversation.members}
|
||||
current_member_ids = {user.id for user in conversation.members}
|
||||
new_member_ids = set(member_ids)
|
||||
|
||||
# Remove members that are no longer in the list
|
||||
for member_id in current_member_ids - new_member_ids:
|
||||
if int(member_id) != conversation.created_by: # Don't remove the creator
|
||||
members_to_remove = current_member_ids - new_member_ids
|
||||
for member_id in members_to_remove:
|
||||
if member_id != conversation.created_by: # Don't remove the creator
|
||||
user = User.query.get(member_id)
|
||||
if user:
|
||||
conversation.members.remove(user)
|
||||
# Create notification for 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()
|
||||
}
|
||||
)
|
||||
|
||||
# Add new members
|
||||
for member_id in new_member_ids - current_member_ids:
|
||||
members_to_add = new_member_ids - current_member_ids
|
||||
for member_id in members_to_add:
|
||||
user = User.query.get(member_id)
|
||||
if user and user not in conversation.members:
|
||||
conversation.members.append(user)
|
||||
# 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()
|
||||
}
|
||||
)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
@@ -336,7 +368,7 @@ def edit_conversation(conversation_id):
|
||||
)
|
||||
db.session.commit()
|
||||
|
||||
flash('Conversation members updated successfully!', 'success')
|
||||
flash('Conversation updated successfully!', 'success')
|
||||
|
||||
# Check if redirect parameter is provided
|
||||
redirect_url = request.args.get('redirect')
|
||||
|
||||
Reference in New Issue
Block a user