From c452a920b13f66656064420b7669a7da7e2a1394 Mon Sep 17 00:00:00 2001 From: Kobe Date: Sat, 31 May 2025 22:53:52 +0200 Subject: [PATCH] fixed editing members --- .../__pycache__/conversations.cpython-313.pyc | Bin 27793 -> 28890 bytes routes/conversations.py | 46 +++++++++++++++--- static/js/create-conversation.js | 46 ++++++++++++++---- .../conversations/create_conversation.html | 17 +++++++ 4 files changed, 93 insertions(+), 16 deletions(-) diff --git a/routes/__pycache__/conversations.cpython-313.pyc b/routes/__pycache__/conversations.cpython-313.pyc index 31ec073970e99bec3ae63379b18d70e7a858b214..732b9f599dcd85736ee1261c32dbaa2588ac48c4 100644 GIT binary patch delta 2344 zcmcIldu*Fm6~EW7&yF8)65EL#J8@#KvC}50?Iz2^ak8Y%V_lZk-&{)E#WV3|Cp2-& zwOgK2)&V1h4XrycrNER;u#NJ^%47*uLQEa%w1Lp@*JiTuveAhlq_nJATLCGBa<7Ba zb-(^i7H(P&#GA%wkW$_Zvgj%fw484OoYOf@W@UpoOsCK=ec&g$*w{N&zediecbBe*Okrh&cS z88b@NVFb}VR_L#kHH14#&VrpK>dxMX+97bD_USg|HeS;z=e1ojI~x1bW{D0i6_e70 zG^M2OPQ!F34TNG6gvPcbbntUf@sI)T?{eT?czMwcXeK!X`(q4oQQ%Xx$Cq?5QwUw#xV_8qm-s zq5l4BAoxm;w%o{@+G)wyqI#839=1Zf)3A-N-s&oCNW0l22u0~kgt<+1Iu}~_uxGE0 z_U^y?y@qxi7arY`v!)RzEO5lHm2z~7=!*nq%S+<$-V(*vge1HjC=TBA+vHpvxocs~KhaFypf1Rp430B+jKQxMoM7-MgI_TCD%{sw1CzZ`ZR6m4 z@|ZwU(e%uG5>|QxcpJPr>;`{en|Fz+K0~3vC4}_sOe#&j$4=6ekR}UE$SzL~GsrS9 z!jjJh5HN55EIm@aG$Ardxpn00O#VX#%prM^L7u@htOmS;6?4MeXXrH|>G=o|=H`zH z1=S`iG7~H4J|>OEVg(HmVlzaTN=J^8*%bY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HjrtkP10a zOhzS7r36$Wt;8uFlXs33(Tz|Wp4upa1&=feQA4YFt&ke(6xar*t12yzW@21`D}0y` zmLTM71zmNKlM^!?$QMej-}&~#RbFJPz;183{l8t-Ak@jjl-E;GCRX#f4?OAqQpz2+ zue8C|jmCo|Ds{Ce^~-7D^dt`IRp5HgKs)S(>3pNcuLz17)LuhF8KA5^o|@$Ria^@K z;7qMntt?LWtBR%m71a_4dSaPesc7L>`!$tx@2ojcP@iH5wb#K)g#nIu4JCf9cpx!l zKq(#=uRf=1tk8J z0qoaTr{_^K2mNAcy&~gatllc+dXdWjC+jyuS%XPRUZ=^>+Q6GuHxI^kL`a+$qJuHV zKxCkY4&aN1I-CQ(axh5MCgykg=AV>AQU13d5^})C<85nJ_hGuU!%43 zD5D=R*v?>rK{^GOioC`6hYXl4`GmnGxYX#jDpIR=MZ?JzBodC2NJ!`!CjD`GiU>9~ z<*BYxl0~0&d{P2CoA&kG)u0UPyIaP$Trs((O|BEJ3#N)OqQ<`h%G{{^?Ww5cOQh8Zdc3XzbwRe@U)H2C=zuIt7-U{D6Gtz*O zWdmNE*C3mZc3zbGJYG!Z4K2>wP}X`Jx6v(pn`!dp%Fo#BzQXi#low^3tI6}ZSACyv z_jwZgTV)(R4~N>?rN2;dSK?ONIEQCp)K7GaG?0|j3+NT10}+x0+>xuAr9na%EI>(z zDf@RuV+=lH@Fs<%G#U#>M#xR*?kJZ&pppHFi4Nxq?iN%02H$ko<3)JTovFLa0?TGM z7+ZjR{!9CEaQWi)u;5+>_ZZ0NWe_W6!p@NK?jIt+|OydQC{LO~{AW(-aAkM$<(>{~0%p-Gm+$-Z%nuS3ni9{X9QV!wNGl>xgj!j6|Pdy)g!2F$oL aaerV2r#E8!D)55_IU{(kRRRlxKmQBJ>z~&E diff --git a/routes/conversations.py b/routes/conversations.py index 024c018..e411d6c 100644 --- a/routes/conversations.py +++ b/routes/conversations.py @@ -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') diff --git a/static/js/create-conversation.js b/static/js/create-conversation.js index 5364419..cee36d8 100644 --- a/static/js/create-conversation.js +++ b/static/js/create-conversation.js @@ -28,6 +28,15 @@ $(document).ready(function() { var creatorId = document.querySelector('.member-row').dataset.userId; addedMembers.add(creatorId); + // If in edit mode, add existing members to the set + if (document.querySelector('.member-row[data-user-id]')) { + document.querySelectorAll('.member-row[data-user-id]').forEach(function(row) { + var memberId = String(row.dataset.userId); + console.log('Adding existing member:', memberId); + addedMembers.add(memberId); + }); + } + /** * Shows an alert modal with the specified message. * @function @@ -45,7 +54,7 @@ $(document).ready(function() { * @event */ $('#addMemberBtn').click(function() { - var selectedUserId = $('#user_id').val(); + var selectedUserId = String($('#user_id').val()); var selectedUserName = $('#user_id option:selected').text(); var selectedUserEmail = $('#user_id option:selected').data('email') || ''; var selectedUserAvatar = $('#user_id option:selected').data('avatar') || "/static/default-avatar.png"; @@ -60,6 +69,7 @@ $(document).ready(function() { return; } + console.log('Adding new member:', selectedUserId); // Add to the set of added members addedMembers.add(selectedUserId); @@ -77,14 +87,6 @@ $(document).ready(function() { .append($(' + + {% endif %} + {% endfor %} + {% endif %}