feat: sync recent call and channel fixes

This commit is contained in:
A 2026-07-01 14:34:59 +08:00
parent e5e0080216
commit 866a87583e
65 changed files with 6680 additions and 229 deletions

View file

@ -6,6 +6,7 @@ package groupcalls
import (
"context"
"crypto/rand"
"encoding/base64"
"encoding/binary"
"fmt"
@ -44,10 +45,55 @@ func (s *Service) Create(ctx context.Context, channelID, creatorUserID int64, ti
})
}
// CreateConference 分配 id/access_hash/slug 并创建 ad-hoc conference call。
func (s *Service) CreateConference(ctx context.Context, creatorUserID, randomID, migratedFromPhoneCallID int64, now int) (domain.GroupCall, error) {
for i := 0; i < 8; i++ {
id, err := randomPositiveInt64()
if err != nil {
return domain.GroupCall{}, err
}
accessHash, err := randomPositiveInt64()
if err != nil {
return domain.GroupCall{}, err
}
slug, err := randomSlug()
if err != nil {
return domain.GroupCall{}, err
}
call, err := s.store.CreateConferenceCall(ctx, domain.GroupCall{
ID: id,
AccessHash: accessHash,
CreatorUserID: creatorUserID,
Kind: domain.GroupCallKindConference,
Version: 1,
CreatedAt: now,
InviteSlug: slug,
InviteLink: conferenceInviteLink(slug),
RandomID: randomID,
MigratedFromPhoneCallID: migratedFromPhoneCallID,
})
if err == nil {
return call, nil
}
if err != domain.ErrGroupCallInvalid {
return domain.GroupCall{}, err
}
}
return domain.GroupCall{}, fmt.Errorf("groupcalls: exhausted conference slug attempts")
}
func (s *Service) Get(ctx context.Context, callID int64) (domain.GroupCall, bool, error) {
return s.store.GetGroupCall(ctx, callID)
}
func (s *Service) GetBySlug(ctx context.Context, slug string) (domain.GroupCall, bool, error) {
return s.store.GetGroupCallBySlug(ctx, slug)
}
func (s *Service) GetByInviteMessage(ctx context.Context, userID int64, msgID int) (domain.GroupCall, domain.GroupCallInvite, bool, error) {
return s.store.GetGroupCallByInviteMessage(ctx, userID, msgID)
}
func (s *Service) Join(ctx context.Context, req domain.JoinGroupCallRequest) (domain.GroupCallMutation, error) {
return s.store.JoinGroupCall(ctx, req)
}
@ -56,6 +102,10 @@ func (s *Service) Leave(ctx context.Context, callID, userID int64, now int) (dom
return s.store.LeaveGroupCall(ctx, callID, userID, now)
}
func (s *Service) RemoveConferenceParticipants(ctx context.Context, req domain.RemoveConferenceCallParticipantsRequest) (domain.RemoveConferenceCallParticipantsResult, error) {
return s.store.RemoveConferenceCallParticipants(ctx, req)
}
func (s *Service) Discard(ctx context.Context, callID int64, now int) (domain.GroupCall, []domain.GroupCallParticipant, error) {
return s.store.DiscardGroupCall(ctx, callID, now)
}
@ -108,6 +158,26 @@ func (s *Service) ParticipantOverride(ctx context.Context, callID, setterUserID,
return s.store.GetParticipantOverride(ctx, callID, setterUserID, targetUserID)
}
func (s *Service) CreateConferenceInvite(ctx context.Context, invite domain.GroupCallInvite) (domain.GroupCallInvite, error) {
return s.store.CreateConferenceInvite(ctx, invite)
}
func (s *Service) SetConferenceInviteStatus(ctx context.Context, callID, inviteeUserID int64, msgID int, status domain.GroupCallInviteStatus, now int) (domain.GroupCallInvite, bool, error) {
return s.store.SetConferenceInviteStatus(ctx, callID, inviteeUserID, msgID, status, now)
}
func (s *Service) ConferenceRecipients(ctx context.Context, callID int64) ([]int64, error) {
return s.store.ListConferenceRecipientUserIDs(ctx, callID)
}
func (s *Service) AppendChainBlock(ctx context.Context, block domain.GroupCallChainBlock) (domain.GroupCallChainBlock, error) {
return s.store.AppendGroupCallChainBlock(ctx, block)
}
func (s *Service) ChainBlocks(ctx context.Context, callID int64, subChainID, offset, limit int) (domain.GroupCallChainBlockPage, error) {
return s.store.ListGroupCallChainBlocks(ctx, callID, subChainID, offset, limit)
}
func randomPositiveInt64() (int64, error) {
var buf [8]byte
if _, err := rand.Read(buf[:]); err != nil {
@ -119,3 +189,15 @@ func randomPositiveInt64() (int64, error) {
}
return v, nil
}
func randomSlug() (string, error) {
var buf [18]byte
if _, err := rand.Read(buf[:]); err != nil {
return "", fmt.Errorf("groupcalls: random slug: %w", err)
}
return base64.RawURLEncoding.EncodeToString(buf[:]), nil
}
func conferenceInviteLink(slug string) string {
return "https://telesrv.net/call/" + slug + "?slug=" + slug
}