elm-matrix-sdk-beta/src/Internal/Api/Main.elm

79 lines
1.4 KiB
Elm
Raw Normal View History

2024-05-25 17:47:15 +00:00
module Internal.Api.Main exposing
( Msg
2024-07-09 15:33:41 +00:00
, sendMessageEvent, sync
2024-05-25 17:47:15 +00:00
)
{-|
# Main API module
This module is used as reference for getting
## VaultUpdate
@docs Msg
## Actions
2024-07-09 15:33:41 +00:00
@docs sendMessageEvent, sync
2024-05-25 17:47:15 +00:00
-}
import Internal.Api.Task as ITask exposing (Backpack)
import Internal.Tools.Json as Json
import Internal.Values.Context as Context
import Internal.Values.Envelope as E
2024-05-26 16:53:31 +00:00
{-| Update message type that is being returned.
-}
2024-05-25 17:47:15 +00:00
type alias Msg =
Backpack
{-| Send a message event.
-}
sendMessageEvent :
E.Envelope a
->
{ content : Json.Value
, eventType : String
, roomId : String
, toMsg : Msg -> msg
, transactionId : String
}
-> Cmd msg
sendMessageEvent env data =
ITask.run
data.toMsg
(ITask.sendMessageEvent
{ content = data.content
, eventType = data.eventType
, roomId = data.roomId
, transactionId = data.transactionId
}
)
(Context.apiFormat env.context)
2024-07-09 15:33:41 +00:00
{-| Sync with the Matrix API to stay up-to-date.
-}
sync :
E.Envelope a
2024-07-09 15:50:48 +00:00
-> { toMsg : Msg -> msg }
2024-07-09 15:33:41 +00:00
-> Cmd msg
sync env data =
ITask.run
data.toMsg
(ITask.sync
{ fullState = Nothing
, presence = env.settings.presence
, since = env.context.nextBatch
2024-07-09 15:50:48 +00:00
, timeout = Just env.settings.syncTime
2024-07-09 15:33:41 +00:00
}
)
(Context.apiFormat env.context)