优化发布群租客清退与历史消息

This commit is contained in:
yml
2026-06-18 09:39:23 +08:00
parent 233920025e
commit f4361c9804
10 changed files with 325 additions and 33 deletions
+1 -10
View File
@@ -14,15 +14,11 @@ func (r *Repository) Messages(ctx context.Context, principal Principal, conversa
page, pageSize = normalizePagination(page, pageSize)
db := r.db.WithContext(ctx)
var participant *model.ChatParticipant
// 管理员可以查看任意会话的消息,普通用户需要是 participant
if principal.Type != "admin" {
p, err := r.findParticipant(db, principal, conversationID, false)
if err != nil {
if _, err := r.findParticipant(db, principal, conversationID, false); err != nil {
return nil, err
}
participant = p
} else {
// 管理员需要验证会话存在
var count int64
@@ -37,11 +33,6 @@ func (r *Repository) Messages(ctx context.Context, principal Principal, conversa
// 构建查询
query := db.Model(&model.ChatMessage{}).Where("conversation_id = ?", conversationID)
// 租客只能看到加入时间之后的消息
if principal.Type == "user" && participant != nil && participant.Role == "renter" {
query = query.Where("created_at >= ?", participant.JoinedAt)
}
var total int64
if err := query.Count(&total).Error; err != nil {
return nil, err