提交2: 发布群核心功能实现

- 实现 EnsureListingConversation: 发布时建发布群,发欢迎语+二维码
- 实现 AddRenterToListingConversation: 付款后拉租客进群
- 实现 RemoveRenterFromListingConversation: 订单终态移出租客
- 实现消息可见性过滤: 租客只能看到 joined_at 之后的消息
- listing 模块注入 ListingChatCreator 接口,发布时建群
- ListingDTO 新增 listing_group_conversation_id 字段
- 付款流程改为拉租客进发布群(替代建订单群)
- 订单完成和取消时自动移出租客
- 创建 chat 适配器实现接口解耦

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
yml
2026-06-17 15:57:10 +08:00
co-authored by Claude Opus 4.8
parent 423c142967
commit ad70b24fb6
9 changed files with 446 additions and 39 deletions
+16 -4
View File
@@ -14,11 +14,15 @@ 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" {
if _, err := r.findParticipant(db, principal, conversationID, false); err != nil {
p, err := r.findParticipant(db, principal, conversationID, false)
if err != nil {
return nil, err
}
participant = p
} else {
// 管理员需要验证会话存在
var count int64
@@ -30,14 +34,22 @@ 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 := db.Model(&model.ChatMessage{}).Where("conversation_id = ?", conversationID).Count(&total).Error; err != nil {
if err := query.Count(&total).Error; err != nil {
return nil, err
}
offset := (page - 1) * pageSize
var rows []model.ChatMessage
if err := db.Where("conversation_id = ?", conversationID).
Order("id ASC").
if err := query.Order("id ASC").
Offset(offset).
Limit(pageSize).
Find(&rows).Error; err != nil {