From 504c66f7c109f326b4571eaecccf31e7bc8b4309 Mon Sep 17 00:00:00 2001 From: mlctrez Date: Fri, 29 Apr 2022 21:59:40 +0000 Subject: [PATCH] make outbox.state same as client.state to allow persisting last message retrieved (#168) After testing quite a bit on the saltyim/app client, I tracked down why all outbox messages were being pulled every time a new client starts up. I believe the outbox client state should be shared with the parent client to allow the last message retrieved from the oubox to be persisted. Co-authored-by: mlctrez Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/168 Reviewed-by: James Mills Co-authored-by: mlctrez Co-committed-by: mlctrez --- client.go | 2 +- client_test.go | 16 ++++++++++++++++ internal/web/app.wasm | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 36bcb8b..903cd75 100644 --- a/client.go +++ b/client.go @@ -295,7 +295,7 @@ func (cli *Client) OutboxClient(to *Addr) *Client { }, key: cli.key, cache: cli.cache, - state: NewState(), + state: cli.state, lookup: cli.lookup, send: cli.send, } diff --git a/client_test.go b/client_test.go index 8f7bc3c..df53f34 100644 --- a/client_test.go +++ b/client_test.go @@ -28,3 +28,19 @@ func TestClient_Outbox(t *testing.T) { test.True(outbox.Path == expected, "expected %s but got %s", expected, outbox.Path) } + +func TestClient_Outbox_State(t *testing.T) { + req := require.New(t) + + endpoint := &url.URL{Host: "example.com", Path: "/path", Scheme: "https"} + key := keys.GenerateEdX25519Key() + + state := NewState() + var testIndex int64 = 100 + state.SetIndex("testIndex", testIndex) + client := &Client{me: &Addr{endpoint: endpoint}, id: &Identity{key: key}, state: state} + + outboxClient := client.OutboxClient(nil) + req.Equal(state, outboxClient.state) + req.Equal(testIndex, outboxClient.state.GetIndex("testIndex")) +} diff --git a/internal/web/app.wasm b/internal/web/app.wasm index ee52862..ce7c53c 100755 --- a/internal/web/app.wasm +++ b/internal/web/app.wasm @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4859acd715745aca7c86ce2f1c65670f390a0ae5bc1ba7eae05317420dc150f3 -size 29231220 +oid sha256:869166394216124ee91c2afe8e07595a0652262cade01a86ac7a0f98436f1ed1 +size 29218993