@@ -9,11 +9,14 @@ package whatsmeow
99import (
1010 "context"
1111 "encoding/hex"
12+ "encoding/json"
1213 "errors"
1314 "fmt"
15+ "os"
1416 "time"
1517
1618 "github.com/rs/zerolog"
19+ "go.mau.fi/util/exerrors"
1720 "go.mau.fi/util/exslices"
1821 "go.mau.fi/util/ptr"
1922
@@ -22,6 +25,7 @@ import (
2225 "go.mau.fi/whatsmeow/proto/waE2E"
2326 "go.mau.fi/whatsmeow/proto/waServerSync"
2427 "go.mau.fi/whatsmeow/store"
28+ "go.mau.fi/whatsmeow/store/sqlstore"
2529 "go.mau.fi/whatsmeow/types"
2630 "go.mau.fi/whatsmeow/types/events"
2731)
@@ -39,6 +43,8 @@ func (cli *Client) FetchAppState(ctx context.Context, name appstate.WAPatchName,
3943 return nil
4044}
4145
46+ var DumpAppStateToDisk = false
47+
4248func (cli * Client ) fetchAppState (ctx context.Context , name appstate.WAPatchName , fullSync , onlyIfNotSynced bool ) ([]any , error ) {
4349 if cli == nil {
4450 return nil , ErrClientIsNil
@@ -79,6 +85,17 @@ func (cli *Client) fetchAppState(ctx context.Context, name appstate.WAPatchName,
7985 } else if patches .Snapshot != nil && state != (appstate.HashState {}) {
8086 return nil , fmt .Errorf ("unexpected non-empty input state (v%d) for %s when applying snapshot" , state .Version , name )
8187 }
88+ if DumpAppStateToDisk {
89+ f := exerrors .Must (os .OpenFile (fmt .Sprintf ("/tmp/appstate-%s-v%d.json" , name , state .Version ), os .O_CREATE | os .O_WRONLY | os .O_TRUNC , 0600 ))
90+ _ = json .NewEncoder (f ).Encode (map [string ]any {
91+ "name" : name ,
92+ "patches" : patches .Patches ,
93+ "snapshot" : patches .Snapshot ,
94+ "keys" : exerrors .Must (cli .Store .AppStateKeys .GetAllAppStateSyncKeys (ctx )),
95+ "lids" : exerrors .Must (cli .Store .LIDs .(* sqlstore.CachedLIDMap ).GetAll (ctx )),
96+ })
97+ _ = f .Close ()
98+ }
8299 wantSnapshot = false
83100 hasMore = patches .HasMorePatches
84101 state , err = cli .applyAppStatePatches (ctx , name , state , patches , fullSync , eventsToDispatchPtr )
0 commit comments