From 7976f11cf4f03c84a030d1d9dd62d29e1dc04a83 Mon Sep 17 00:00:00 2001 From: unknown <1251316345@qq.com> Date: Fri, 27 Feb 2026 14:48:37 +0800 Subject: [PATCH] modified app chat forum theme --- app.py | 8 +++++++- templates/chat.html | 44 ++++++++++++++++++++++++++++++++++++++++---- templates/forum.html | 24 +++++++++++++++++++++++- 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index b0c883f..1185e3f 100644 --- a/app.py +++ b/app.py @@ -704,9 +704,10 @@ def api_add_friend(): return jsonify({'success': False, 'message': '已经是好友或已发送请求'}), 400 friend_req = Friend(user_id=user_id, friend_id=friend_id, status='pending') db.session.add(friend_req) + db.session.flush() # 发送通知给对方 sender_name = session['user'].get('name', '未知用户') - notif = Notification(user_id=friend_id, type='friend_request', content=f'{sender_name} 请求添加你为好友', from_user=sender_name) + notif = Notification(user_id=friend_id, type='friend_request', content=f'{sender_name} 请求添加你为好友', from_user=sender_name, post_id=friend_req.id) db.session.add(notif) db.session.commit() return jsonify({'success': True, 'message': '好友请求已发送'}) @@ -1104,6 +1105,11 @@ def api_notifications(): item['contest_name'] = contest.name if contest else '' applicant = User.query.get(ta.user_id) item['applicant_name'] = applicant.name if applicant else '' + if n.type == 'friend_request' and n.post_id: + fr = Friend.query.get(n.post_id) + if fr: + item['application_status'] = fr.status + item['friend_request_id'] = fr.id result.append(item) return jsonify({'success': True, 'notifications': result}) diff --git a/templates/chat.html b/templates/chat.html index c787e7e..226dcd4 100644 --- a/templates/chat.html +++ b/templates/chat.html @@ -384,17 +384,20 @@ function renderNotifications() { list.innerHTML = notifData.map(n => { const isContestApp = n.type === 'contest_application'; const isTeacherApp = n.type === 'teacher_application'; + const isFriendReq = n.type === 'friend_request'; const isResult = n.type === 'contest_result' || n.type === 'teacher_result'; const isNewExam = n.type === 'contest_new_exam'; const isGraded = n.type === 'exam_graded'; const isSystem = n.type === 'system_announcement'; const isPendingContest = isContestApp && n.application_status === 'pending'; const isPendingTeacher = isTeacherApp && n.application_status === 'pending'; + const isPendingFriend = isFriendReq && n.application_status === 'pending'; let statusHtml = ''; if ((isContestApp || isTeacherApp) && n.application_status === 'approved') statusHtml = '已批准'; else if ((isContestApp || isTeacherApp) && n.application_status === 'rejected') statusHtml = '已拒绝'; - const icon = isContestApp ? '📋' : isTeacherApp ? '👨🏫' : isResult ? '📢' : isNewExam ? '📝' : isGraded ? '✅' : isSystem ? '📢' : '🔔'; - const iconBg = isContestApp ? 'bg-orange-100' : isTeacherApp ? 'bg-purple-100' : isResult ? 'bg-green-100' : isNewExam ? 'bg-indigo-100' : isGraded ? 'bg-emerald-100' : isSystem ? 'bg-amber-100' : 'bg-blue-100'; + else if (isFriendReq && n.application_status === 'accepted') statusHtml = '已同意'; + const icon = isContestApp ? '📋' : isTeacherApp ? '👨🏫' : isFriendReq ? '👤' : isResult ? '📢' : isNewExam ? '📝' : isGraded ? '✅' : isSystem ? '📢' : '🔔'; + const iconBg = isContestApp ? 'bg-orange-100' : isTeacherApp ? 'bg-purple-100' : isFriendReq ? 'bg-blue-100' : isResult ? 'bg-green-100' : isNewExam ? 'bg-indigo-100' : isGraded ? 'bg-emerald-100' : isSystem ? 'bg-amber-100' : 'bg-blue-100'; const clickAction = `showNotifDetail(${n.id})`; let actionsHtml = ''; if (isPendingContest && currentUser.role === 'admin') { @@ -409,6 +412,12 @@ function renderNotifications() { `; } + if (isPendingFriend && n.friend_request_id) { + actionsHtml = `