Avoid post-login configuration on reconnects and relogins during a session

This commit is contained in:
Bohdan Horbeshko 2025-07-21 12:29:07 -04:00
parent 9ee13bf582
commit 2dd521c3ed
3 changed files with 19 additions and 1 deletions

View file

@ -57,12 +57,19 @@ type IntPair struct {
type barrier struct { type barrier struct {
mu sync.Mutex mu sync.Mutex
open bool open bool
released bool
releaseCh chan struct{} releaseCh chan struct{}
} }
// Wait blocks until the barrier is released. // Wait blocks until the barrier is released.
func (b *barrier) Wait() { func (b *barrier) Wait() {
b.mu.Lock() b.mu.Lock()
if b.released {
b.mu.Unlock()
return
}
if !b.open { if !b.open {
b.open = true b.open = true
b.releaseCh = make(chan struct{}) // Reinitialize the channel b.releaseCh = make(chan struct{}) // Reinitialize the channel
@ -81,6 +88,8 @@ func (b *barrier) Done() {
if b.open { if b.open {
close(b.releaseCh) // Close the channel to release waiting goroutines close(b.releaseCh) // Close the channel to release waiting goroutines
b.open = false // Mark the barrier as closed b.open = false // Mark the barrier as closed
} else {
b.released = true
} }
} }

View file

@ -145,9 +145,11 @@ func (c *Client) Connect(resource string) error {
c.Session.Login = c.me.PhoneNumber c.Session.Login = c.me.PhoneNumber
} }
log.Debug("waiting for loginFinish")
c.locks.loginFinish.Wait() c.locks.loginFinish.Wait()
go c.updateHandler() go c.updateHandler()
log.Warn("Going online")
c.online = true c.online = true
c.locks.authorizationReady.Unlock() c.locks.authorizationReady.Unlock()
c.addResource(resource) c.addResource(resource)
@ -163,6 +165,7 @@ func (c *Client) Connect(resource string) error {
gateway.SubscribeToTransport(c.xmpp, c.jid) gateway.SubscribeToTransport(c.xmpp, c.jid)
c.sendPresence(gateway.SPStatus("Logged in as: " + c.Session.Login)) c.sendPresence(gateway.SPStatus("Logged in as: " + c.Session.Login))
}() }()
log.Warn("Client connected!")
return nil return nil
} }
@ -248,6 +251,7 @@ func (c *Client) Disconnect(resource string, quit bool) bool {
} }
func (c *Client) interactor() { func (c *Client) interactor() {
wasSessionLoginEmpty := c.Session.Login == ""
for { for {
c.locks.authorizerReadLock.Lock() c.locks.authorizerReadLock.Lock()
if c.authorizer == nil { if c.authorizer == nil {
@ -293,7 +297,11 @@ func (c *Client) interactor() {
c.locks.authorizerReadLock.Unlock() c.locks.authorizerReadLock.Unlock()
} }
if c.loginStage != LoginStageCancel { if c.loginStage != LoginStageCancel {
if wasSessionLoginEmpty {
c.wizardStageOrPrompt(LoginStagePreset, "Do you want to use a config preset? `/preset modern` enables brand new XMPP features, `/preset classic` targets legacy clients stuck in 00s. /pass proceeds to the next stage.") c.wizardStageOrPrompt(LoginStagePreset, "Do you want to use a config preset? `/preset modern` enables brand new XMPP features, `/preset classic` targets legacy clients stuck in 00s. /pass proceeds to the next stage.")
} else {
c.wizardStageOrPrompt(LoginStageSuccess, "")
}
} }
} }

View file

@ -26,6 +26,7 @@ func (c *Client) setLoginStage(stage LoginStage) {
case LoginStageSuccess, LoginStageCancel: case LoginStageSuccess, LoginStageCancel:
c.locks.loginFinish.Done() c.locks.loginFinish.Done()
} }
log.Debugf("set loginStage %v", stage)
} }
// StartLoginWizard initiates a loginWizard object // StartLoginWizard initiates a loginWizard object