Add nextBatch value in Vault

pull/31/head
Bram 2024-06-08 15:25:49 +02:00
parent 0ded7ab6bd
commit 6783186c18
3 changed files with 27 additions and 2 deletions

View File

@ -346,6 +346,7 @@ fields :
} }
, vault : , vault :
{ accountData : Desc { accountData : Desc
, nextBatch : Desc
, rooms : Desc , rooms : Desc
, user : Desc , user : Desc
} }
@ -565,6 +566,9 @@ fields =
{ accountData = { accountData =
[ "The account's global private data." [ "The account's global private data."
] ]
, nextBatch =
[ "The next batch that can be used to sync with the Matrix API."
]
, rooms = , rooms =
[ "Directory of joined rooms that the user is a member of." [ "Directory of joined rooms that the user is a member of."
] ]

View File

@ -44,6 +44,7 @@ import Internal.Values.User as User exposing (User)
-} -}
type alias Vault = type alias Vault =
{ accountData : Dict String Json.Value { accountData : Dict String Json.Value
, nextBatch : Maybe String
, rooms : Hashdict Room , rooms : Hashdict Room
, user : Maybe User , user : Maybe User
} }
@ -56,13 +57,15 @@ type VaultUpdate
= CreateRoomIfNotExists String = CreateRoomIfNotExists String
| MapRoom String Room.RoomUpdate | MapRoom String Room.RoomUpdate
| More (List VaultUpdate) | More (List VaultUpdate)
| Optional (Maybe VaultUpdate)
| SetAccountData String Json.Value | SetAccountData String Json.Value
| SetNextBatch String
| SetUser User | SetUser User
coder : Json.Coder Vault coder : Json.Coder Vault
coder = coder =
Json.object3 Json.object4
{ name = Text.docs.vault.name { name = Text.docs.vault.name
, description = Text.docs.vault.description , description = Text.docs.vault.description
, init = Vault , init = Vault
@ -74,6 +77,13 @@ coder =
, coder = Json.fastDict Json.value , coder = Json.fastDict Json.value
} }
) )
(Json.field.optional.value
{ fieldName = "nextBatch"
, toField = .nextBatch
, description = Text.fields.vault.nextBatch
, coder = Json.string
}
)
(Json.field.required (Json.field.required
{ fieldName = "rooms" { fieldName = "rooms"
, toField = .rooms , toField = .rooms
@ -109,6 +119,7 @@ getAccountData key vault =
init : Maybe User -> Vault init : Maybe User -> Vault
init mUser = init mUser =
{ accountData = Dict.empty { accountData = Dict.empty
, nextBatch = Nothing
, rooms = Hashdict.empty .roomId , rooms = Hashdict.empty .roomId
, user = mUser , user = mUser
} }
@ -152,8 +163,17 @@ update vu vault =
More items -> More items ->
List.foldl update vault items List.foldl update vault items
Optional (Just u) ->
update u vault
Optional Nothing ->
vault
SetAccountData key value -> SetAccountData key value ->
setAccountData key value vault setAccountData key value vault
SetNextBatch nb ->
{ vault | nextBatch = Just nb }
SetUser user -> SetUser user ->
{ vault | user = Just user } { vault | user = Just user }

View File

@ -12,11 +12,12 @@ import Test.Values.User as TestUser
vault : Fuzzer Vault vault : Fuzzer Vault
vault = vault =
Fuzz.map3 Vault Fuzz.map4 Vault
(Fuzz.string (Fuzz.string
|> Fuzz.map (\k -> ( k, Json.encode Json.int 0 )) |> Fuzz.map (\k -> ( k, Json.encode Json.int 0 ))
|> Fuzz.list |> Fuzz.list
|> Fuzz.map Dict.fromList |> Fuzz.map Dict.fromList
) )
(Fuzz.maybe Fuzz.string)
(TestHashdict.fuzzer .roomId TestRoom.fuzzer) (TestHashdict.fuzzer .roomId TestRoom.fuzzer)
(Fuzz.maybe TestUser.fuzzer) (Fuzz.maybe TestUser.fuzzer)