elm-format
parent
aa0fe12fb8
commit
d3637cf45f
|
@ -1,4 +1,5 @@
|
|||
module Internal.Api.Context exposing (..)
|
||||
|
||||
{-| This module hosts functions for the `Context` type.
|
||||
|
||||
The `Context` type is a type that is passed along a chain of tasks.
|
||||
|
@ -10,13 +11,15 @@ after having set the value using a setter function.
|
|||
|
||||
Additionaly, there are remove functions which are intended to tell the compiler
|
||||
"you will have to get this value again if you'd like to use it later."
|
||||
|
||||
-}
|
||||
|
||||
import Internal.Config.Leaking as L
|
||||
import Internal.Tools.LoginValues exposing (AccessToken(..))
|
||||
|
||||
type Context a =
|
||||
Context
|
||||
|
||||
type Context a
|
||||
= Context
|
||||
{ accessToken : String
|
||||
, baseUrl : String
|
||||
, transactionId : String
|
||||
|
@ -24,16 +27,25 @@ type Context a =
|
|||
, versions : List String
|
||||
}
|
||||
|
||||
|
||||
type alias UsernameAndPassword =
|
||||
{ username : String, password : String }
|
||||
|
||||
type alias VB a = { a | versions : (), baseUrl : () }
|
||||
|
||||
type alias VBA a = { a | accessToken : (), baseUrl : (), versions : () }
|
||||
type alias VB a =
|
||||
{ a | versions : (), baseUrl : () }
|
||||
|
||||
type alias VBAT a = { a | accessToken : (), baseUrl : (), versions : (), transactionId : () }
|
||||
|
||||
{-| Get a default Context type. -}
|
||||
type alias VBA a =
|
||||
{ a | accessToken : (), baseUrl : (), versions : () }
|
||||
|
||||
|
||||
type alias VBAT a =
|
||||
{ a | accessToken : (), baseUrl : (), versions : (), transactionId : () }
|
||||
|
||||
|
||||
{-| Get a default Context type.
|
||||
-}
|
||||
init : Context {}
|
||||
init =
|
||||
Context
|
||||
|
@ -44,67 +56,93 @@ init =
|
|||
, versions = L.versions
|
||||
}
|
||||
|
||||
{-| Get the access token from the Context. -}
|
||||
|
||||
{-| Get the access token from the Context.
|
||||
-}
|
||||
getAccessToken : Context { a | accessToken : () } -> String
|
||||
getAccessToken (Context { accessToken }) =
|
||||
accessToken
|
||||
|
||||
{-| Get the base url from the Context. -}
|
||||
|
||||
{-| Get the base url from the Context.
|
||||
-}
|
||||
getBaseUrl : Context { a | baseUrl : () } -> String
|
||||
getBaseUrl (Context { baseUrl }) =
|
||||
baseUrl
|
||||
|
||||
{-| Get the transaction id from the Context. -}
|
||||
|
||||
{-| Get the transaction id from the Context.
|
||||
-}
|
||||
getTransactionId : Context { a | transactionId : () } -> String
|
||||
getTransactionId (Context { transactionId }) =
|
||||
transactionId
|
||||
|
||||
{-| Get the username and password of the user, if present. -}
|
||||
|
||||
{-| Get the username and password of the user, if present.
|
||||
-}
|
||||
getUsernameAndPassword : Context { a | accessToken : () } -> Maybe UsernameAndPassword
|
||||
getUsernameAndPassword (Context { usernameAndPassword }) =
|
||||
usernameAndPassword
|
||||
|
||||
{-| Get the supported spec versions from the Context. -}
|
||||
|
||||
{-| Get the supported spec versions from the Context.
|
||||
-}
|
||||
getVersions : Context { a | versions : () } -> List String
|
||||
getVersions (Context { versions }) =
|
||||
versions
|
||||
|
||||
{-| Insert an access token into the context. -}
|
||||
|
||||
{-| Insert an access token into the context.
|
||||
-}
|
||||
setAccessToken : { accessToken : String, usernameAndPassword : Maybe UsernameAndPassword } -> Context a -> Context { a | accessToken : () }
|
||||
setAccessToken { accessToken, usernameAndPassword } (Context data) =
|
||||
Context { data | accessToken = accessToken, usernameAndPassword = usernameAndPassword }
|
||||
|
||||
{-| Insert a base url into the context. -}
|
||||
|
||||
{-| Insert a base url into the context.
|
||||
-}
|
||||
setBaseUrl : String -> Context a -> Context { a | baseUrl : () }
|
||||
setBaseUrl baseUrl (Context data) =
|
||||
Context { data | baseUrl = baseUrl }
|
||||
|
||||
{-| Insert a transaction id into the context. -}
|
||||
|
||||
{-| Insert a transaction id into the context.
|
||||
-}
|
||||
setTransactionId : String -> Context a -> Context { a | transactionId : () }
|
||||
setTransactionId transactionId (Context data) =
|
||||
Context { data | transactionId = transactionId }
|
||||
|
||||
{-| Insert a transaction id into the context. -}
|
||||
|
||||
{-| Insert a transaction id into the context.
|
||||
-}
|
||||
setVersions : List String -> Context a -> Context { a | versions : () }
|
||||
setVersions versions (Context data) =
|
||||
Context { data | versions = versions }
|
||||
|
||||
{-| Remove the access token from the Context -}
|
||||
|
||||
{-| Remove the access token from the Context
|
||||
-}
|
||||
removeAccessToken : Context { a | accessToken : () } -> Context a
|
||||
removeAccessToken (Context data) =
|
||||
Context data
|
||||
|
||||
{-| Remove the base url from the Context -}
|
||||
|
||||
{-| Remove the base url from the Context
|
||||
-}
|
||||
removeBaseUrl : Context { a | baseUrl : () } -> Context a
|
||||
removeBaseUrl (Context data) =
|
||||
Context data
|
||||
|
||||
{-| Remove the transaction id from the Context -}
|
||||
|
||||
{-| Remove the transaction id from the Context
|
||||
-}
|
||||
removeTransactionId : Context { a | transactionId : () } -> Context a
|
||||
removeTransactionId (Context data) =
|
||||
Context data
|
||||
|
||||
{-| Remove the versions from the Context -}
|
||||
|
||||
{-| Remove the versions from the Context
|
||||
-}
|
||||
removeVersions : Context { a | versions : () } -> Context a
|
||||
removeVersions (Context data) =
|
||||
Context data
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
module Internal.Api.CredUpdate exposing (..)
|
||||
|
||||
import Hash
|
||||
import Internal.Api.Chain as Chain exposing (TaskChain, IdemChain)
|
||||
import Html exposing (input)
|
||||
import Internal.Api.Chain as Chain exposing (IdemChain, TaskChain)
|
||||
import Internal.Api.Context as Context exposing (VB, VBA, VBAT)
|
||||
import Internal.Api.GetEvent.Main as GetEvent
|
||||
import Internal.Api.Invite.Main as Invite
|
||||
import Internal.Api.JoinedMembers.Main as JoinedMembers
|
||||
import Internal.Api.LoginWithUsernameAndPassword.Main as LoginWithUsernameAndPassword
|
||||
import Internal.Api.Versions.V1.Versions as V
|
||||
import Internal.Api.Redact.Main as Redact
|
||||
import Internal.Api.SendMessageEvent.Main as SendMessageEvent
|
||||
import Internal.Api.SendStateKey.Main as SendStateKey
|
||||
import Internal.Api.Sync.Main as Sync
|
||||
import Internal.Api.Versions.Main as Versions
|
||||
import Internal.Api.Versions.V1.Versions as V
|
||||
import Internal.Tools.Exceptions as X
|
||||
import Internal.Tools.LoginValues exposing (AccessToken(..))
|
||||
import Internal.Tools.SpecEnums as Enums
|
||||
import Json.Encode as E
|
||||
import Task exposing (Task)
|
||||
import Time
|
||||
import Html exposing (input)
|
||||
|
||||
|
||||
type CredUpdate
|
||||
|
@ -37,22 +37,26 @@ type CredUpdate
|
|||
| UpdateAccessToken String
|
||||
| UpdateVersions V.Versions
|
||||
|
||||
type alias FutureTask = Task X.Error CredUpdate
|
||||
|
||||
type alias FutureTask =
|
||||
Task X.Error CredUpdate
|
||||
|
||||
|
||||
{-| Turn a chain of tasks into a full executable task.
|
||||
-}
|
||||
toTask : TaskChain CredUpdate {} b -> FutureTask
|
||||
toTask =
|
||||
Chain.toTask
|
||||
>> Task.map
|
||||
(\updates ->
|
||||
case updates of
|
||||
[ item ] ->
|
||||
item
|
||||
|
||||
_ ->
|
||||
MultipleUpdates updates
|
||||
)
|
||||
Chain.toTask
|
||||
>> Task.map
|
||||
(\updates ->
|
||||
case updates of
|
||||
[ item ] ->
|
||||
item
|
||||
|
||||
_ ->
|
||||
MultipleUpdates updates
|
||||
)
|
||||
|
||||
|
||||
{-| Get a functional access token.
|
||||
-}
|
||||
|
@ -61,58 +65,64 @@ accessToken ctoken =
|
|||
case ctoken of
|
||||
NoAccess ->
|
||||
X.NoAccessToken
|
||||
|> X.SDKException
|
||||
|> Task.fail
|
||||
|> always
|
||||
|> X.SDKException
|
||||
|> Task.fail
|
||||
|> always
|
||||
|
||||
AccessToken t ->
|
||||
{ contextChange = Context.setAccessToken { accessToken = t, usernameAndPassword = Nothing }
|
||||
, messages = []
|
||||
}
|
||||
|> Chain.TaskChainPiece
|
||||
|> Task.succeed
|
||||
|> always
|
||||
|
||||
|> Chain.TaskChainPiece
|
||||
|> Task.succeed
|
||||
|> always
|
||||
|
||||
UsernameAndPassword { username, password, token } ->
|
||||
case token of
|
||||
Just t ->
|
||||
accessToken (AccessToken t)
|
||||
|
||||
|
||||
Nothing ->
|
||||
loginWithUsernameAndPassword
|
||||
{ username = username, password = password }
|
||||
|
||||
|
||||
type alias GetEventInput =
|
||||
{ eventId : String, roomId : String }
|
||||
|
||||
|
||||
{-| Get an event from the API.
|
||||
-}
|
||||
getEvent : GetEventInput -> IdemChain CredUpdate (VBA a)
|
||||
getEvent { eventId, roomId } context =
|
||||
let
|
||||
input = { accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, eventId = eventId
|
||||
, roomId = roomId
|
||||
}
|
||||
input =
|
||||
{ accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, eventId = eventId
|
||||
, roomId = roomId
|
||||
}
|
||||
in
|
||||
input
|
||||
|> GetEvent.getEvent (Context.getVersions context)
|
||||
|> Task.map (\output ->
|
||||
Chain.TaskChainPiece
|
||||
{ contextChange = identity
|
||||
, messages = [ GetEvent input output ]
|
||||
}
|
||||
)
|
||||
|> Task.map
|
||||
(\output ->
|
||||
Chain.TaskChainPiece
|
||||
{ contextChange = identity
|
||||
, messages = [ GetEvent input output ]
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
{-| Get the supported spec versions from the homeserver.
|
||||
-}
|
||||
getVersions : TaskChain CredUpdate { a | baseUrl : () } (VB a)
|
||||
getVersions context =
|
||||
let
|
||||
input = Context.getBaseUrl context
|
||||
input =
|
||||
Context.getBaseUrl context
|
||||
in
|
||||
Versions.getVersions input
|
||||
Versions.getVersions input
|
||||
|> Task.map
|
||||
(\output ->
|
||||
Chain.TaskChainPiece
|
||||
|
@ -121,24 +131,28 @@ getVersions context =
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
type alias InviteInput =
|
||||
{ reason : Maybe String
|
||||
, roomId : String
|
||||
, userId : String
|
||||
}
|
||||
|
||||
{-| Invite a user to a room. -}
|
||||
|
||||
{-| Invite a user to a room.
|
||||
-}
|
||||
invite : InviteInput -> IdemChain CredUpdate (VBA a)
|
||||
invite { reason, roomId, userId } context =
|
||||
let
|
||||
input = { accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, reason = reason
|
||||
, roomId = roomId
|
||||
, userId = userId
|
||||
}
|
||||
input =
|
||||
{ accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, reason = reason
|
||||
, roomId = roomId
|
||||
, userId = userId
|
||||
}
|
||||
in
|
||||
input
|
||||
input
|
||||
|> Invite.invite (Context.getVersions context)
|
||||
|> Task.map
|
||||
(\output ->
|
||||
|
@ -148,18 +162,21 @@ invite { reason, roomId, userId } context =
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
type alias JoinedMembersInput =
|
||||
{ roomId : String }
|
||||
|
||||
|
||||
joinedMembers : JoinedMembersInput -> IdemChain CredUpdate (VBA a)
|
||||
joinedMembers { roomId } context =
|
||||
let
|
||||
input = { accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, roomId = roomId
|
||||
}
|
||||
input =
|
||||
{ accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, roomId = roomId
|
||||
}
|
||||
in
|
||||
input
|
||||
input
|
||||
|> JoinedMembers.joinedMembers (Context.getVersions context)
|
||||
|> Task.map
|
||||
(\output ->
|
||||
|
@ -169,25 +186,28 @@ joinedMembers { roomId } context =
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
type alias LoginWithUsernameAndPasswordInput =
|
||||
{ password : String
|
||||
, username : String
|
||||
}
|
||||
|
||||
|
||||
loginWithUsernameAndPassword : LoginWithUsernameAndPasswordInput -> TaskChain CredUpdate (VB a) (VBA a)
|
||||
loginWithUsernameAndPassword ({ username, password } as data) context =
|
||||
let
|
||||
input = { baseUrl = Context.getBaseUrl context
|
||||
, username = username
|
||||
, password = password
|
||||
}
|
||||
input =
|
||||
{ baseUrl = Context.getBaseUrl context
|
||||
, username = username
|
||||
, password = password
|
||||
}
|
||||
in
|
||||
input
|
||||
input
|
||||
|> LoginWithUsernameAndPassword.loginWithUsernameAndPassword (Context.getVersions context)
|
||||
|> Task.map
|
||||
(\output ->
|
||||
Chain.TaskChainPiece
|
||||
{ contextChange =
|
||||
{ contextChange =
|
||||
Context.setAccessToken
|
||||
{ accessToken = output.accessToken
|
||||
, usernameAndPassword = Just data
|
||||
|
@ -196,26 +216,29 @@ loginWithUsernameAndPassword ({ username, password } as data) context =
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
type alias RedactInput =
|
||||
{ eventId : String
|
||||
, reason : Maybe String
|
||||
, roomId : String
|
||||
}
|
||||
|
||||
|
||||
{-| Redact an event from a room.
|
||||
-}
|
||||
redact : RedactInput -> TaskChain CredUpdate (VBAT a) (VBA a)
|
||||
redact { eventId, reason, roomId } context =
|
||||
let
|
||||
input = { accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, eventId = eventId
|
||||
, reason = reason
|
||||
, roomId = roomId
|
||||
, txnId = Context.getTransactionId context
|
||||
}
|
||||
input =
|
||||
{ accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, eventId = eventId
|
||||
, reason = reason
|
||||
, roomId = roomId
|
||||
, txnId = Context.getTransactionId context
|
||||
}
|
||||
in
|
||||
input
|
||||
input
|
||||
|> Redact.redact (Context.getVersions context)
|
||||
|> Task.map
|
||||
(\output ->
|
||||
|
@ -225,26 +248,29 @@ redact { eventId, reason, roomId } context =
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
type alias SendMessageEventInput =
|
||||
{ content : E.Value
|
||||
, eventType : String
|
||||
, roomId : String
|
||||
}
|
||||
|
||||
|
||||
{-| Send a message event to a room.
|
||||
-}
|
||||
sendMessageEvent : SendMessageEventInput -> TaskChain CredUpdate (VBAT a) (VBA a)
|
||||
sendMessageEvent { content, eventType, roomId } context =
|
||||
let
|
||||
input = { accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, content = content
|
||||
, eventType = eventType
|
||||
, roomId = roomId
|
||||
, transactionId = Context.getTransactionId context
|
||||
}
|
||||
input =
|
||||
{ accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, content = content
|
||||
, eventType = eventType
|
||||
, roomId = roomId
|
||||
, transactionId = Context.getTransactionId context
|
||||
}
|
||||
in
|
||||
input
|
||||
input
|
||||
|> SendMessageEvent.sendMessageEvent (Context.getVersions context)
|
||||
|> Task.map
|
||||
(\output ->
|
||||
|
@ -254,6 +280,7 @@ sendMessageEvent { content, eventType, roomId } context =
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
type alias SendStateEventInput =
|
||||
{ content : E.Value
|
||||
, eventType : String
|
||||
|
@ -261,20 +288,22 @@ type alias SendStateEventInput =
|
|||
, stateKey : String
|
||||
}
|
||||
|
||||
|
||||
{-| Send a state key event to a room.
|
||||
-}
|
||||
sendStateEvent : SendStateEventInput -> IdemChain CredUpdate (VBA a)
|
||||
sendStateEvent { content, eventType, roomId, stateKey } context =
|
||||
let
|
||||
input = { accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, content = content
|
||||
, eventType = eventType
|
||||
, roomId = roomId
|
||||
, stateKey = stateKey
|
||||
}
|
||||
input =
|
||||
{ accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, content = content
|
||||
, eventType = eventType
|
||||
, roomId = roomId
|
||||
, stateKey = stateKey
|
||||
}
|
||||
in
|
||||
input
|
||||
input
|
||||
|> SendStateKey.sendStateKey (Context.getVersions context)
|
||||
|> Task.map
|
||||
(\output ->
|
||||
|
@ -284,6 +313,7 @@ sendStateEvent { content, eventType, roomId, stateKey } context =
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
type alias SyncInput =
|
||||
{ filter : Maybe String
|
||||
, fullState : Maybe Bool
|
||||
|
@ -292,21 +322,23 @@ type alias SyncInput =
|
|||
, timeout : Maybe Int
|
||||
}
|
||||
|
||||
|
||||
{-| Sync the latest updates.
|
||||
-}
|
||||
sync : SyncInput -> IdemChain CredUpdate (VBA a)
|
||||
sync data context =
|
||||
let
|
||||
input = { accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, filter = data.filter
|
||||
, fullState = data.fullState
|
||||
, setPresence = data.setPresence
|
||||
, since = data.since
|
||||
, timeout = data.timeout
|
||||
}
|
||||
input =
|
||||
{ accessToken = Context.getAccessToken context
|
||||
, baseUrl = Context.getBaseUrl context
|
||||
, filter = data.filter
|
||||
, fullState = data.fullState
|
||||
, setPresence = data.setPresence
|
||||
, since = data.since
|
||||
, timeout = data.timeout
|
||||
}
|
||||
in
|
||||
input
|
||||
input
|
||||
|> Sync.sync (Context.getVersions context)
|
||||
|> Task.map
|
||||
(\output ->
|
||||
|
@ -316,6 +348,7 @@ sync data context =
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
{-| Insert versions, or get them if they are not provided.
|
||||
-}
|
||||
versions : Maybe V.Versions -> TaskChain CredUpdate { a | baseUrl : () } (VB a)
|
||||
|
@ -323,38 +356,41 @@ versions mVersions =
|
|||
case mVersions of
|
||||
Just vs ->
|
||||
withVersions vs
|
||||
|
||||
|
||||
Nothing ->
|
||||
getVersions
|
||||
|
||||
{-| Create a task that insert the base URL into the context.
|
||||
|
||||
{-| Create a task that insert the base URL into the context.
|
||||
-}
|
||||
withBaseUrl : String -> TaskChain CredUpdate a { a | baseUrl : () }
|
||||
withBaseUrl baseUrl =
|
||||
{ contextChange = Context.setBaseUrl baseUrl
|
||||
, messages = []
|
||||
}
|
||||
|> Chain.TaskChainPiece
|
||||
|> Task.succeed
|
||||
|> always
|
||||
|> Chain.TaskChainPiece
|
||||
|> Task.succeed
|
||||
|> always
|
||||
|
||||
|
||||
{-| Create a task that inserts a transaction id into the context.
|
||||
-}
|
||||
withTransactionId : (Int -> String) -> TaskChain CredUpdate a { a | transactionId : () }
|
||||
withTransactionId toString =
|
||||
Time.now
|
||||
|> Task.map
|
||||
(\now ->
|
||||
{ contextChange =
|
||||
now
|
||||
|> Time.posixToMillis
|
||||
|> toString
|
||||
|> Context.setTransactionId
|
||||
, messages = []
|
||||
}
|
||||
|> Chain.TaskChainPiece
|
||||
)
|
||||
|> always
|
||||
|> Task.map
|
||||
(\now ->
|
||||
{ contextChange =
|
||||
now
|
||||
|> Time.posixToMillis
|
||||
|> toString
|
||||
|> Context.setTransactionId
|
||||
, messages = []
|
||||
}
|
||||
|> Chain.TaskChainPiece
|
||||
)
|
||||
|> always
|
||||
|
||||
|
||||
{-| Create a task that inserts versions into the context.
|
||||
-}
|
||||
|
@ -363,6 +399,6 @@ withVersions vs =
|
|||
{ contextChange = Context.setVersions vs.versions
|
||||
, messages = []
|
||||
}
|
||||
|> Chain.TaskChainPiece
|
||||
|> Task.succeed
|
||||
|> always
|
||||
|> Chain.TaskChainPiece
|
||||
|> Task.succeed
|
||||
|> always
|
||||
|
|
|
@ -5,6 +5,7 @@ import Internal.Tools.Exceptions as X
|
|||
import Json.Decode as D
|
||||
import Task exposing (Task)
|
||||
|
||||
|
||||
type alias InviteInputV1 =
|
||||
{ accessToken : String
|
||||
, baseUrl : String
|
||||
|
@ -12,6 +13,7 @@ type alias InviteInputV1 =
|
|||
, userId : String
|
||||
}
|
||||
|
||||
|
||||
type alias InviteInputV2 =
|
||||
{ accessToken : String
|
||||
, baseUrl : String
|
||||
|
@ -20,7 +22,10 @@ type alias InviteInputV2 =
|
|||
, userId : String
|
||||
}
|
||||
|
||||
type alias InviteOutputV1 = ()
|
||||
|
||||
type alias InviteOutputV1 =
|
||||
()
|
||||
|
||||
|
||||
inviteV1 : InviteInputV1 -> Task X.Error InviteOutputV1
|
||||
inviteV1 data =
|
||||
|
@ -39,7 +44,8 @@ inviteV1 data =
|
|||
, timeout = Nothing
|
||||
, decoder = always (D.map (always ()) D.value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
inviteV2 : InviteInputV2 -> Task X.Error InviteOutputV1
|
||||
inviteV2 data =
|
||||
R.rawApiCall
|
||||
|
@ -57,4 +63,4 @@ inviteV2 data =
|
|||
]
|
||||
, timeout = Nothing
|
||||
, decoder = always (D.map (always ()) D.value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,13 +22,12 @@ invite versions =
|
|||
|> VC.sameForVersion "r0.6.1"
|
||||
|> VC.addMiddleLayer
|
||||
{ downcast =
|
||||
(\data ->
|
||||
\data ->
|
||||
{ accessToken = data.accessToken
|
||||
, baseUrl = data.baseUrl
|
||||
, roomId = data.roomId
|
||||
, userId = data.userId
|
||||
}
|
||||
)
|
||||
, current = Api.inviteV2
|
||||
, upcast = identity
|
||||
, version = "v1.1"
|
||||
|
@ -40,8 +39,10 @@ invite versions =
|
|||
|> VC.mostRecentFromVersionList versions
|
||||
|> Maybe.withDefault (always <| Task.fail X.UnsupportedSpecVersion)
|
||||
|
||||
|
||||
type alias InviteInput =
|
||||
Api.InviteInputV2
|
||||
|
||||
|
||||
type alias InviteOutput =
|
||||
Api.InviteOutputV1
|
||||
|
|
|
@ -6,12 +6,14 @@ import Internal.Tools.Exceptions as X
|
|||
import Json.Encode as E
|
||||
import Task exposing (Task)
|
||||
|
||||
|
||||
type alias LoginWithUsernameAndPasswordInputV1 =
|
||||
{ baseUrl : String
|
||||
, password : String
|
||||
, username : String
|
||||
}
|
||||
|
||||
|
||||
type alias LoginWithUsernameAndPasswordOutputV1 =
|
||||
SO.LoggedInResponse
|
||||
|
||||
|
@ -27,8 +29,8 @@ loginWithUsernameAndPasswordV1 data =
|
|||
, queryParams = []
|
||||
, bodyParams =
|
||||
[ [ ( "type", E.string "m.id.user" )
|
||||
, ( "user", E.string data.username )
|
||||
]
|
||||
, ( "user", E.string data.username )
|
||||
]
|
||||
|> E.object
|
||||
|> R.RequiredValue "identifier"
|
||||
, R.RequiredString "password" data.password
|
||||
|
@ -37,4 +39,3 @@ loginWithUsernameAndPasswordV1 data =
|
|||
, timeout = Nothing
|
||||
, decoder = always SO.loggedInResponseDecoder
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import Internal.Tools.Exceptions as X
|
|||
import Internal.Tools.VersionControl as VC
|
||||
import Task exposing (Task)
|
||||
|
||||
|
||||
loginWithUsernameAndPassword : List String -> LoginWithUsernameAndPasswordInput -> Task X.Error LoginWithUsernameAndPasswordOutput
|
||||
loginWithUsernameAndPassword versions =
|
||||
VC.withBottomLayer
|
||||
|
@ -18,6 +19,6 @@ loginWithUsernameAndPassword versions =
|
|||
type alias LoginWithUsernameAndPasswordInput =
|
||||
Api.LoginWithUsernameAndPasswordInputV1
|
||||
|
||||
|
||||
type alias LoginWithUsernameAndPasswordOutput =
|
||||
Api.LoginWithUsernameAndPasswordOutputV1
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ that the credentials type needs to know about before it can make a request.
|
|||
-}
|
||||
|
||||
import Internal.Api.LoginWithUsernameAndPassword.V1.Login as L
|
||||
import Internal.Api.Versions.V1.Versions as V
|
||||
import Internal.Api.Request as R
|
||||
import Internal.Api.Versions.V1.Versions as V
|
||||
import Internal.Tools.Exceptions as X
|
||||
import Internal.Tools.LoginValues exposing (AccessToken(..))
|
||||
import Internal.Tools.ValueGetter exposing (ValueGetter)
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
module Internal.Api.Task exposing (..)
|
||||
|
||||
{-| This module contains all tasks that can be executed.
|
||||
-}
|
||||
|
||||
import Hash
|
||||
import Internal.Api.CredUpdate as C exposing (CredUpdate)
|
||||
import Internal.Api.Chain as Chain
|
||||
import Internal.Tools.LoginValues exposing (AccessToken)
|
||||
import Internal.Api.CredUpdate as C exposing (CredUpdate)
|
||||
import Internal.Api.Versions.V1.Versions as V
|
||||
import Json.Encode as E
|
||||
import Internal.Tools.LoginValues exposing (AccessToken)
|
||||
import Internal.Tools.SpecEnums as Enums
|
||||
import Json.Encode as E
|
||||
|
||||
|
||||
type alias FutureTask =
|
||||
C.FutureTask
|
||||
|
||||
type alias FutureTask = C.FutureTask
|
||||
|
||||
type alias GetEventInput =
|
||||
{ accessToken : AccessToken
|
||||
|
@ -20,13 +24,15 @@ type alias GetEventInput =
|
|||
, versions : Maybe V.Versions
|
||||
}
|
||||
|
||||
|
||||
getEvent : GetEventInput -> FutureTask
|
||||
getEvent { accessToken, baseUrl, eventId, roomId, versions } =
|
||||
C.withBaseUrl baseUrl
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen (C.getEvent { eventId = eventId, roomId = roomId })
|
||||
|> C.toTask
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen (C.getEvent { eventId = eventId, roomId = roomId })
|
||||
|> C.toTask
|
||||
|
||||
|
||||
type alias InviteInput =
|
||||
{ accessToken : AccessToken
|
||||
|
@ -34,16 +40,18 @@ type alias InviteInput =
|
|||
, reason : Maybe String
|
||||
, roomId : String
|
||||
, userId : String
|
||||
, versions : Maybe V.Versions
|
||||
, versions : Maybe V.Versions
|
||||
}
|
||||
|
||||
|
||||
invite : InviteInput -> FutureTask
|
||||
invite { accessToken, baseUrl, reason, roomId, userId, versions } =
|
||||
C.withBaseUrl baseUrl
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen (C.invite { reason = reason, roomId = roomId, userId = userId })
|
||||
|> C.toTask
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen (C.invite { reason = reason, roomId = roomId, userId = userId })
|
||||
|> C.toTask
|
||||
|
||||
|
||||
type alias JoinedMembersInput =
|
||||
{ accessToken : AccessToken
|
||||
|
@ -52,13 +60,15 @@ type alias JoinedMembersInput =
|
|||
, versions : Maybe V.Versions
|
||||
}
|
||||
|
||||
|
||||
joinedMembers : JoinedMembersInput -> FutureTask
|
||||
joinedMembers { accessToken, baseUrl, roomId, versions } =
|
||||
C.withBaseUrl baseUrl
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen (C.joinedMembers { roomId = roomId })
|
||||
|> C.toTask
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen (C.joinedMembers { roomId = roomId })
|
||||
|> C.toTask
|
||||
|
||||
|
||||
type alias RedactInput =
|
||||
{ accessToken : AccessToken
|
||||
|
@ -70,29 +80,31 @@ type alias RedactInput =
|
|||
, versions : Maybe V.Versions
|
||||
}
|
||||
|
||||
|
||||
redact : RedactInput -> FutureTask
|
||||
redact { accessToken, baseUrl, eventId, extraTransactionNoise, reason, roomId, versions} =
|
||||
redact { accessToken, baseUrl, eventId, extraTransactionNoise, reason, roomId, versions } =
|
||||
C.withBaseUrl baseUrl
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen
|
||||
(C.withTransactionId
|
||||
(\now ->
|
||||
[ Hash.fromInt now
|
||||
, Hash.fromString baseUrl
|
||||
, Hash.fromString eventId
|
||||
, Hash.fromString extraTransactionNoise
|
||||
, Hash.fromString (reason |> Maybe.withDefault "noreason")
|
||||
, Hash.fromString roomId
|
||||
]
|
||||
|> List.foldl Hash.independent (Hash.fromString "redact")
|
||||
|> Hash.toString
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen
|
||||
(C.withTransactionId
|
||||
(\now ->
|
||||
[ Hash.fromInt now
|
||||
, Hash.fromString baseUrl
|
||||
, Hash.fromString eventId
|
||||
, Hash.fromString extraTransactionNoise
|
||||
, Hash.fromString (reason |> Maybe.withDefault "noreason")
|
||||
, Hash.fromString roomId
|
||||
]
|
||||
|> List.foldl Hash.independent (Hash.fromString "redact")
|
||||
|> Hash.toString
|
||||
)
|
||||
)
|
||||
)
|
||||
|> Chain.andThen (C.redact { eventId = eventId, reason = reason, roomId = roomId })
|
||||
|> Chain.andThen
|
||||
( Chain.maybe <| C.getEvent { eventId = eventId, roomId = roomId })
|
||||
|> C.toTask
|
||||
|> Chain.andThen (C.redact { eventId = eventId, reason = reason, roomId = roomId })
|
||||
|> Chain.andThen
|
||||
(Chain.maybe <| C.getEvent { eventId = eventId, roomId = roomId })
|
||||
|> C.toTask
|
||||
|
||||
|
||||
type alias SendMessageEventInput =
|
||||
{ accessToken : AccessToken
|
||||
|
@ -104,28 +116,30 @@ type alias SendMessageEventInput =
|
|||
, versions : Maybe V.Versions
|
||||
}
|
||||
|
||||
|
||||
sendMessageEvent : SendMessageEventInput -> FutureTask
|
||||
sendMessageEvent { accessToken, baseUrl, content, eventType, extraTransactionNoise, roomId, versions } =
|
||||
C.withBaseUrl baseUrl
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen
|
||||
( C.withTransactionId
|
||||
(\now ->
|
||||
[ Hash.fromInt now
|
||||
, Hash.fromString baseUrl
|
||||
, Hash.fromString (E.encode 0 content)
|
||||
, Hash.fromString eventType
|
||||
, Hash.fromString extraTransactionNoise
|
||||
, Hash.fromString roomId
|
||||
]
|
||||
|> List.foldl Hash.independent (Hash.fromString "send message")
|
||||
|> Hash.toString
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen
|
||||
(C.withTransactionId
|
||||
(\now ->
|
||||
[ Hash.fromInt now
|
||||
, Hash.fromString baseUrl
|
||||
, Hash.fromString (E.encode 0 content)
|
||||
, Hash.fromString eventType
|
||||
, Hash.fromString extraTransactionNoise
|
||||
, Hash.fromString roomId
|
||||
]
|
||||
|> List.foldl Hash.independent (Hash.fromString "send message")
|
||||
|> Hash.toString
|
||||
)
|
||||
)
|
||||
)
|
||||
|> Chain.andThen (C.sendMessageEvent { content = content, eventType = eventType, roomId = roomId })
|
||||
-- TODO: Get event from API to see what it looks like
|
||||
|> C.toTask
|
||||
|> Chain.andThen (C.sendMessageEvent { content = content, eventType = eventType, roomId = roomId })
|
||||
-- TODO: Get event from API to see what it looks like
|
||||
|> C.toTask
|
||||
|
||||
|
||||
type alias SendStateKeyInput =
|
||||
{ accessToken : AccessToken
|
||||
|
@ -137,14 +151,16 @@ type alias SendStateKeyInput =
|
|||
, versions : Maybe V.Versions
|
||||
}
|
||||
|
||||
|
||||
sendStateKey : SendStateKeyInput -> FutureTask
|
||||
sendStateKey { accessToken, baseUrl, content, eventType, roomId, stateKey, versions } =
|
||||
C.withBaseUrl baseUrl
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen (C.sendStateEvent { content = content, eventType = eventType, roomId = roomId, stateKey = stateKey})
|
||||
-- TODO: Get event from API to see what it looks like
|
||||
|> C.toTask
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen (C.sendStateEvent { content = content, eventType = eventType, roomId = roomId, stateKey = stateKey })
|
||||
-- TODO: Get event from API to see what it looks like
|
||||
|> C.toTask
|
||||
|
||||
|
||||
type alias SyncInput =
|
||||
{ accessToken : AccessToken
|
||||
|
@ -157,18 +173,19 @@ type alias SyncInput =
|
|||
, versions : Maybe V.Versions
|
||||
}
|
||||
|
||||
|
||||
sync : SyncInput -> FutureTask
|
||||
sync { accessToken, baseUrl, filter, fullState, setPresence, since, timeout, versions } =
|
||||
C.withBaseUrl baseUrl
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen
|
||||
(C.sync
|
||||
{ filter = filter
|
||||
, fullState = fullState
|
||||
, setPresence = setPresence
|
||||
, since = since
|
||||
, timeout = timeout
|
||||
}
|
||||
)
|
||||
|> C.toTask
|
||||
|> Chain.andThen (C.versions versions)
|
||||
|> Chain.andThen (C.accessToken accessToken)
|
||||
|> Chain.andThen
|
||||
(C.sync
|
||||
{ filter = filter
|
||||
, fullState = fullState
|
||||
, setPresence = setPresence
|
||||
, since = since
|
||||
, timeout = timeout
|
||||
}
|
||||
)
|
||||
|> C.toTask
|
||||
|
|
|
@ -5,6 +5,7 @@ import Internal.Api.Versions.V1.Versions as SO
|
|||
import Internal.Tools.Exceptions as X
|
||||
import Task exposing (Task)
|
||||
|
||||
|
||||
versionsV1 : { baseUrl : String } -> Task X.Error SO.Versions
|
||||
versionsV1 data =
|
||||
R.rawApiCall
|
||||
|
|
|
@ -8,14 +8,18 @@ Values like these usually imply that there is a leakage in the implementation or
|
|||
|
||||
-}
|
||||
|
||||
import Time
|
||||
import Hash
|
||||
import Time
|
||||
|
||||
|
||||
accessToken : String
|
||||
accessToken = "mistaken_access_token"
|
||||
accessToken =
|
||||
"mistaken_access_token"
|
||||
|
||||
|
||||
baseUrl : String
|
||||
baseUrl = "https://matrix.example.org"
|
||||
baseUrl =
|
||||
"https://matrix.example.org"
|
||||
|
||||
|
||||
eventId : String
|
||||
|
@ -52,10 +56,12 @@ sender : String
|
|||
sender =
|
||||
"@alice:example.org"
|
||||
|
||||
|
||||
transactionId : String
|
||||
transactionId =
|
||||
"elm" ++ (Hash.fromString "leaked_transactionId" |> Hash.toString)
|
||||
|
||||
|
||||
versions : List String
|
||||
versions =
|
||||
[]
|
||||
|
|
|
@ -5,8 +5,8 @@ module Internal.Room exposing (..)
|
|||
|
||||
import Dict
|
||||
import Internal.Api.CredUpdate exposing (CredUpdate)
|
||||
import Internal.Api.Task as Api
|
||||
import Internal.Api.Sync.V2.SpecObjects as Sync
|
||||
import Internal.Api.Task as Api
|
||||
import Internal.Context as Context exposing (Context)
|
||||
import Internal.Event as Event exposing (Event)
|
||||
import Internal.Tools.Exceptions as X
|
||||
|
|
|
@ -51,11 +51,12 @@ getEventById : String -> IRoom -> Maybe IEvent
|
|||
getEventById eventId (IRoom room) =
|
||||
Hashdict.get eventId room.events
|
||||
|
||||
|
||||
getStateEvent : { eventType : String, stateKey : String } -> IRoom -> Maybe IEvent
|
||||
getStateEvent data (IRoom room) =
|
||||
room.timeline
|
||||
|> Timeline.mostRecentState
|
||||
|> StateManager.getStateEvent data
|
||||
|> Timeline.mostRecentState
|
||||
|> StateManager.getStateEvent data
|
||||
|
||||
|
||||
{-| Get the room's id.
|
||||
|
|
Loading…
Reference in New Issue