Merge branch '4-compiler-bug' into 4-transfer-api

pull/24/head
Bram 2024-05-27 16:44:57 +02:00
commit 567ac5596a
17 changed files with 405 additions and 355 deletions

View File

@ -1,4 +1,4 @@
module Internal.Api.BaseUrl.Api exposing (..) module Internal.Api.BaseUrl.Api exposing (baseUrl)
{-| {-|
@ -7,6 +7,8 @@ module Internal.Api.BaseUrl.Api exposing (..)
This module looks for the right homeserver address. This module looks for the right homeserver address.
@docs baseUrl
-} -}
import Internal.Api.Chain as C import Internal.Api.Chain as C
@ -19,6 +21,8 @@ import Internal.Values.Envelope as E
import Internal.Values.Vault as V import Internal.Values.Vault as V
{-| Get the homeserver base URL of a given server name.
-}
baseUrl : BaseUrlInput -> C.TaskChain R.Error (E.EnvelopeUpdate V.VaultUpdate) ph { ph | baseUrl : () } baseUrl : BaseUrlInput -> C.TaskChain R.Error (E.EnvelopeUpdate V.VaultUpdate) ph { ph | baseUrl : () }
baseUrl data = baseUrl data =
R.toChain R.toChain

View File

@ -1,7 +1,7 @@
module Internal.Api.Chain exposing module Internal.Api.Chain exposing
( TaskChain, CompleteChain ( TaskChain, CompleteChain
, IdemChain, toTask , IdemChain, toTask
, fail, succeed, andThen, catchWith , fail, succeed, andThen, catchWith, maybe
) )
{-| {-|
@ -27,7 +27,7 @@ avoid leaking values passing through the API in unexpected ways.
## Operations ## Operations
@docs fail, succeed, andThen, catchWith @docs fail, succeed, andThen, catchWith, maybe
-} -}

View File

