mirror of
https://github.com/mautrix/whatsapp.git
synced 2026-11-09 15:49:18 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fd355360c |
3 changed files with 26 additions and 17 deletions
2
go.mod
2
go.mod
|
|
@ -20,7 +20,7 @@ require (
|
|||
golang.org/x/sync v0.24.0
|
||||
google.golang.org/protobuf v1.36.12
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
maunium.net/go/mautrix v0.32.0
|
||||
maunium.net/go/mautrix v0.32.1-0.20261025192835-58302644df53
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -103,5 +103,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
|
||||
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
|
||||
maunium.net/go/mautrix v0.32.0 h1:xuAZzzyWce0pFkBhV/MCLFiJdVs2rFkY3Eep7hNng4I=
|
||||
maunium.net/go/mautrix v0.32.0/go.mod h1:tZSwPzw+/0pa0dxGufkh0uJqM84BNxB6e2I0+S0UyjU=
|
||||
maunium.net/go/mautrix v0.32.1-0.20261025192835-58302644df53 h1:bL8PdtUUkpuHNO+r7fnyzrSUk3b8d7+f/E/r1HInRkg=
|
||||
maunium.net/go/mautrix v0.32.1-0.20261025192835-58302644df53/go.mod h1:tZSwPzw+/0pa0dxGufkh0uJqM84BNxB6e2I0+S0UyjU=
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ var (
|
|||
_ bridgev2.LoginProcessDisplayAndWait = (*WALogin)(nil)
|
||||
_ bridgev2.LoginProcessUserInput = (*WALogin)(nil)
|
||||
_ bridgev2.LoginProcessWithOverride = (*WALogin)(nil)
|
||||
_ bridgev2.LoginProcessWithParams = (*WALogin)(nil)
|
||||
_ bridgev2.LoginProcessWebAuthn = (*WALogin)(nil)
|
||||
)
|
||||
|
||||
|
|
@ -144,6 +145,14 @@ const LoginConnectWait = 30 * time.Second
|
|||
const LoginPairPhoneWait = 30 * time.Second
|
||||
|
||||
func (wl *WALogin) Start(ctx context.Context) (*bridgev2.LoginStep, error) {
|
||||
return wl.StartWithParams(ctx, bridgev2.LoginStartParams{})
|
||||
}
|
||||
|
||||
func (wl *WALogin) StartWithOverride(ctx context.Context, old *bridgev2.UserLogin) (*bridgev2.LoginStep, error) {
|
||||
return wl.StartWithParams(ctx, bridgev2.LoginStartParams{Override: old})
|
||||
}
|
||||
|
||||
func (wl *WALogin) StartWithParams(ctx context.Context, params bridgev2.LoginStartParams) (*bridgev2.LoginStep, error) {
|
||||
wl.Main.firstClientConnectOnce.Do(wl.Main.onFirstClientConnect)
|
||||
device := wl.Main.DeviceStore.NewDevice()
|
||||
wl.Client = whatsmeow.NewClient(device, waLog.Zerolog(wl.Log))
|
||||
|
|
@ -153,8 +162,20 @@ func (wl *WALogin) Start(ctx context.Context) (*bridgev2.LoginStep, error) {
|
|||
if err := wl.Main.updateProxy(ctx, wl.Client, true); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if params.WebSocketHTTP != nil {
|
||||
wl.Client.SetPreLoginHTTPClient(&http.Client{Transport: params.WebSocketHTTP})
|
||||
}
|
||||
|
||||
if wl.PhoneCode {
|
||||
if params.Override != nil {
|
||||
phoneNumber := fmt.Sprintf("+%s", params.Override.ID)
|
||||
wl.Log.Debug().
|
||||
Str("phone_number", phoneNumber).
|
||||
Msg("Auto-submitting phone number for relogin")
|
||||
return wl.SubmitUserInput(ctx, map[string]string{
|
||||
"phone_number": phoneNumber,
|
||||
})
|
||||
}
|
||||
return &bridgev2.LoginStep{
|
||||
Type: bridgev2.LoginStepTypeUserInput,
|
||||
StepID: LoginStepIDPhoneNumber,
|
||||
|
|
@ -184,20 +205,6 @@ func (wl *WALogin) Start(ctx context.Context) (*bridgev2.LoginStep, error) {
|
|||
return makeQRStep(wl.QRs[0]), nil
|
||||
}
|
||||
|
||||
func (wl *WALogin) StartWithOverride(ctx context.Context, old *bridgev2.UserLogin) (*bridgev2.LoginStep, error) {
|
||||
step, err := wl.Start(ctx)
|
||||
if err == nil && step != nil && old != nil && step.StepID == LoginStepIDPhoneNumber {
|
||||
phoneNumber := fmt.Sprintf("+%s", old.ID)
|
||||
wl.Log.Debug().
|
||||
Str("phone_number", phoneNumber).
|
||||
Msg("Auto-submitting phone number for relogin")
|
||||
return wl.SubmitUserInput(ctx, map[string]string{
|
||||
"phone_number": phoneNumber,
|
||||
})
|
||||
}
|
||||
return step, err
|
||||
}
|
||||
|
||||
func (wl *WALogin) SubmitUserInput(ctx context.Context, input map[string]string) (*bridgev2.LoginStep, error) {
|
||||
err := wl.Client.Connect()
|
||||
if err != nil {
|
||||
|
|
@ -316,6 +323,8 @@ func (wl *WALogin) handleEvent(rawEvt any) {
|
|||
wl.LoginError = ErrUnexpectedDisconnect
|
||||
case *events.ManualLoginReconnect:
|
||||
wl.Received515.Set()
|
||||
// PairSuccess is dispatched separately and may arrive after the 515.
|
||||
return
|
||||
default:
|
||||
wl.Log.Warn().Type("event_type", evt).Msg("Got unexpected event")
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in a new issue