Merge remote-tracking branch 'origin/main' into main

main
Bram 2023-09-22 15:33:55 +02:00
commit 42de2a291c
3 changed files with 47 additions and 31 deletions

View File

@ -26,7 +26,7 @@ superior ASCII snake model.)
Every task will add another value to an extensible record, which can be used
by later tasks in the chain. Additionally, every subtask can leave a `VaultUpdate`
type as a message to the Credentials to update certain information.
type as a message to the Vault to update certain information.
-}

View File

@ -1,6 +1,6 @@
module Internal.Values.Vault exposing (..)
{-| The Credentials type is the keychain of the Matrix SDK.
{-| The IVault (Internal Vault) type is the keychain of the Matrix SDK.
It handles all communication with the homeserver.
-}
@ -51,7 +51,7 @@ getInvites (IVault data) =
data.invites
{-| Get a room from the Credentials type by the room's id.
{-| Get a room from the IVault type by the room's id.
-}
getRoomById : String -> IVault -> Maybe IRoom
getRoomById roomId (IVault cred) =
@ -72,7 +72,7 @@ getSince (IVault { since }) =
since
{-| Create new empty Credentials.
{-| Create new empty IVault.
-}
init : IVault
init =
@ -102,7 +102,7 @@ insertAccountData { content, eventType, roomId } (IVault data) =
IVault { data | accountData = Dict.insert eventType content data.accountData }
{-| Add a new room to the Credentials type. If a room with this id already exists, it is overwritten.
{-| Add a new room to the IVault type. If a room with this id already exists, it is overwritten.
This function can hence also be used as an update function for rooms.

View File

@ -168,10 +168,7 @@ roomId =
{-| Send an unformatted text message to a room.
task =
room
|> sendMessage "Hello, world!"
|> Task.attempt onResponse
sendMessage { room = someRoom, onResponse = MessageSent, text = "Hello!" }
**Hint:** are you trying to send multiple messages at the same time? You might want to use `sendMessages` instead.
@ -188,17 +185,27 @@ This way, you will lose messages!
If you're intending to send the same message multiple times, this function will emphasize that these messages are not the same.
data = { room = someRoom, onResponse = MessageSent, text = "Hello!" }
-- SAFE
Task.sequence [ sendMessage "Hello, world!", sendMessage "hi mom!" ]
Cmd.batch [ sendMessage data, sendMessage { data | text = "hi mom!" } ]
-- NOT SAFE
Task.sequence [ sendMessage "Hello, world!", sendMessage "Hello world!" ]
Cmd.batch [ sendMessage data, sendMessage data ]
-- SAFE
Task.sequence <| sendMessages [ "Hello, world!", "hi mom!" ]
sendMessages
{ room = someRoom
, textPieces = [ "Hello!", "hi mom!" ]
, onResponse = MessageSent
}
-- SAFE
Task.sequence <| sendMessages [ "Hello, world!", "Hello, world!" ]
sendMessages
{ room = someRoom
, textPieces = [ "Hello!", "Hello!" ]
, onResponse = MessageSent
}
-}
sendMessages : { room : Room, textPieces : List String, onResponse : VaultUpdate -> msg } -> Cmd msg
@ -210,18 +217,19 @@ sendMessages { room, textPieces, onResponse } =
Keep in mind that this function is not safe to use if you're sending exactly the same messages multiple times:
data =
{ content = E.object []
, eventType = "com.example.foo"
, room = someRoom
, stateKey = Nothing
, onResponse = EventSent
}
-- SAFE
Task.sequence
[ sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
, sendOneEvent { content = E.int 0, eventType = "com.example.foo", stateKey = Nothing } room
]
Cmd.batch [ sendOneEvent data , sendOneEvent { data | content = E.int 0 } ]
-- NOT SAFE
Task.sequence
[ sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
, sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
]
Cmd.batch [ sendOneEvent data , sendOneEvent data ]
-}
sendOneEvent : { content : D.Value, eventType : String, room : Room, stateKey : Maybe String, onResponse : VaultUpdate -> msg } -> Cmd msg
sendOneEvent =
@ -236,17 +244,25 @@ This function ensures that every messages is treated separately.
Keep in mind that this function doesn't send the events in order, it just makes them safe to send at the same time.
-- NOT SAFE
[ sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
, sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
]
|> Task.sequence
data =
{ content = E.object []
, eventType = "com.example.foo"
, room = someRoom
, stateKey = Nothing
, onResponse = EventSent
}
Cmd.batch [ sendOneEvent data , sendOneEvent data ]
-- SAFE
[ { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
, { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
]
|> sendMultipleEvents
|> Task.sequence
data =
{ content = E.object []
, eventType = "com.example.foo"
, stateKey = Nothing
, onResponse = EventSent
}
sendMultipleEvents [ data, data ] someRoom
-}
sendMultipleEvents : List { content : D.Value, eventType : String, stateKey : Maybe String, onResponse : VaultUpdate -> msg } -> Room -> Cmd msg