@ -22,6 +22,8 @@ import Internal.Values.Vault as V
import Json.Encode as E import Json.Encode as E
{-| Log in using a username and password.
-}
loginWithUsernameAndPassword : LoginWithUsernameAndPasswordInput -> A.TaskChain (Phantom a) (Phantom { a | accessToken : () }) loginWithUsernameAndPassword : LoginWithUsernameAndPasswordInput -> A.TaskChain (Phantom a) (Phantom { a | accessToken : () })
loginWithUsernameAndPassword = loginWithUsernameAndPassword =
A.startWithVersion "r0.0.0" loginWithUsernameAndPasswordV1 A.startWithVersion "r0.0.0" loginWithUsernameAndPasswordV1
@ -46,8 +48,10 @@ loginWithUsernameAndPassword =
|> A.versionChain |> A.versionChain
{-| Context needed for logging in with a username and password
-}
type alias Phantom a = type alias Phantom a =
{ a | baseUrl : (), versions : () } { a | baseUrl : (), now : (), versions : () }
type alias LoginWithUsernameAndPasswordInput = type alias LoginWithUsernameAndPasswordInput =
@ -159,333 +163,340 @@ type alias PhantomV1 a =
loginWithUsernameAndPasswordV1 : LoginWithUsernameAndPasswordInputV1 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () }) loginWithUsernameAndPasswordV1 : LoginWithUsernameAndPasswordInputV1 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () })
loginWithUsernameAndPasswordV1 { username, password } context = loginWithUsernameAndPasswordV1 { username, password } =
A.request \context ->
{ attributes = A.request
[ R.bodyString "password" password { attributes =
, R.bodyString "type" "m.login.password" [ R.bodyString "password" password
, R.bodyString "user" username , R.bodyString "type" "m.login.password"
, R.onStatusCode 400 "M_UNKNOWN" , R.bodyString "user" username
, R.onStatusCode 403 "M_FORBIDDEN" , R.onStatusCode 400 "M_UNKNOWN"
] , R.onStatusCode 403 "M_FORBIDDEN"
, coder = coderV1 ]
, method = "POST" , coder = coderV1
, path = [ "_matrix", "client", "r0", "login" ] , method = "POST"
, contextChange = , path = [ "_matrix", "client", "r0", "login" ]
\out -> Context.setAccessToken out.accessToken , contextChange =
, toUpdate = \out -> Context.setAccessToken out.accessToken
\out -> , toUpdate =
( E.More \out ->
[ E.SetAccessToken ( E.More
{ created = Context.getNow context [ E.SetAccessToken
, expiryMs = Nothing { created = Context.getNow context
, lastUsed = Context.getNow context , expiryMs = Nothing
, refresh = out.refreshToken , lastUsed = Context.getNow context
, value = out.accessToken , refresh = out.refreshToken
} , value = out.accessToken
, out.user }
|> Maybe.map (V.SetUser >> E.ContentUpdate) , out.user
|> E.Optional |> Maybe.map (V.SetUser >> E.ContentUpdate)
] |> E.Optional
, [] ]
) , []
} )
context }
context
loginWithUsernameAndPasswordV2 : LoginWithUsernameAndPasswordInputV2 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () }) loginWithUsernameAndPasswordV2 : LoginWithUsernameAndPasswordInputV2 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () })
loginWithUsernameAndPasswordV2 { deviceId, initialDeviceDisplayName, username, password } context = loginWithUsernameAndPasswordV2 { deviceId, initialDeviceDisplayName, username, password } =
A.request \context ->
{ attributes = A.request
[ R.bodyOpString "device_id" deviceId { attributes =
, R.bodyOpString "initial_device_display_name" initialDeviceDisplayName [ R.bodyOpString "device_id" deviceId
, R.bodyString "password" password , R.bodyOpString "initial_device_display_name" initialDeviceDisplayName
, R.bodyString "type" "m.login.password" , R.bodyString "password" password
, R.bodyString "user" username , R.bodyString "type" "m.login.password"
, R.onStatusCode 400 "M_UNKNOWN" , R.bodyString "user" username
, R.onStatusCode 403 "M_FORBIDDEN" , R.onStatusCode 400 "M_UNKNOWN"
, R.onStatusCode 429 "string" -- Yup. That's what it says. , R.onStatusCode 403 "M_FORBIDDEN"
] , R.onStatusCode 429 "string" -- Yup. That's what it says.
, coder = coderV2 ]
, method = "POST" , coder = coderV2
, path = [ "_matrix", "client", "r0", "login" ] , method = "POST"
, contextChange = , path = [ "_matrix", "client", "r0", "login" ]
\out -> Context.setAccessToken out.accessToken , contextChange =
, toUpdate = \out -> Context.setAccessToken out.accessToken
\out -> , toUpdate =
( E.More \out ->
[ E.SetAccessToken ( E.More
{ created = Context.getNow context [ E.SetAccessToken
, expiryMs = Nothing { created = Context.getNow context
, lastUsed = Context.getNow context , expiryMs = Nothing
, refresh = Nothing , lastUsed = Context.getNow context
, value = out.accessToken , refresh = Nothing
} , value = out.accessToken
, out.user }
|> Maybe.map (V.SetUser >> E.ContentUpdate) , out.user
|> E.Optional |> Maybe.map (V.SetUser >> E.ContentUpdate)
, out.deviceId |> E.Optional
|> Maybe.map E.SetDeviceId , out.deviceId
|> E.Optional |> Maybe.map E.SetDeviceId
] |> E.Optional
, [] ]
) , []
} )
context }
context
loginWithUsernameAndPasswordV3 : LoginWithUsernameAndPasswordInputV2 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () }) loginWithUsernameAndPasswordV3 : LoginWithUsernameAndPasswordInputV2 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () })
loginWithUsernameAndPasswordV3 { deviceId, initialDeviceDisplayName, username, password } context = loginWithUsernameAndPasswordV3 { deviceId, initialDeviceDisplayName, username, password } =
A.request \context ->
{ attributes = A.request
[ R.bodyOpString "address" Nothing { attributes =
, R.bodyOpString "device_id" deviceId [ R.bodyOpString "address" Nothing
, R.bodyValue "identifier" , R.bodyOpString "device_id" deviceId
(E.object , R.bodyValue "identifier"
[ ( "type", E.string "m.id.user" ) (E.object
, ( "user", E.string username ) [ ( "type", E.string "m.id.user" )
] , ( "user", E.string username )
) ]
, R.bodyOpString "initial_device_display_name" initialDeviceDisplayName )
, R.bodyString "password" password , R.bodyOpString "initial_device_display_name" initialDeviceDisplayName
, R.bodyString "type" "m.login.password" , R.bodyString "password" password
, R.bodyString "user" username , R.bodyString "type" "m.login.password"
, R.onStatusCode 400 "M_UNKNOWN" , R.bodyString "user" username
, R.onStatusCode 403 "M_FORBIDDEN" , R.onStatusCode 400 "M_UNKNOWN"
, R.onStatusCode 429 "M_LIMIT_EXCEEDED" , R.onStatusCode 403 "M_FORBIDDEN"
] , R.onStatusCode 429 "M_LIMIT_EXCEEDED"
, coder = coderV3 ]
, method = "POST" , coder = coderV3
, path = [ "_matrix", "client", "r0", "login" ] , method = "POST"
, contextChange = , path = [ "_matrix", "client", "r0", "login" ]
\out -> Context.setAccessToken out.accessToken , contextChange =
, toUpdate = \out -> Context.setAccessToken out.accessToken
\out -> , toUpdate =
( E.More \out ->
[ E.SetAccessToken ( E.More
{ created = Context.getNow context [ E.SetAccessToken
, expiryMs = Nothing { created = Context.getNow context
, lastUsed = Context.getNow context , expiryMs = Nothing
, refresh = Nothing , lastUsed = Context.getNow context
, value = out.accessToken , refresh = Nothing
} , value = out.accessToken
, out.user }
|> Maybe.map (V.SetUser >> E.ContentUpdate) , out.user
|> E.Optional |> Maybe.map (V.SetUser >> E.ContentUpdate)
, out.deviceId |> E.Optional
|> Maybe.map E.SetDeviceId , out.deviceId
|> E.Optional |> Maybe.map E.SetDeviceId
] |> E.Optional
, [] ]
) , []
} )
context }
context
loginWithUsernameAndPasswordV4 : LoginWithUsernameAndPasswordInputV2 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () }) loginWithUsernameAndPasswordV4 : LoginWithUsernameAndPasswordInputV2 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () })
loginWithUsernameAndPasswordV4 { deviceId, initialDeviceDisplayName, username, password } context = loginWithUsernameAndPasswordV4 { deviceId, initialDeviceDisplayName, username, password } =
A.request \context ->
{ attributes = A.request
[ R.bodyOpString "address" Nothing { attributes =
, R.bodyOpString "device_id" deviceId [ R.bodyOpString "address" Nothing
, R.bodyValue "identifier" , R.bodyOpString "device_id" deviceId
(E.object , R.bodyValue "identifier"
[ ( "type", E.string "m.id.user" ) (E.object
, ( "user", E.string username ) [ ( "type", E.string "m.id.user" )
] , ( "user", E.string username )
) ]
, R.bodyOpString "initial_device_display_name" initialDeviceDisplayName )
, R.bodyString "password" password , R.bodyOpString "initial_device_display_name" initialDeviceDisplayName
, R.bodyString "type" "m.login.password" , R.bodyString "password" password
, R.bodyString "user" username , R.bodyString "type" "m.login.password"
, R.onStatusCode 400 "M_UNKNOWN" , R.bodyString "user" username
, R.onStatusCode 403 "M_FORBIDDEN" , R.onStatusCode 400 "M_UNKNOWN"
, R.onStatusCode 429 "M_LIMIT_EXCEEDED" , R.onStatusCode 403 "M_FORBIDDEN"
] , R.onStatusCode 429 "M_LIMIT_EXCEEDED"
, coder = coderV4 ]
, method = "POST" , coder = coderV4
, path = [ "_matrix", "client", "r0", "login" ] , method = "POST"
, contextChange = , path = [ "_matrix", "client", "r0", "login" ]
\out -> Context.setAccessToken out.accessToken , contextChange =
, toUpdate = \out -> Context.setAccessToken out.accessToken
\out -> , toUpdate =
( E.More \out ->
[ E.SetAccessToken ( E.More
{ created = Context.getNow context [ E.SetAccessToken
, expiryMs = Nothing { created = Context.getNow context
, lastUsed = Context.getNow context , expiryMs = Nothing
, refresh = Nothing , lastUsed = Context.getNow context
, value = out.accessToken , refresh = Nothing
} , value = out.accessToken
, out.user }
|> Maybe.map (V.SetUser >> E.ContentUpdate) , out.user
|> E.Optional |> Maybe.map (V.SetUser >> E.ContentUpdate)
, out.wellKnown |> E.Optional
|> Maybe.map (.homeserver >> .baseUrl) , out.wellKnown
|> Maybe.map E.SetBaseUrl |> Maybe.map (.homeserver >> .baseUrl)
|> E.Optional |> Maybe.map E.SetBaseUrl
, out.deviceId |> E.Optional
|> Maybe.map E.SetDeviceId , out.deviceId
|> E.Optional |> Maybe.map E.SetDeviceId
] |> E.Optional
, [] ]
) , []
} )
context }
context
loginWithUsernameAndPasswordV5 : LoginWithUsernameAndPasswordInputV2 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () }) loginWithUsernameAndPasswordV5 : LoginWithUsernameAndPasswordInputV2 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () })
loginWithUsernameAndPasswordV5 { deviceId, initialDeviceDisplayName, username, password } context = loginWithUsernameAndPasswordV5 { deviceId, initialDeviceDisplayName, username, password } =
A.request \context ->
{ attributes = A.request
[ R.bodyOpString "address" Nothing { attributes =
, R.bodyOpString "device_id" deviceId [ R.bodyOpString "address" Nothing
, R.bodyValue "identifier" , R.bodyOpString "device_id" deviceId
(E.object , R.bodyValue "identifier"
[ ( "type", E.string "m.id.user" ) (E.object
, ( "user", E.string username ) [ ( "type", E.string "m.id.user" )
] , ( "user", E.string username )
) ]
, R.bodyOpString "initial_device_display_name" initialDeviceDisplayName )
, R.bodyString "password" password , R.bodyOpString "initial_device_display_name" initialDeviceDisplayName
, R.bodyString "type" "m.login.password" , R.bodyString "password" password
, R.bodyString "user" username , R.bodyString "type" "m.login.password"
, R.onStatusCode 400 "M_UNKNOWN" , R.bodyString "user" username
, R.onStatusCode 403 "M_FORBIDDEN" , R.onStatusCode 400 "M_UNKNOWN"
, R.onStatusCode 429 "M_LIMIT_EXCEEDED" , R.onStatusCode 403 "M_FORBIDDEN"
] , R.onStatusCode 429 "M_LIMIT_EXCEEDED"
, coder = coderV4 ]
, method = "POST" , coder = coderV4
, path = [ "_matrix", "client", "v3", "login" ] , method = "POST"
, contextChange = , path = [ "_matrix", "client", "v3", "login" ]
\out -> Context.setAccessToken out.accessToken , contextChange =
, toUpdate = \out -> Context.setAccessToken out.accessToken
\out -> , toUpdate =
( E.More \out ->
[ E.SetAccessToken ( E.More
{ created = Context.getNow context [ E.SetAccessToken
, expiryMs = Nothing { created = Context.getNow context
, lastUsed = Context.getNow context , expiryMs = Nothing
, refresh = Nothing , lastUsed = Context.getNow context
, value = out.accessToken , refresh = Nothing
} , value = out.accessToken
, out.user }
|> Maybe.map (V.SetUser >> E.ContentUpdate) , out.user
|> E.Optional |> Maybe.map (V.SetUser >> E.ContentUpdate)
, out.wellKnown |> E.Optional
|> Maybe.map (.homeserver >> .baseUrl) , out.wellKnown
|> Maybe.map E.SetBaseUrl |> Maybe.map (.homeserver >> .baseUrl)
|> E.Optional |> Maybe.map E.SetBaseUrl
, out.deviceId |> E.Optional
|> Maybe.map E.SetDeviceId , out.deviceId
|> E.Optional |> Maybe.map E.SetDeviceId
] |> E.Optional
, [] ]
) , []
} )
context }
context
loginWithUsernameAndPasswordV6 : LoginWithUsernameAndPasswordInputV3 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () }) loginWithUsernameAndPasswordV6 : LoginWithUsernameAndPasswordInputV3 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () })
loginWithUsernameAndPasswordV6 { deviceId, enableRefreshToken, initialDeviceDisplayName, username, password } context = loginWithUsernameAndPasswordV6 { deviceId, enableRefreshToken, initialDeviceDisplayName, username, password } =
A.request \context ->
{ attributes = A.request
[ R.bodyOpString "address" Nothing { attributes =
, R.bodyOpString "device_id" deviceId [ R.bodyOpString "address" Nothing
, R.bodyValue "identifier" , R.bodyOpString "device_id" deviceId
(E.object , R.bodyValue "identifier"
[ ( "type", E.string "m.id.user" ) (E.object
, ( "user", E.string username ) [ ( "type", E.string "m.id.user" )
] , ( "user", E.string username )
) ]
, R.bodyOpString "initial_device_display_name" initialDeviceDisplayName )
, R.bodyString "password" password , R.bodyOpString "initial_device_display_name" initialDeviceDisplayName
, R.bodyOpBool "refresh_token" enableRefreshToken , R.bodyString "password" password
, R.bodyString "type" "m.login.password" , R.bodyOpBool "refresh_token" enableRefreshToken
, R.bodyString "user" username , R.bodyString "type" "m.login.password"
, R.onStatusCode 400 "M_UNKNOWN" , R.bodyString "user" username
, R.onStatusCode 403 "M_FORBIDDEN" , R.onStatusCode 400 "M_UNKNOWN"
, R.onStatusCode 429 "M_LIMIT_EXCEEDED" , R.onStatusCode 403 "M_FORBIDDEN"
] , R.onStatusCode 429 "M_LIMIT_EXCEEDED"
, coder = coderV5 ]
, method = "POST" , coder = coderV5
, path = [ "_matrix", "client", "v3", "login" ] , method = "POST"
, contextChange = , path = [ "_matrix", "client", "v3", "login" ]
\out -> Context.setAccessToken out.accessToken , contextChange =
, toUpdate = \out -> Context.setAccessToken out.accessToken
\out -> , toUpdate =
( E.More \out ->
[ E.SetAccessToken ( E.More
{ created = Context.getNow context [ E.SetAccessToken
, expiryMs = out.expiresInMs { created = Context.getNow context
, lastUsed = Context.getNow context , expiryMs = out.expiresInMs
, refresh = out.refreshToken , lastUsed = Context.getNow context
, value = out.accessToken , refresh = out.refreshToken
} , value = out.accessToken
, out.user }
|> Maybe.map (V.SetUser >> E.ContentUpdate) , out.user
|> E.Optional |> Maybe.map (V.SetUser >> E.ContentUpdate)
, out.wellKnown |> E.Optional
|> Maybe.map (.homeserver >> .baseUrl) , out.wellKnown
|> Maybe.map E.SetBaseUrl |> Maybe.map (.homeserver >> .baseUrl)
|> E.Optional |> Maybe.map E.SetBaseUrl
, out.deviceId |> E.Optional
|> Maybe.map E.SetDeviceId , out.deviceId
|> E.Optional |> Maybe.map E.SetDeviceId
] |> E.Optional
, [] ]
) , []
} )
context }
context
loginWithUsernameAndPasswordV7 : LoginWithUsernameAndPasswordInputV3 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () }) loginWithUsernameAndPasswordV7 : LoginWithUsernameAndPasswordInputV3 i -> A.TaskChain (PhantomV1 a) (PhantomV1 { a | accessToken : () })
loginWithUsernameAndPasswordV7 { deviceId, enableRefreshToken, initialDeviceDisplayName, username, password } context = loginWithUsernameAndPasswordV7 { deviceId, enableRefreshToken, initialDeviceDisplayName, username, password } =
A.request \context ->
{ attributes = A.request
[ R.bodyOpString "address" Nothing { attributes =
, R.bodyOpString "device_id" deviceId [ R.bodyOpString "address" Nothing
, R.bodyValue "identifier" , R.bodyOpString "device_id" deviceId
(E.object , R.bodyValue "identifier"
[ ( "type", E.string "m.id.user" ) (E.object
, ( "user", E.string username ) [ ( "type", E.string "m.id.user" )
] , ( "user", E.string username )
) ]
, R.bodyOpString "initial_device_display_name" initialDeviceDisplayName )
, R.bodyString "password" password , R.bodyOpString "initial_device_display_name" initialDeviceDisplayName
, R.bodyOpBool "refresh_token" enableRefreshToken , R.bodyString "password" password
, R.bodyString "type" "m.login.password" , R.bodyOpBool "refresh_token" enableRefreshToken
, R.bodyString "user" username , R.bodyString "type" "m.login.password"
, R.onStatusCode 400 "M_UNKNOWN" , R.bodyString "user" username
, R.onStatusCode 403 "M_FORBIDDEN" , R.onStatusCode 400 "M_UNKNOWN"
, R.onStatusCode 429 "M_LIMIT_EXCEEDED" , R.onStatusCode 403 "M_FORBIDDEN"
] , R.onStatusCode 429 "M_LIMIT_EXCEEDED"
, coder = coderV6 ]
, method = "POST" , coder = coderV6
, path = [ "_matrix", "client", "v3", "login" ] , method = "POST"
, contextChange = , path = [ "_matrix", "client", "v3", "login" ]
\out -> Context.setAccessToken out.accessToken , contextChange =
, toUpdate = \out -> Context.setAccessToken out.accessToken
\out -> , toUpdate =
( E.More \out ->
[ E.SetAccessToken ( E.More
{ created = Context.getNow context [ E.SetAccessToken
, expiryMs = out.expiresInMs { created = Context.getNow context
, lastUsed = Context.getNow context , expiryMs = out.expiresInMs
, refresh = out.refreshToken , lastUsed = Context.getNow context
, value = out.accessToken , refresh = out.refreshToken
} , value = out.accessToken
, E.ContentUpdate (V.SetUser out.user) }
, out.wellKnown , E.ContentUpdate (V.SetUser out.user)
|> Maybe.map (.homeserver >> .baseUrl) , out.wellKnown
|> Maybe.map E.SetBaseUrl |> Maybe.map (.homeserver >> .baseUrl)
|> E.Optional |> Maybe.map E.SetBaseUrl
, E.SetDeviceId out.deviceId |> E.Optional
] , E.SetDeviceId out.deviceId
, [] ]
) , []
} )
context }
context
coderV1 : Json.Coder LoginWithUsernameAndPasswordOutputV1 coderV1 : Json.Coder LoginWithUsernameAndPasswordOutputV1

