Finish /sync API definition
parent
632158f309
commit
0978e43fc0
|
@ -16,9 +16,30 @@ communicate with the Matrix server about the Vault's needs.
|
||||||
import Internal.Api.Api as A
|
import Internal.Api.Api as A
|
||||||
import Internal.Api.Request as R
|
import Internal.Api.Request as R
|
||||||
import Internal.Api.Sync.V1 as V1
|
import Internal.Api.Sync.V1 as V1
|
||||||
|
import Internal.Api.Sync.V2 as V2
|
||||||
|
import Internal.Api.Sync.V3 as V3
|
||||||
|
import Internal.Api.Sync.V4 as V4
|
||||||
import Internal.Filter.Timeline as Filter
|
import Internal.Filter.Timeline as Filter
|
||||||
|
|
||||||
|
|
||||||
|
{-| Sync with the Matrix API.
|
||||||
|
-}
|
||||||
|
sync : SyncInput -> A.TaskChain (Phantom a) (Phantom a)
|
||||||
|
sync =
|
||||||
|
A.startWithVersion "v1.1" syncV1
|
||||||
|
|> A.forVersion "v1.2" syncV2
|
||||||
|
|> A.sameForVersion "v1.3"
|
||||||
|
|> A.forVersion "v1.4" syncV3
|
||||||
|
|> A.sameForVersion "v1.5"
|
||||||
|
|> A.sameForVersion "v1.6"
|
||||||
|
|> A.sameForVersion "v1.7"
|
||||||
|
|> A.sameForVersion "v1.8"
|
||||||
|
|> A.sameForVersion "v1.9"
|
||||||
|
|> A.sameForVersion "v1.10"
|
||||||
|
|> A.forVersion "v1.11" syncV4
|
||||||
|
|> A.versionChain
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- For simplicity, we will not use a filter for now
|
-- For simplicity, we will not use a filter for now
|
||||||
-- and assume that every client always wants to receive all events.
|
-- and assume that every client always wants to receive all events.
|
||||||
|
@ -38,6 +59,8 @@ type alias PhantomV1 a =
|
||||||
|
|
||||||
type PresenceV1
|
type PresenceV1
|
||||||
= OfflineV1
|
= OfflineV1
|
||||||
|
| OnlineV1
|
||||||
|
| UnavailableV1
|
||||||
|
|
||||||
|
|
||||||
type alias SyncInput =
|
type alias SyncInput =
|
||||||
|
@ -59,10 +82,17 @@ type alias SyncInputV1 a =
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sync : SyncInput -> A.TaskChain (Phantom a) (Phantom a)
|
presenceV1ToString : PresenceV1 -> String
|
||||||
sync =
|
presenceV1ToString p =
|
||||||
A.startWithVersion "r0.0.0" syncV1
|
case p of
|
||||||
|> A.versionChain
|
OfflineV1 ->
|
||||||
|
"offline"
|
||||||
|
|
||||||
|
OnlineV1 ->
|
||||||
|
"online"
|
||||||
|
|
||||||
|
UnavailableV1 ->
|
||||||
|
"unavailable"
|
||||||
|
|
||||||
|
|
||||||
syncV1 : SyncInputV1 i -> A.TaskChain (PhantomV1 a) (PhantomV1 a)
|
syncV1 : SyncInputV1 i -> A.TaskChain (PhantomV1 a) (PhantomV1 a)
|
||||||
|
@ -71,24 +101,83 @@ syncV1 data =
|
||||||
{ attributes =
|
{ attributes =
|
||||||
[ R.accessToken
|
[ R.accessToken
|
||||||
, R.queryOpString "filter" Nothing -- FILTER HERE
|
, R.queryOpString "filter" Nothing -- FILTER HERE
|
||||||
, R.queryOpString "since" data.since
|
|
||||||
, R.queryOpBool "full_state" data.fullState
|
, R.queryOpBool "full_state" data.fullState
|
||||||
, data.presenceV1
|
, data.presenceV1
|
||||||
|> Maybe.map (always "offline")
|
|> Maybe.map presenceV1ToString
|
||||||
|> R.queryOpString "set_presence"
|
|> R.queryOpString "set_presence"
|
||||||
|
, R.queryOpString "since" data.since
|
||||||
, R.queryOpInt "timeout" data.timeout
|
, R.queryOpInt "timeout" data.timeout
|
||||||
]
|
]
|
||||||
, coder = V1.syncResponseCoder
|
, coder = V1.coderSyncResponse
|
||||||
, contextChange = always identity
|
, contextChange = always identity
|
||||||
, method = "GET"
|
, method = "GET"
|
||||||
, path = [ "_matrix", "client", "r0", "sync" ]
|
, path = [ "_matrix", "client", "r0", "sync" ]
|
||||||
, toUpdate =
|
, toUpdate =
|
||||||
\out ->
|
V1.updateSyncResponse { filter = Filter.pass, since = data.since }
|
||||||
( V1.syncResponseToUpdate
|
}
|
||||||
{ filter = Filter.pass -- FILTER HERE
|
|
||||||
, since = data.since
|
|
||||||
}
|
syncV2 : SyncInputV1 i -> A.TaskChain (PhantomV1 a) (PhantomV1 a)
|
||||||
out
|
syncV2 data =
|
||||||
, []
|
A.request
|
||||||
)
|
{ attributes =
|
||||||
|
[ R.accessToken
|
||||||
|
, R.queryOpString "filter" Nothing
|
||||||
|
, R.queryOpBool "full_state" data.fullState
|
||||||
|
, data.presenceV1
|
||||||
|
|> Maybe.map presenceV1ToString
|
||||||
|
|> R.queryOpString "set_presence"
|
||||||
|
, R.queryOpString "since" data.since
|
||||||
|
, R.queryOpInt "timeout" data.timeout
|
||||||
|
]
|
||||||
|
, coder = V2.coderSyncResponse
|
||||||
|
, contextChange = always identity
|
||||||
|
, method = "GET"
|
||||||
|
, path = [ "_matrix", "client", "r0", "sync" ]
|
||||||
|
, toUpdate =
|
||||||
|
V2.updateSyncResponse { filter = Filter.pass, since = data.since }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
syncV3 : SyncInputV1 i -> A.TaskChain (PhantomV1 a) (PhantomV1 a)
|
||||||
|
syncV3 data =
|
||||||
|
A.request
|
||||||
|
{ attributes =
|
||||||
|
[ R.accessToken
|
||||||
|
, R.queryOpString "filter" Nothing
|
||||||
|
, R.queryOpBool "full_state" data.fullState
|
||||||
|
, data.presenceV1
|
||||||
|
|> Maybe.map presenceV1ToString
|
||||||
|
|> R.queryOpString "set_presence"
|
||||||
|
, R.queryOpString "since" data.since
|
||||||
|
, R.queryOpInt "timeout" data.timeout
|
||||||
|
]
|
||||||
|
, coder = V3.coderSyncResponse
|
||||||
|
, contextChange = always identity
|
||||||
|
, method = "GET"
|
||||||
|
, path = [ "_matrix", "client", "r0", "sync" ]
|
||||||
|
, toUpdate =
|
||||||
|
V3.updateSyncResponse { filter = Filter.pass, since = data.since }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
syncV4 : SyncInputV1 i -> A.TaskChain (PhantomV1 a) (PhantomV1 a)
|
||||||
|
syncV4 data =
|
||||||
|
A.request
|
||||||
|
{ attributes =
|
||||||
|
[ R.accessToken
|
||||||
|
, R.queryOpString "filter" Nothing
|
||||||
|
, R.queryOpBool "full_state" data.fullState
|
||||||
|
, data.presenceV1
|
||||||
|
|> Maybe.map presenceV1ToString
|
||||||
|
|> R.queryOpString "set_presence"
|
||||||
|
, R.queryOpString "since" data.since
|
||||||
|
, R.queryOpInt "timeout" data.timeout
|
||||||
|
]
|
||||||
|
, coder = V4.coderSyncResponse
|
||||||
|
, contextChange = always identity
|
||||||
|
, method = "GET"
|
||||||
|
, path = [ "_matrix", "client", "r0", "sync" ]
|
||||||
|
, toUpdate =
|
||||||
|
V4.updateSyncResponse { filter = Filter.pass, since = data.since }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue