优化了消息数量,筛选和顶部部分
This commit is contained in:
@@ -40,6 +40,18 @@ func (r *Repository) conversationQuery(ctx context.Context, principal Principal)
|
||||
Joins("JOIN chat_participants AS cp ON cp.conversation_id = c.id").
|
||||
Where("cp.participant_type = ? AND cp.participant_id = ?", principal.Type, principal.ID)
|
||||
}
|
||||
|
||||
func (r *Repository) CountUnreadMessages(ctx context.Context, principal Principal) (int64, error) {
|
||||
var total int64
|
||||
err := r.db.WithContext(ctx).Table("chat_messages AS cm").
|
||||
Joins("JOIN chat_participants AS cp ON cp.conversation_id = cm.conversation_id").
|
||||
Where("cp.participant_type = ? AND cp.participant_id = ?", principal.Type, principal.ID).
|
||||
Where("NOT (cm.sender_type = ? AND cm.sender_id = ?)", principal.Type, principal.ID).
|
||||
Where("(cp.last_read_at IS NULL OR cm.created_at > cp.last_read_at)").
|
||||
Count(&total).Error
|
||||
return total, err
|
||||
}
|
||||
|
||||
func (r *Repository) findParticipant(tx *gorm.DB, principal Principal, conversationID uint64, lock bool) (*model.ChatParticipant, error) {
|
||||
var participant model.ChatParticipant
|
||||
db := tx
|
||||
|
||||
Reference in New Issue
Block a user