diff --git a/src/Internal/Config/Text.elm b/src/Internal/Config/Text.elm index 0c0d4ad..c1c2060 100644 --- a/src/Internal/Config/Text.elm +++ b/src/Internal/Config/Text.elm @@ -346,6 +346,7 @@ fields : } , vault : { accountData : Desc + , nextBatch : Desc , rooms : Desc , user : Desc } @@ -565,6 +566,9 @@ fields = { accountData = [ "The account's global private data." ] + , nextBatch = + [ "The next batch that can be used to sync with the Matrix API." + ] , rooms = [ "Directory of joined rooms that the user is a member of." ] diff --git a/src/Internal/Values/Vault.elm b/src/Internal/Values/Vault.elm index 2725744..1c4112f 100644 --- a/src/Internal/Values/Vault.elm +++ b/src/Internal/Values/Vault.elm @@ -44,6 +44,7 @@ import Internal.Values.User as User exposing (User) -} type alias Vault = { accountData : Dict String Json.Value + , nextBatch : Maybe String , rooms : Hashdict Room , user : Maybe User } @@ -56,13 +57,15 @@ type VaultUpdate = CreateRoomIfNotExists String | MapRoom String Room.RoomUpdate | More (List VaultUpdate) + | Optional (Maybe VaultUpdate) | SetAccountData String Json.Value + | SetNextBatch String | SetUser User coder : Json.Coder Vault coder = - Json.object3 + Json.object4 { name = Text.docs.vault.name , description = Text.docs.vault.description , init = Vault @@ -74,6 +77,13 @@ coder = , coder = Json.fastDict Json.value } ) + (Json.field.optional.value + { fieldName = "nextBatch" + , toField = .nextBatch + , description = Text.fields.vault.nextBatch + , coder = Json.string + } + ) (Json.field.required { fieldName = "rooms" , toField = .rooms @@ -109,6 +119,7 @@ getAccountData key vault = init : Maybe User -> Vault init mUser = { accountData = Dict.empty + , nextBatch = Nothing , rooms = Hashdict.empty .roomId , user = mUser } @@ -152,8 +163,17 @@ update vu vault = More items -> List.foldl update vault items + Optional (Just u) -> + update u vault + + Optional Nothing -> + vault + SetAccountData key value -> setAccountData key value vault + SetNextBatch nb -> + { vault | nextBatch = Just nb } + SetUser user -> { vault | user = Just user } diff --git a/tests/Test/Values/Vault.elm b/tests/Test/Values/Vault.elm index 3982791..f1c90a0 100644 --- a/tests/Test/Values/Vault.elm +++ b/tests/Test/Values/Vault.elm @@ -12,11 +12,12 @@ import Test.Values.User as TestUser vault : Fuzzer Vault vault = - Fuzz.map3 Vault + Fuzz.map4 Vault (Fuzz.string |> Fuzz.map (\k -> ( k, Json.encode Json.int 0 )) |> Fuzz.list |> Fuzz.map Dict.fromList ) + (Fuzz.maybe Fuzz.string) (TestHashdict.fuzzer .roomId TestRoom.fuzzer) (Fuzz.maybe TestUser.fuzzer)