fix: sync streamline self username cache convergence

This commit is contained in:
iamxvbaba 2026-08-02 19:32:18 +08:00
parent 8bc1560c16
commit 8356989e01
12 changed files with 294 additions and 89 deletions

View file

@ -210,26 +210,39 @@ func (r *Router) maybeMarkSessionReceivesUpdates(ctx context.Context) {
if !ok {
return
}
if provider, ok := r.deps.Sessions.(SessionUpdatesStateProvider); ok {
rawAuthKeyID, okRaw := RawAuthKeyIDFrom(ctx)
sessionID, okSess := SessionIDFrom(ctx)
if okRaw && okSess && provider.ReceivesUpdatesForAuthKey(rawAuthKeyID, sessionID) {
return
}
if r.sessionUpdatesActivationStarted(ctx) {
return
}
r.stageSessionUpdatesReadyAfterDelivery(ctx, userID)
}
func (r *Router) markSessionReceivesUpdatesNow(ctx context.Context, userID int64) {
func (r *Router) sessionUpdatesActivationStarted(ctx context.Context) bool {
provider, ok := r.deps.Sessions.(SessionUpdatesStateProvider)
if !ok {
return false
}
rawAuthKeyID, okRaw := RawAuthKeyIDFrom(ctx)
sessionID, okSession := SessionIDFrom(ctx)
return okRaw && okSession && provider.UpdatesActivationStartedForAuthKey(rawAuthKeyID, sessionID)
}
func (r *Router) markSessionReceivesUpdatesNow(ctx context.Context, userID int64) bool {
if r.deps.Sessions == nil {
return
return false
}
r.syncSessionChannelMemberships(ctx, userID)
sessionID, ok := SessionIDFrom(ctx)
if !ok {
return
return false
}
r.deps.Sessions.SetReceivesUpdatesForAuthKey(rawAuthKeyIDForOrigin(ctx), sessionID, true)
if _, ok := r.deps.Sessions.(SessionUpdatesStateProvider); !ok {
// Alternate lightweight binders cannot expose flushing/membership state.
// Preserve their historical behavior; the Router claim still collapses
// callbacks which overlap this activation attempt.
return true
}
return r.sessionUpdatesActivationStarted(ctx)
}
func ptr[T any](v T) *T { return &v }