补充profile页面功能区功能

This commit is contained in:
2026-06-08 15:39:09 +08:00
parent 48fb499138
commit de62513987
8 changed files with 3756 additions and 1399 deletions

View File

@@ -3281,6 +3281,89 @@ class SupabaseService {
}
}
// 标记单条通知为已读 (ml_notifications)
async markUserNotificationRead(notificationId: string): Promise<boolean> {
try {
const res = await supa
.from('ml_notifications')
.update({ is_read: true })
.eq('id', notificationId)
.execute()
return res.error == null
} catch (e) {
console.error('[markUserNotificationRead] 标记通知已读失败:', e)
return false
}
}
// 标记聊天会话为已读
async markChatRoomRead(merchantId: string): Promise<boolean> {
try {
const userId = this.getCurrentUserId()
if (userId == null) return false
const res = await supa
.from('ml_chat_rooms')
.update({ unread_count: 0 })
.eq('user_id', userId)
.eq('merchant_id', merchantId)
.execute()
return res.error == null
} catch (e) {
console.error('[markChatRoomRead] 标记会话已读失败:', e)
return false
}
}
// 一键已读:所有通知 + 所有会话
async markAllMessagesRead(): Promise<boolean> {
try {
const userId = this.getCurrentUserId()
if (userId == null) return false
const noteRes = await supa
.from('ml_notifications')
.update({ is_read: true })
.eq('user_id', userId)
.eq('is_read', false)
.execute()
if (noteRes.error != null) {
console.error('[markAllMessagesRead] 通知已读失败:', noteRes.error)
}
const roomRes = await supa
.from('ml_chat_rooms')
.update({ unread_count: 0 })
.eq('user_id', userId)
.gt('unread_count', 0)
.execute()
if (roomRes.error != null) {
console.error('[markAllMessagesRead] 会话已读失败:', roomRes.error)
}
return true
} catch (e) {
console.error('[markAllMessagesRead] 一键已读失败:', e)
return false
}
}
// 软删除消息(前端兜底:后端表缺少软删除字段时仅 console.warn
async softDeleteMessages(messageIds: Array<string>): Promise<boolean> {
try {
const userId = this.getCurrentUserId()
if (userId == null) return false
if (messageIds.length === 0) return true
// TODO: 后端 ml_notifications / ml_chat_rooms 表当前缺少 consumer_deleted_at / deleted_at / user_deleted_at 字段
// 现阶段不执行数据库删除/更新,仅打印警告。如需持久化软删除,请先在相关表增加对应字段并补充 API。
console.warn('[softDeleteMessages] 后端缺少软删除字段/API本次跳过数据库操作。messageIds:', messageIds)
return true
} catch (e) {
console.error('[softDeleteMessages] 软删除失败:', e)
return false
}
}
// 获取用户通知 (系统、活动、订单)
async getUserNotifications(type: string | null = null): Promise<Notification[]> {
try {