View File

@ -28,6 +28,8 @@ import Internal.Values.Context as Context
import Internal.Values.Envelope as E import Internal.Values.Envelope as E
{-| Update message type that is being returned.
-}
type alias Msg = type alias Msg =
Backpack Backpack

View File

@ -19,19 +19,22 @@ import Task
import Time import Time
{-| Get the current time and place it in the context.
-}
getNow : A.TaskChain a { a | now : () } getNow : A.TaskChain a { a | now : () }
getNow _ = getNow =
Task.map \_ ->
(\now -> Task.map
{ messages = [ E.SetNow now ] (\now ->
, logs = { messages = [ E.SetNow now ]
[ "Identified current time at Unix time " , logs =
, now |> Time.posixToMillis |> String.fromInt [ "Identified current time at Unix time "
] , now |> Time.posixToMillis |> String.fromInt
|> String.concat ]
|> log.debug |> String.concat
|> List.singleton |> log.debug
, contextChange = Context.setNow now |> List.singleton
} , contextChange = Context.setNow now
) }
Time.now )
Time.now

View File

@ -1,4 +1,4 @@
module Internal.Api.SendMessageEvent.Api exposing (..) module Internal.Api.SendMessageEvent.Api exposing (Phantom, sendMessageEvent)
{-| {-|
@ -7,7 +7,7 @@ module Internal.Api.SendMessageEvent.Api exposing (..)
This module helps send message events to rooms on the Matrix API. This module helps send message events to rooms on the Matrix API.
@docs Phantom @docs Phantom, sendMessageEvent
-} -}
@ -19,6 +19,8 @@ import Internal.Tools.Json as Json
import Internal.Values.Envelope as E import Internal.Values.Envelope as E
{-| Send a message event to the Matrix room.
-}
sendMessageEvent : SendMessageEventInput -> A.TaskChain (Phantom a) (Phantom a) sendMessageEvent : SendMessageEventInput -> A.TaskChain (Phantom a) (Phantom a)
sendMessageEvent = sendMessageEvent =
A.startWithVersion "r0.0.0" sendMessageEventV1 A.startWithVersion "r0.0.0" sendMessageEventV1
@ -44,8 +46,10 @@ sendMessageEvent =
|> A.versionChain |> A.versionChain
{-| Context needed for sending a message event
-}
type alias Phantom a = type alias Phantom a =
a { a | accessToken : (), baseUrl : (), versions : () }
type alias PhantomV1 a = type alias PhantomV1 a =

