Skip to content

Commit

Permalink
client: send bridge states for whatsapp initial connect errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Dec 12, 2024
1 parent f2a28ab commit 273690a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
22 changes: 22 additions & 0 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ func (m *MetaClient) periodicReconnect() {
}
}

func (m *MetaClient) tryConnectE2EE(fromConnectFailure bool) {
err := m.connectE2EE()
if err != nil {
if m.waState.StateEvent != status.StateBadCredentials && m.waState.StateEvent != status.StateUnknownError {
m.waState = status.BridgeState{
StateEvent: status.StateUnknownError,
Error: WAConnectError,
Info: map[string]any{
"go_error": err.Error(),
},
}
m.UserLogin.BridgeState.Send(m.waState)
}
if fromConnectFailure {
m.UserLogin.Log.Err(err).Msg("Failed to connect to e2ee after 415 error")
} else {
m.UserLogin.Log.Err(err).Msg("Failed to connect to e2ee")
}
}
}

func (m *MetaClient) connectE2EE() error {
m.e2eeConnectLock.Lock()
defer m.e2eeConnectLock.Unlock()
Expand Down Expand Up @@ -407,6 +428,7 @@ func (m *MetaClient) FillBridgeState(state status.BridgeState) status.BridgeStat
state.StateEvent = copyFrom.StateEvent
state.Error = copyFrom.Error
state.Message = copyFrom.Message
state.Info = copyFrom.Info
}
}
if m.LoginMeta.LoginUA != "" {
Expand Down
8 changes: 2 additions & 6 deletions pkg/connector/handlemeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
WADisconnected status.BridgeStateErrorCode = "wa-transient-disconnect"
WAPermanentError status.BridgeStateErrorCode = "wa-unknown-permanent-error"
WACATError status.BridgeStateErrorCode = "wa-cat-refresh-error"
WAConnectError status.BridgeStateErrorCode = "wa-unknown-connect-error"
MetaConnectionUnauthorized status.BridgeStateErrorCode = "meta-connection-unauthorized"
MetaPermanentError status.BridgeStateErrorCode = "meta-unknown-permanent-error"
MetaCookieRemoved status.BridgeStateErrorCode = "meta-cookie-removed"
Expand Down Expand Up @@ -79,12 +80,7 @@ func (m *MetaClient) handleMetaEvent(rawEvt any) {
m.incomingTables <- tbl
}
if m.LoginMeta.Platform.IsMessenger() || m.Main.Config.IGE2EE {
go func() {
err := m.connectE2EE()
if err != nil {
log.Err(err).Msg("Error connecting to e2ee")
}
}()
go m.tryConnectE2EE(false)
}
m.metaState = status.BridgeState{StateEvent: status.StateConnected}
m.UserLogin.BridgeState.Send(m.metaState)
Expand Down
7 changes: 1 addition & 6 deletions pkg/connector/handlewhatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,7 @@ func (m *MetaClient) e2eeEventHandler(rawEvt any) {
m.E2EEClient = nil
}
log.Debug().Msg("Reconnecting e2ee client after WhatsApp 415 error")
go func() {
err := m.connectE2EE()
if err != nil {
log.Err(err).Msg("Error connecting to e2ee after 415 error")
}
}()
go m.tryConnectE2EE(true)
}
}

Expand Down

0 comments on commit 273690a

Please sign in to comment.