owpengram-server/internal/store/memory/channel_groupcall.go

47 lines
1.6 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.

package memory
import (
"context"
"telesrv/internal/domain"
)
// SetActiveCall 写入/清除 channel 行上的活跃群通话关联。
func (s *ChannelStore) SetActiveCall(_ context.Context, channelID, callID, callAccessHash int64, notEmpty bool) (domain.Channel, error) {
s.mu.Lock()
defer s.mu.Unlock()
ch, ok := s.channels[channelID]
if !ok || ch.Deleted {
return domain.Channel{}, domain.ErrChannelInvalid
}
ch.ActiveCallID = callID
ch.ActiveCallAccessHash = callAccessHash
ch.ActiveCallNotEmpty = notEmpty && callID != 0
s.channels[channelID] = ch
return ch, nil
}
// AppendCallServiceMessage 生成群通话服务消息(带频道 pts
func (s *ChannelStore) AppendCallServiceMessage(_ context.Context, channelID, senderUserID int64, date int, action domain.ChannelMessageAction) (domain.SendChannelMessageResult, error) {
return s.appendServiceMessageLocked(channelID, senderUserID, date, action)
}
func (s *ChannelStore) appendServiceMessageLocked(channelID, senderUserID int64, date int, action domain.ChannelMessageAction) (domain.SendChannelMessageResult, error) {
s.mu.Lock()
defer s.mu.Unlock()
ch, ok := s.channels[channelID]
if !ok || ch.Deleted {
return domain.SendChannelMessageResult{}, domain.ErrChannelInvalid
}
msg, event := s.appendChannelServiceMessageLocked(channelID, senderUserID, date, action)
ch = s.channels[channelID]
ch.TopMessageID = msg.ID
ch.Pts = event.Pts
s.channels[channelID] = ch
return domain.SendChannelMessageResult{
Channel: ch,
Message: msg,
Event: event,
Recipients: s.activeMemberIDsLocked(channelID, 0, 0),
}, nil
}