From e1390a8adcd69d15e903963ab1b30ebdeccd6e57 Mon Sep 17 00:00:00 2001 From: Kobe Date: Sat, 31 May 2025 23:15:46 +0200 Subject: [PATCH] fix event filtering --- .../__pycache__/conversations.cpython-313.pyc | Bin 29378 -> 29378 bytes routes/__pycache__/main.cpython-313.pyc | Bin 59803 -> 60484 bytes routes/main.py | 18 ++++ static/js/notifications.js | 92 +++++++++++++++++- 4 files changed, 106 insertions(+), 4 deletions(-) diff --git a/routes/__pycache__/conversations.cpython-313.pyc b/routes/__pycache__/conversations.cpython-313.pyc index 4a7805f16e977c7f6fc679731919a8f289bbdc04..c049c162ccb214f4131e7fba42b48f56b1da335f 100644 GIT binary patch delta 20 acmX@~l=0A0M$XT?yj%=GP_vP9XAuBVAqLU_ delta 20 acmX@~l=0A0M$XT?yj%=Gz`K!iXAuBS_6B1B diff --git a/routes/__pycache__/main.cpython-313.pyc b/routes/__pycache__/main.cpython-313.pyc index eeb0d924a9fa403160e0ddccabc5550d942c2e2d..277727a866deedea307c4d3ac6b4e8e2e58a80a3 100644 GIT binary patch delta 2037 zcmZ{ldrVVj6u|FyOK%^P@@QcS#g^IvrBJX_Cq;0gP9@^h%G7~_h8D#E#oOw9G7*vu zog3z4i^7zU_$Etqclg*NnfQwO$7KG|OGRZdOI()4BK$F*+jm;rbk6(7ujf18dEIl* z_qFr7Vxu$8Vx*{powhIMd{Q?z~|}I+Ss>=lW`{6xJ7K~E{2I_42+L$P?pKd zSZ9(=GKEC!O-yJo9QVJzcd*=7%U2xS4IHr~7<$6TLdb{ov| z9OhDo*=b>+w#5dwHfO{4n~kg`6;xZQW&~xcJubJ0_wm@YptRQSsrT_`sm$*|JVIif5B*u^v(A$63+eZ?W#>w}!jN$cmPe{Y07`ig|W{Sp)fYIJ> zw2Nu!hxOh1Kw5r(TK+Xh>GiaQqAsngWN(S6H+5~@yEPE?r2JfS_{J5gc@9B-LDRe}oaJ1<4)EK1iAuk1QU?Vzf45i4bduUoUC z*oO?<`nV|Ve;kg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bm$#wB(KUp4b|&}WoxK9b<&i}wk3|PtlT>lH#pJL%KV4nvQ_2Wks5Irb1+HZ zmm#NoV&pVW+^}=BQz%CtX83V1JqZs^ANBC-sGr2;hBLSIOt~_)iIhWUELYfuK`P*Q zEYym|+#Jq@#`B+uckoUgUcFPr7gc(WCA$CO0kRXs@v^K2 z7U<^$=1Jldp(Pxl!FEL(>1c29ON9Dh&$x$F!)N2eqyfB_eB>qh!X+2c;VC4ZdSUT$ zhOh_ETCKh@*TiP>G6W|oG6HN-(o!G$qhZ88L^I+IxIEE7YQb^kJJKLOxDw(?2tt$g zzkHa%$vngIH$syRn4H`$tXQXBttRDi;HqpO2Oz{6gk9Mc+{)A>-QR2DElklJL^lFU zg`y_SLtr6E`jt|^h5xNF)lkZ1RbVqdEM%5UUA*)KwF#IphWgC+Gf5Hm`h87)8m3`f zk09PhsBHop+42+oM@99;ZNhSMfHU#O4QfwNYrX)k$2Sl=++}=6PX0beSbg86GrNfv zKAH)zSH3v2Pk0Y+(+9!X400HHXI~@V$g{H|SB8C(CgNr?!iq>o*brL~m53dP-H0B9 z8vO|5-+G1|mA$vlku Jh2*Ji^-rg3t9AeY diff --git a/routes/main.py b/routes/main.py index fbcc644..e539d9d 100644 --- a/routes/main.py +++ b/routes/main.py @@ -491,6 +491,24 @@ def init_routes(main_bp): # Get paginated notifications notifications = query.order_by(Notif.timestamp.desc()).paginate(page=page, per_page=per_page) + # Check if this is an AJAX request + if request.headers.get('X-Requested-With') == 'XMLHttpRequest': + return jsonify({ + 'notifications': [{ + 'id': notif.id, + 'notif_type': notif.notif_type, + 'timestamp': notif.timestamp.strftime('%Y-%m-%d %H:%M:%S'), + 'read': notif.read, + 'details': notif.details, + 'sender': { + 'username': notif.sender.username, + 'last_name': notif.sender.last_name + } if notif.sender else None + } for notif in notifications.items], + 'total_pages': total_pages, + 'current_page': page + }) + return render_template('notifications/notifications.html', notifications=notifications.items, total_pages=total_pages, diff --git a/static/js/notifications.js b/static/js/notifications.js index 428f339..bb7ac9a 100644 --- a/static/js/notifications.js +++ b/static/js/notifications.js @@ -66,14 +66,68 @@ document.addEventListener('DOMContentLoaded', function() { } const data = await response.json(); - updateNotificationsTable(data.notifications); - updatePagination(data.total_pages, data.current_page); - // Reinitialize tooltips after updating the table + // Update the table with the notifications + if (data.notifications && data.notifications.length > 0) { + notifsTableBody.innerHTML = data.notifications.map(notif => ` + + ${notif.timestamp} + ${getNotifTypeBadge(notif.notif_type)} + ${notif.sender ? `${notif.sender.username} ${notif.sender.last_name}` : 'System'} + + ${notif.read ? + 'Read' : + 'Unread'} + + +
+ ${getActionButtons(notif)} + + ${!notif.read ? ` + + ` : ''} + +
+ + + `).join(''); + } else { + notifsTableBody.innerHTML = 'No notifications found'; + } + + // Update pagination + totalPages = data.total_pages; + currentPage = data.current_page; + currentPageSpan.textContent = currentPage; + totalPagesSpan.textContent = totalPages; + prevPageBtn.disabled = currentPage <= 1; + nextPageBtn.disabled = currentPage >= totalPages; + + // Reinitialize tooltips const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); tooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl); }); + + // Reattach event listeners + attachEventListeners(); } catch (error) { console.error('Error fetching notifications:', error); notifsTableBody.innerHTML = 'Error loading notifications'; @@ -330,4 +384,34 @@ document.addEventListener('DOMContentLoaded', function() { updateURL(); } }); -}); \ No newline at end of file +}); + +// Function to get action buttons based on notification type +function getActionButtons(notif) { + if (notif.notif_type === 'room_invite' || notif.notif_type === 'room_invite_removed') { + if (notif.details && notif.details.room_id) { + return ` + + + + `; + } + } else if (notif.notif_type === 'conversation_invite' || + notif.notif_type === 'conversation_invite_removed' || + notif.notif_type === 'conversation_message') { + if (notif.details && notif.details.conversation_id) { + return ` + + + + `; + } + } + return ''; +} \ No newline at end of file