View File

@ -65,7 +65,7 @@ type alias UFTask a b =
{-| Get an access token to talk to the Matrix API {-| Get an access token to talk to the Matrix API
-} -}
getAccessToken : UFTask { a | now : () } { a | accessToken : (), now : () } getAccessToken : UFTask { a | baseUrl : (), now : (), versions : () } { a | accessToken : (), baseUrl : (), now : (), versions : () }
getAccessToken c = getAccessToken c =
case Context.fromApiFormat c of case Context.fromApiFormat c of
context -> context ->

View File

@ -50,8 +50,6 @@ for interacting with the Matrix API.
import Internal.Config.Text as Text import Internal.Config.Text as Text
import Internal.Grammar.UserId as U import Internal.Grammar.UserId as U
import Internal.Tools.Json as Json import Internal.Tools.Json as Json
import Json.Decode as D
import Json.Encode as E
import Set exposing (Set) import Set exposing (Set)

View File

@ -56,7 +56,7 @@ import Internal.Tools.Json as Json
import Internal.Values.Event as Event exposing (Event) import Internal.Values.Event as Event exposing (Event)
import Internal.Values.StateManager as StateManager exposing (StateManager) import Internal.Values.StateManager as StateManager exposing (StateManager)
import Internal.Values.Timeline as Timeline exposing (Timeline) import Internal.Values.Timeline as Timeline exposing (Timeline)
import Internal.Values.User as User exposing (User) import Internal.Values.User exposing (User)
import Json.Encode as E import Json.Encode as E
@ -255,7 +255,7 @@ update ru room =
AddSync batch -> AddSync batch ->
addSync batch room addSync batch room
Invite user -> Invite _ ->
-- TODO: Invite user -- TODO: Invite user
room room

