feat(conversations): add notification mute functionality for conversations
- Rename Muted field to NotificationMuted across model, DTOs and converters - Add UpdateNotificationMuted repository method with upsert support - Add SetConversationNotificationMuted service method - Add PUT /:id/notification_muted route for setting mute status - Improve S3 storage resilience by skipping bucket check on access denied
This commit is contained in:
@@ -28,6 +28,7 @@ type MessageRepository interface {
|
||||
GetParticipant(conversationID string, userID string) (*model.ConversationParticipant, error)
|
||||
UpdateLastReadSeq(conversationID string, userID string, lastReadSeq int64) error
|
||||
UpdatePinned(conversationID string, userID string, isPinned bool) error
|
||||
UpdateNotificationMuted(conversationID string, userID string, notificationMuted bool) error
|
||||
GetUnreadCount(conversationID string, userID string) (int64, error)
|
||||
UpdateConversationLastSeq(conversationID string, seq int64) error
|
||||
GetNextSeq(conversationID string) (int64, error)
|
||||
@@ -337,6 +338,36 @@ func (r *messageRepository) UpdatePinned(conversationID string, userID string, i
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateNotificationMuted 更新会话免打扰状态(用户维度)
|
||||
func (r *messageRepository) UpdateNotificationMuted(conversationID string, userID string, notificationMuted bool) error {
|
||||
result := r.db.Model(&model.ConversationParticipant{}).
|
||||
Where("conversation_id = ? AND user_id = ?", conversationID, userID).
|
||||
Update("muted", notificationMuted)
|
||||
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
|
||||
if result.RowsAffected == 0 {
|
||||
return r.db.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{
|
||||
{Name: "conversation_id"},
|
||||
{Name: "user_id"},
|
||||
},
|
||||
DoUpdates: clause.Assignments(map[string]any{
|
||||
"muted": notificationMuted,
|
||||
"updated_at": gorm.Expr("CURRENT_TIMESTAMP"),
|
||||
}),
|
||||
}).Create(&model.ConversationParticipant{
|
||||
ConversationID: conversationID,
|
||||
UserID: userID,
|
||||
NotificationMuted: notificationMuted,
|
||||
}).Error
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUnreadCount 获取未读消息数
|
||||
// userID 参数为 string 类型(UUID格式),与JWT中user_id保持一致
|
||||
func (r *messageRepository) GetUnreadCount(conversationID string, userID string) (int64, error) {
|
||||
|
||||
Reference in New Issue
Block a user