优化发布群租客清退与历史消息
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user