View File

@ -36,7 +36,7 @@ Since the username is safely parsed, one can get these parts of the username.
-} -}
import Internal.Config.Log as Log exposing (log) import Internal.Config.Log exposing (log)
import Internal.Grammar.ServerName as ServerName import Internal.Grammar.ServerName as ServerName
import Internal.Grammar.UserId as UserId import Internal.Grammar.UserId as UserId
import Internal.Tools.Json as Json import Internal.Tools.Json as Json

View File

@ -33,8 +33,6 @@ Rooms are environments where people can have a conversation with each other.
-} -}
import FastDict as Dict exposing (Dict) import FastDict as Dict exposing (Dict)
import Internal.Api.Request as Request
import Internal.Config.Log exposing (Log)
import Internal.Config.Text as Text import Internal.Config.Text as Text
import Internal.Tools.Hashdict as Hashdict exposing (Hashdict) import Internal.Tools.Hashdict as Hashdict exposing (Hashdict)
import Internal.Tools.Json as Json import Internal.Tools.Json as Json

View File

@ -3,10 +3,13 @@ module Test.Values.Context exposing (..)
import Expect import Expect
import Fuzz exposing (Fuzzer) import Fuzz exposing (Fuzzer)
import Internal.Config.Leaks as Leaks import Internal.Config.Leaks as Leaks
import Internal.Values.Context as Context exposing (Context) import Internal.Tools.Hashdict as Hashdict
import Internal.Values.Context as Context exposing (Context, Versions)
import Json.Decode as D import Json.Decode as D
import Json.Encode as E import Json.Encode as E
import Set
import Test exposing (..) import Test exposing (..)
import Test.Tools.Timestamp as TestTimestamp
fuzzer : Fuzzer Context fuzzer : Fuzzer Context
@ -16,14 +19,28 @@ fuzzer =
maybeString = maybeString =
Fuzz.maybe Fuzz.string Fuzz.maybe Fuzz.string
in in
Fuzz.map7 Context Fuzz.map8 (\a b c d e f ( g, h ) ( i, j ) -> Context a b c d e f g h i j)
(Fuzz.constant <| Hashdict.empty .value)
maybeString maybeString
maybeString maybeString
(Fuzz.maybe TestTimestamp.fuzzer)
maybeString maybeString
maybeString maybeString
maybeString (Fuzz.pair
maybeString Fuzz.string
(Fuzz.maybe <| Fuzz.list Fuzz.string) maybeString
)
(Fuzz.pair
maybeString
(Fuzz.maybe <| versionsFuzzer)
)
versionsFuzzer : Fuzzer Versions
versionsFuzzer =
Fuzz.map2 Versions
(Fuzz.list Fuzz.string)
(Fuzz.map Set.fromList <| Fuzz.list Fuzz.string)
{-| If a leak is spotted, make sure to change the leaking value and then test {-| If a leak is spotted, make sure to change the leaking value and then test
@ -64,7 +81,7 @@ leaks =
|> Expect.notEqual Leaks.transaction |> Expect.notEqual Leaks.transaction
) )
, fuzz2 fuzzer , fuzz2 fuzzer
(Fuzz.list Fuzz.string) versionsFuzzer
"Versions" "Versions"
(\context value -> (\context value ->
context context
@ -110,7 +127,7 @@ apiContext =
|> Expect.equal value |> Expect.equal value
) )
, fuzz2 fuzzer , fuzz2 fuzzer
(Fuzz.list Fuzz.string) versionsFuzzer
"Versions" "Versions"
(\context value -> (\context value ->
context context
@ -126,7 +143,7 @@ json : Test
json = json =
describe "JSON encode + JSON decode" describe "JSON encode + JSON decode"
[ test "Empty is {}" [ test "Empty is {}"
(Context.init (Context.init ""
|> Context.encode |> Context.encode
|> E.encode 0 |> E.encode 0
|> Expect.equal "{}" |> Expect.equal "{}"

View File

@ -28,7 +28,7 @@ suite =
[ fuzz Fuzz.string [ fuzz Fuzz.string
"currentVersion" "currentVersion"
(\s -> (\s ->
s { content = s, serverName = "" }
|> Envelope.init |> Envelope.init
|> Envelope.extractSettings .currentVersion |> Envelope.extractSettings .currentVersion
|> Expect.equal Default.currentVersion |> Expect.equal Default.currentVersion
@ -36,7 +36,7 @@ suite =
, fuzz Fuzz.string , fuzz Fuzz.string
"deviceName" "deviceName"
(\s -> (\s ->
s { content = s, serverName = "" }
|> Envelope.init |> Envelope.init
|> Envelope.extractSettings .deviceName |> Envelope.extractSettings .deviceName
|> Expect.equal Default.deviceName |> Expect.equal Default.deviceName
@ -44,7 +44,7 @@ suite =
, fuzz Fuzz.string , fuzz Fuzz.string
"syncTime" "syncTime"
(\s -> (\s ->
s { content = s, serverName = "" }
|> Envelope.init |> Envelope.init
|> Envelope.extractSettings .syncTime |> Envelope.extractSettings .syncTime
|> Expect.equal Default.syncTime |> Expect.equal Default.syncTime

View File

@ -1,9 +1,7 @@
module Test.Values.Room exposing (..) module Test.Values.Room exposing (..)
import Expect
import Fuzz exposing (Fuzzer) import Fuzz exposing (Fuzzer)
import Internal.Values.Room as Room exposing (Room) import Internal.Values.Room as Room exposing (Room)
import Json.Decode as D
import Json.Encode as E import Json.Encode as E
import Test exposing (..) import Test exposing (..)
import Test.Filter.Timeline as TestFilter import Test.Filter.Timeline as TestFilter

View File

@ -2,7 +2,7 @@ module Test.Values.Timeline exposing (..)
import Expect import Expect
import Fuzz exposing (Fuzzer) import Fuzz exposing (Fuzzer)
import Internal.Filter.Timeline as Filter exposing (Filter) import Internal.Filter.Timeline as Filter
import Internal.Tools.Json as Json import Internal.Tools.Json as Json
import Internal.Values.Timeline as Timeline exposing (Batch, Timeline) import Internal.Values.Timeline as Timeline exposing (Batch, Timeline)
import Json.Decode as D import Json.Decode as D

View File

@ -0,0 +1,13 @@
module Test.Values.User exposing (..)
import Fuzz exposing (Fuzzer)
import Internal.Grammar.ServerName as SN
import Internal.Values.User exposing (User)
fuzzer : Fuzzer User
fuzzer =
Fuzz.constant
{ localpart = "temporary"
, domain = { host = SN.DNS "matrix.org", port_ = Nothing }
}

View File

@ -1,20 +1,22 @@
module Test.Values.Vault exposing (..) module Test.Values.Vault exposing (..)
import FastDict as Dict exposing (Dict) import FastDict as Dict
import Fuzz exposing (Fuzzer) import Fuzz exposing (Fuzzer)
import Internal.Tools.Json as Json import Internal.Tools.Json as Json
import Internal.Values.Vault exposing (Vault) import Internal.Values.Vault exposing (Vault)
import Test exposing (..) import Test exposing (..)
import Test.Tools.Hashdict as TestHashdict import Test.Tools.Hashdict as TestHashdict
import Test.Values.Room as TestRoom import Test.Values.Room as TestRoom
import Test.Values.User as TestUser
vault : Fuzzer Vault vault : Fuzzer Vault
vault = vault =
Fuzz.map2 Vault Fuzz.map3 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
) )
(TestHashdict.fuzzer .roomId TestRoom.fuzzer) (TestHashdict.fuzzer .roomId TestRoom.fuzzer)
TestUser.fuzzer