Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type MetaClient struct {
E2EEClient *whatsmeow.Client
WADevice *store.Device
e2eeConnectLock sync.Mutex
waGenericErrors int

metaState status.BridgeState
waState status.BridgeState
Expand Down
7 changes: 7 additions & 0 deletions pkg/connector/handlewhatsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"go.mau.fi/mautrix-meta/pkg/metaid"
)

var MaxGenericWhatsappErrorRetries = 5

func (m *MetaClient) e2eeEventHandler(rawEvt any) bool {
if m == nil || m.E2EEClient == nil {
return false
Expand Down Expand Up @@ -80,6 +82,7 @@ func (m *MetaClient) e2eeEventHandler(rawEvt any) bool {
m.e2eeConnectWaiter.Set()
m.waState = status.BridgeState{StateEvent: status.StateConnected}
m.UserLogin.BridgeState.Send(m.waState)
m.waGenericErrors = 0
case *events.Disconnected:
log.Debug().Msg("Disconnected from WhatsApp socket")
m.e2eeConnectWaiter.Clear()
Expand Down Expand Up @@ -128,6 +131,10 @@ func (m *MetaClient) e2eeEventHandler(rawEvt any) bool {
m.resetWADevice()
log.Debug().Msg("Doing full reconnect after WhatsApp 418 error")
go m.FullReconnect()
} else if e.Reason == events.ConnectFailureGeneric && m.canReconnect() && m.waGenericErrors < MaxGenericWhatsappErrorRetries {
log.Debug().Msg("Doing full reconnect after WhatsApp 400 error")
m.waGenericErrors++
go m.FullReconnect()
}
}

Expand Down