2026-05-15 17:57:22 +08:00

41 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright © 2023 OpenIM. All rights reserved.
package conversation
import (
"context"
"time"
pbconversation "github.com/openimsdk/protocol/conversation"
)
// computeIsMuted 根据会话模型中存储的 mute_duration 和 mute_end_time 计算当前是否处于静音状态:
// - duration == 0 且 end == 0未静音
// - duration == -1 且 end == 0永久静音
// - end > 0 且 end > now定时静音仍有效
// - end > 0 且 end <= now定时静音已过期视为未静音
func computeIsMuted(muteDuration int32, muteEndTime int64) bool {
if muteDuration == 0 && muteEndTime == 0 {
return false
}
if muteDuration == -1 && muteEndTime == 0 {
return true
}
return muteEndTime > time.Now().Unix()
}
// fillConversationUserMute 根据会话模型字段(已由 ConversationDB2Pb 通过 CopyStructFields 填入
// conv.MuteDuration / conv.MuteEndTime计算并设置 conv.IsMuted无需额外数据库查询。
func (c *conversationServer) fillConversationUserMute(_ context.Context, conv *pbconversation.Conversation) {
if conv == nil {
return
}
conv.IsMuted = computeIsMuted(conv.MuteDuration, conv.MuteEndTime)
}
func (c *conversationServer) fillConversationsUserMute(ctx context.Context, list []*pbconversation.Conversation) {
for _, conv := range list {
c.fillConversationUserMute(ctx, conv)
}
}