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 <mlctrez@gmail.com>
Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/168
Reviewed-by: James Mills <james@mills.io>
Co-authored-by: mlctrez <mlctrez@noreply@mills.io>
Co-committed-by: mlctrez <mlctrez@noreply@mills.io>
This commit is contained in:
mlctrez 2022-04-29 21:59:40 +00:00 committed by James Mills
parent 12fc010ce7
commit 504c66f7c1
3 changed files with 19 additions and 3 deletions

View File

@ -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,
}

View File

@ -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"))
}

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4859acd715745aca7c86ce2f1c65670f390a0ae5bc1ba7eae05317420dc150f3
size 29231220
oid sha256:869166394216124ee91c2afe8e07595a0652262cade01a86ac7a0f98436f1ed1
size 29218993