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