feat: add new_device flag to pair additional accounts into one store - #203
feat: add new_device flag to pair additional accounts into one store#203Ceirced wants to merge 1 commit into
Conversation
A jid-less client resolves its device via container.GetFirstDevice(), which only creates a blank device when the store is empty — so in a database that already holds a session, pairing a second account is impossible: the client silently resumes the first stored session and no QR is ever emitted (and the resumed session kicks the original client with a replaced-stream error). Expose whatsmeow's container.NewDevice() through a new newDevice parameter on the Neonize export, threaded through NewClient/NewAClient and both ClientFactory.new_client() as new_device=False. Passing new_device=True with a uuid forces a brand-new blank device, so a fresh QR pairing starts alongside the existing sessions. Default behavior is unchanged.
|
Following up on the draft note — I've now run the live two-account QR pairing against this branch's build (darwin/arm64, Go 1.26.5, real WhatsApp servers). Everything checks out: 1. Default path unaffected (empty store): 2. The fix (populated store): 3. Coexistence: connected both devices from the same store simultaneously and held them online — I also reproduced the failure mode this PR fixes, on a store seeded with an existing device row: without the flag no QR is ever emitted — whatsmeow resumes the stored session, gets a 401, and deletes the device row. With One unrelated upstream note from testing multi-session use: starting two clients' Undrafting — ready for review. |
Problem
In a database that already contains a session, it is currently impossible to pair a second account. A jid-less client resolves its device via
container.GetFirstDevice(), which only creates a blank device when the store is empty — soClientFactory.new_client(uuid=...)on a populated store silently resumes the first stored session instead: no QR is ever emitted, and the resumed session kicks the original client with a replaced-stream error.container.NewDevice()— whatsmeow's API for exactly this — is not exposed anywhere in goneonize.This is the failure described in #104 ("a new client was created, but there is no display to scan the QR code"). The README's multi-session example only covers resuming known JIDs, matching the comment in
main.go: "If you want multiple sessions, remember their JIDs and use .GetDevice(jid)" — onboarding session #2 has no supported path today. Downstream apps currently have to work around this with one database per account.Change
goneonize/main.go: newnewDevice C.intparameter on theNeonizeexport; when set (and no jid is given) the client is built oncontainer.NewDevice()instead ofGetFirstDevice(), so a fresh QR pairing starts alongside existing sessions.neonize/client.py,neonize/aioze/client.py:new_device: bool = FalseonNewClient/NewAClientand bothClientFactory.new_client(); flag passed through to Go.neonize/_binder.py: matchingctypes.c_intin theNeonizeargtypes.README.md: multi-session example gains an "add another account" line.Usage:
Compatibility
Default behavior is byte-for-byte unchanged: jid →
GetDevice, no jid →GetFirstDevice. The C signature change is internal — the Python layer and the goneonize binary ship together per release. The blank device fromNewDevice()is persisted by whatsmeow on successful pairing, exactly like the empty-store first pairing today.Testing
go build ./...passes on the patchedgoneonize.python -m py_compileon the three touched Python files.Fixes #104