modified app chat forum theme
This commit is contained in:
8
app.py
8
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})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user