Transform API results into CredUpdate types
parent
68d93180c1
commit
205263f5cd
|
@ -16,6 +16,19 @@ import Json.Encode as E
|
||||||
import Task exposing (Task)
|
import Task exposing (Task)
|
||||||
|
|
||||||
|
|
||||||
|
type CredUpdate
|
||||||
|
= MultipleUpdates (List CredUpdate)
|
||||||
|
-- Updates as a result of API calls
|
||||||
|
| GetEvent GetEvent.EventInput GetEvent.EventOutput
|
||||||
|
| JoinedMembersToRoom JoinedMembers.JoinedMembersInput JoinedMembers.JoinedMembersOutput
|
||||||
|
| MessageEventSent SendMessageEvent.SendMessageEventInput SendMessageEvent.SendMessageEventOutput
|
||||||
|
| StateEventSent SendStateKey.SendStateKeyInput SendStateKey.SendStateKeyOutput
|
||||||
|
| SyncUpdate Sync.SyncInput Sync.SyncOutput
|
||||||
|
-- Updates as a result of getting data early
|
||||||
|
| UpdateAccessToken String
|
||||||
|
| UpdateVersions V.Versions
|
||||||
|
|
||||||
|
|
||||||
type alias Future a =
|
type alias Future a =
|
||||||
Task X.Error a
|
Task X.Error a
|
||||||
|
|
||||||
|
@ -31,17 +44,28 @@ type alias GetEventInput =
|
||||||
|
|
||||||
{-| Get a specific event from the Matrix API.
|
{-| Get a specific event from the Matrix API.
|
||||||
-}
|
-}
|
||||||
getEvent : GetEventInput -> Future GetEvent.EventOutput
|
getEvent : GetEventInput -> Future CredUpdate
|
||||||
getEvent data =
|
getEvent data =
|
||||||
VG.withInfo2
|
VG.withInfo2
|
||||||
(\accessToken versions ->
|
(\accessToken versions ->
|
||||||
GetEvent.getEvent
|
let
|
||||||
versions.versions
|
input : GetEvent.EventInput
|
||||||
|
input =
|
||||||
{ accessToken = accessToken
|
{ accessToken = accessToken
|
||||||
, baseUrl = data.baseUrl
|
, baseUrl = data.baseUrl
|
||||||
, eventId = data.eventId
|
, eventId = data.eventId
|
||||||
, roomId = data.roomId
|
, roomId = data.roomId
|
||||||
}
|
}
|
||||||
|
in
|
||||||
|
GetEvent.getEvent versions.versions input
|
||||||
|
|> Task.map
|
||||||
|
(\output ->
|
||||||
|
MultipleUpdates
|
||||||
|
[ GetEvent input output
|
||||||
|
, UpdateAccessToken accessToken
|
||||||
|
, UpdateVersions versions
|
||||||
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
(PreApi.accessToken data.baseUrl data.accessToken)
|
(PreApi.accessToken data.baseUrl data.accessToken)
|
||||||
(PreApi.versions data.baseUrl data.versions)
|
(PreApi.versions data.baseUrl data.versions)
|
||||||
|
@ -57,16 +81,27 @@ type alias JoinedMembersInput =
|
||||||
|
|
||||||
{-| Get a list of members who are part of a Matrix room.
|
{-| Get a list of members who are part of a Matrix room.
|
||||||
-}
|
-}
|
||||||
joinedMembers : JoinedMembersInput -> Future JoinedMembers.JoinedMembersOutput
|
joinedMembers : JoinedMembersInput -> Future CredUpdate
|
||||||
joinedMembers data =
|
joinedMembers data =
|
||||||
VG.withInfo2
|
VG.withInfo2
|
||||||
(\accessToken versions ->
|
(\accessToken versions ->
|
||||||
JoinedMembers.joinedMembers
|
let
|
||||||
versions.versions
|
input : JoinedMembers.JoinedMembersInput
|
||||||
|
input =
|
||||||
{ accessToken = accessToken
|
{ accessToken = accessToken
|
||||||
, baseUrl = data.baseUrl
|
, baseUrl = data.baseUrl
|
||||||
, roomId = data.roomId
|
, roomId = data.roomId
|
||||||
}
|
}
|
||||||
|
in
|
||||||
|
JoinedMembers.joinedMembers versions.versions input
|
||||||
|
|> Task.map
|
||||||
|
(\output ->
|
||||||
|
MultipleUpdates
|
||||||
|
[ JoinedMembersToRoom input output
|
||||||
|
, UpdateAccessToken accessToken
|
||||||
|
, UpdateVersions versions
|
||||||
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
(PreApi.accessToken data.baseUrl data.accessToken)
|
(PreApi.accessToken data.baseUrl data.accessToken)
|
||||||
(PreApi.versions data.baseUrl data.versions)
|
(PreApi.versions data.baseUrl data.versions)
|
||||||
|
@ -85,12 +120,13 @@ type alias SendMessageEventInput =
|
||||||
|
|
||||||
{-| Send a message event into a Matrix room.
|
{-| Send a message event into a Matrix room.
|
||||||
-}
|
-}
|
||||||
sendMessageEvent : SendMessageEventInput -> Future SendMessageEvent.SendMessageEventOutput
|
sendMessageEvent : SendMessageEventInput -> Future CredUpdate
|
||||||
sendMessageEvent data =
|
sendMessageEvent data =
|
||||||
VG.withInfo3
|
VG.withInfo3
|
||||||
(\accessToken versions transactionId ->
|
(\accessToken versions transactionId ->
|
||||||
SendMessageEvent.sendMessageEvent
|
let
|
||||||
versions.versions
|
input : SendMessageEvent.SendMessageEventInput
|
||||||
|
input =
|
||||||
{ accessToken = accessToken
|
{ accessToken = accessToken
|
||||||
, baseUrl = data.baseUrl
|
, baseUrl = data.baseUrl
|
||||||
, content = data.content
|
, content = data.content
|
||||||
|
@ -98,6 +134,16 @@ sendMessageEvent data =
|
||||||
, roomId = data.roomId
|
, roomId = data.roomId
|
||||||
, transactionId = transactionId
|
, transactionId = transactionId
|
||||||
}
|
}
|
||||||
|
in
|
||||||
|
SendMessageEvent.sendMessageEvent versions.versions input
|
||||||
|
|> Task.map
|
||||||
|
(\output ->
|
||||||
|
MultipleUpdates
|
||||||
|
[ MessageEventSent input output
|
||||||
|
, UpdateAccessToken accessToken
|
||||||
|
, UpdateVersions versions
|
||||||
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
(PreApi.accessToken data.baseUrl data.accessToken)
|
(PreApi.accessToken data.baseUrl data.accessToken)
|
||||||
(PreApi.versions data.baseUrl data.versions)
|
(PreApi.versions data.baseUrl data.versions)
|
||||||
|
@ -129,12 +175,13 @@ type alias SendStateKeyInput =
|
||||||
|
|
||||||
{-| Send a state event into a Matrix room.
|
{-| Send a state event into a Matrix room.
|
||||||
-}
|
-}
|
||||||
sendStateEvent : SendStateKeyInput -> Future SendStateKey.SendStateKeyOutput
|
sendStateEvent : SendStateKeyInput -> Future CredUpdate
|
||||||
sendStateEvent data =
|
sendStateEvent data =
|
||||||
VG.withInfo2
|
VG.withInfo2
|
||||||
(\accessToken versions ->
|
(\accessToken versions ->
|
||||||
SendStateKey.sendStateKey
|
let
|
||||||
versions.versions
|
input : SendStateKey.SendStateKeyInput
|
||||||
|
input =
|
||||||
{ accessToken = accessToken
|
{ accessToken = accessToken
|
||||||
, baseUrl = data.baseUrl
|
, baseUrl = data.baseUrl
|
||||||
, content = data.content
|
, content = data.content
|
||||||
|
@ -142,6 +189,16 @@ sendStateEvent data =
|
||||||
, roomId = data.roomId
|
, roomId = data.roomId
|
||||||
, stateKey = data.stateKey
|
, stateKey = data.stateKey
|
||||||
}
|
}
|
||||||
|
in
|
||||||
|
SendStateKey.sendStateKey versions.versions input
|
||||||
|
|> Task.map
|
||||||
|
(\output ->
|
||||||
|
MultipleUpdates
|
||||||
|
[ StateEventSent input output
|
||||||
|
, UpdateAccessToken accessToken
|
||||||
|
, UpdateVersions versions
|
||||||
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
(PreApi.accessToken data.baseUrl data.accessToken)
|
(PreApi.accessToken data.baseUrl data.accessToken)
|
||||||
(PreApi.versions data.baseUrl data.versions)
|
(PreApi.versions data.baseUrl data.versions)
|
||||||
|
@ -161,12 +218,13 @@ type alias SyncInput =
|
||||||
|
|
||||||
{-| Get the latest sync from the Matrix API.
|
{-| Get the latest sync from the Matrix API.
|
||||||
-}
|
-}
|
||||||
syncCredentials : SyncInput -> Future Sync.SyncOutput
|
syncCredentials : SyncInput -> Future CredUpdate
|
||||||
syncCredentials data =
|
syncCredentials data =
|
||||||
VG.withInfo2
|
VG.withInfo2
|
||||||
(\accessToken versions ->
|
(\accessToken versions ->
|
||||||
Sync.sync
|
let
|
||||||
versions.versions
|
input : Sync.SyncInput
|
||||||
|
input =
|
||||||
{ accessToken = accessToken
|
{ accessToken = accessToken
|
||||||
, baseUrl = data.baseUrl
|
, baseUrl = data.baseUrl
|
||||||
, filter = data.filter
|
, filter = data.filter
|
||||||
|
@ -175,6 +233,16 @@ syncCredentials data =
|
||||||
, since = data.since
|
, since = data.since
|
||||||
, timeout = data.timeout
|
, timeout = data.timeout
|
||||||
}
|
}
|
||||||
|
in
|
||||||
|
Sync.sync versions.versions input
|
||||||
|
|> Task.map
|
||||||
|
(\output ->
|
||||||
|
MultipleUpdates
|
||||||
|
[ SyncUpdate input output
|
||||||
|
, UpdateAccessToken accessToken
|
||||||
|
, UpdateVersions versions
|
||||||
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
(PreApi.accessToken data.baseUrl data.accessToken)
|
(PreApi.accessToken data.baseUrl data.accessToken)
|
||||||
(PreApi.versions data.baseUrl data.versions)
|
(PreApi.versions data.baseUrl data.versions)
|
||||||
|
|
Loading…
Reference in New Issue