merged from gramsrv upstream
This commit is contained in:
parent
79c64ee916
commit
21a0856587
651 changed files with 54774 additions and 4590 deletions
|
|
@ -3,21 +3,11 @@ package rpc
|
|||
import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/iamxvbaba/td/tg"
|
||||
|
||||
"telesrv/internal/domain"
|
||||
)
|
||||
|
||||
type phoneChangeEventConfirmer interface {
|
||||
ConfirmEvent(ctx context.Context, authKeyID [8]byte, userID int64, event domain.UpdateEvent) error
|
||||
}
|
||||
|
||||
type phoneChangeReliableDispatchReporter interface {
|
||||
PhoneChangeUsesReliableDispatch() bool
|
||||
}
|
||||
|
||||
func (r *Router) onAccountSendChangePhoneCode(ctx context.Context, req *tg.AccountSendChangePhoneCodeRequest) (tg.AuthSentCodeClass, error) {
|
||||
userID, found, err := r.currentUserID(ctx)
|
||||
if err != nil {
|
||||
|
|
@ -73,22 +63,11 @@ func (r *Router) onAccountChangePhone(ctx context.Context, req *tg.AccountChange
|
|||
return nil, internalErr()
|
||||
}
|
||||
r.invalidateRPCProjectionForUser(result.User.ID)
|
||||
if result.Event.Pts > 0 {
|
||||
if confirmer, ok := r.deps.Updates.(phoneChangeEventConfirmer); ok {
|
||||
if err := confirmer.ConfirmEvent(ctx, authKeyID, userID, result.Event); err != nil {
|
||||
// user/event/outbox 已原子提交,不能把已成功改号伪装成失败;当前
|
||||
// session 仍会收到 pts 簿记,设备水位存储可由后续 getDifference 自愈。
|
||||
r.log.Warn("confirm phone change event", zap.Int64("user_id", userID), zap.Int("pts", result.Event.Pts), zap.Error(err))
|
||||
}
|
||||
}
|
||||
reliable := false
|
||||
if reporter, ok := r.deps.Account.(phoneChangeReliableDispatchReporter); ok {
|
||||
reliable = reporter.PhoneChangeUsesReliableDispatch()
|
||||
}
|
||||
if !reliable {
|
||||
r.pushUserUpdates(ctx, userID, tgUpdateForOutboxEvent(result.Event))
|
||||
}
|
||||
r.bookkeepAuxPtsForCurrentSession(ctx, result.Event)
|
||||
if result.Changed {
|
||||
// account.changePhone returns the authoritative self User to the current
|
||||
// session. Other online sessions receive a non-PTS updateUser; offline
|
||||
// sessions converge on their next full-user/startup read.
|
||||
r.pushPremiumStatusUpdate(ctx, result.User)
|
||||
}
|
||||
return r.tgSelfUserWithUsernames(ctx, result.User), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue