Merge remote-tracking branch 'origin/main' into main
commit
42de2a291c
|
@ -26,7 +26,7 @@ superior ASCII snake model.)
|
||||||
|
|
||||||
Every task will add another value to an extensible record, which can be used
|
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`
|
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.
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module Internal.Values.Vault exposing (..)
|
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.
|
It handles all communication with the homeserver.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ getInvites (IVault data) =
|
||||||
data.invites
|
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 : String -> IVault -> Maybe IRoom
|
||||||
getRoomById roomId (IVault cred) =
|
getRoomById roomId (IVault cred) =
|
||||||
|
@ -72,7 +72,7 @@ getSince (IVault { since }) =
|
||||||
since
|
since
|
||||||
|
|
||||||
|
|
||||||
{-| Create new empty Credentials.
|
{-| Create new empty IVault.
|
||||||
-}
|
-}
|
||||||
init : IVault
|
init : IVault
|
||||||
init =
|
init =
|
||||||
|
@ -102,7 +102,7 @@ insertAccountData { content, eventType, roomId } (IVault data) =
|
||||||
IVault { data | accountData = Dict.insert eventType content data.accountData }
|
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.
|
This function can hence also be used as an update function for rooms.
|
||||||
|
|
||||||
|
|
|
@ -168,10 +168,7 @@ roomId =
|
||||||
|
|
||||||
{-| Send an unformatted text message to a room.
|
{-| Send an unformatted text message to a room.
|
||||||
|
|
||||||
task =
|
sendMessage { room = someRoom, onResponse = MessageSent, text = "Hello!" }
|
||||||
room
|
|
||||||
|> sendMessage "Hello, world!"
|
|
||||||
|> Task.attempt onResponse
|
|
||||||
|
|
||||||
**Hint:** are you trying to send multiple messages at the same time? You might want to use `sendMessages` instead.
|
**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.
|
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
|
-- SAFE
|
||||||
Task.sequence [ sendMessage "Hello, world!", sendMessage "hi mom!" ]
|
Cmd.batch [ sendMessage data, sendMessage { data | text = "hi mom!" } ]
|
||||||
|
|
||||||
-- NOT SAFE
|
-- NOT SAFE
|
||||||
Task.sequence [ sendMessage "Hello, world!", sendMessage "Hello world!" ]
|
Cmd.batch [ sendMessage data, sendMessage data ]
|
||||||
|
|
||||||
-- SAFE
|
-- SAFE
|
||||||
Task.sequence <| sendMessages [ "Hello, world!", "hi mom!" ]
|
sendMessages
|
||||||
|
{ room = someRoom
|
||||||
|
, textPieces = [ "Hello!", "hi mom!" ]
|
||||||
|
, onResponse = MessageSent
|
||||||
|
}
|
||||||
|
|
||||||
-- SAFE
|
-- 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
|
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:
|
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
|
-- SAFE
|
||||||
Task.sequence
|
Cmd.batch [ sendOneEvent data , sendOneEvent { data | content = E.int 0 } ]
|
||||||
[ sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
|
||||||
, sendOneEvent { content = E.int 0, eventType = "com.example.foo", stateKey = Nothing } room
|
|
||||||
]
|
|
||||||
|
|
||||||
-- NOT SAFE
|
-- NOT SAFE
|
||||||
Task.sequence
|
Cmd.batch [ sendOneEvent data , sendOneEvent data ]
|
||||||
[ sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
|
||||||
, sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
|
||||||
]
|
|
||||||
|
|
||||||
-}
|
-}
|
||||||
sendOneEvent : { content : D.Value, eventType : String, room : Room, stateKey : Maybe String, onResponse : VaultUpdate -> msg } -> Cmd msg
|
sendOneEvent : { content : D.Value, eventType : String, room : Room, stateKey : Maybe String, onResponse : VaultUpdate -> msg } -> Cmd msg
|
||||||
sendOneEvent =
|
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.
|
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
|
-- NOT SAFE
|
||||||
[ sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
data =
|
||||||
, sendOneEvent { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
{ content = E.object []
|
||||||
]
|
, eventType = "com.example.foo"
|
||||||
|> Task.sequence
|
, room = someRoom
|
||||||
|
, stateKey = Nothing
|
||||||
|
, onResponse = EventSent
|
||||||
|
}
|
||||||
|
|
||||||
|
Cmd.batch [ sendOneEvent data , sendOneEvent data ]
|
||||||
|
|
||||||
-- SAFE
|
-- SAFE
|
||||||
[ { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
data =
|
||||||
, { content = E.object [], eventType = "com.example.foo", stateKey = Nothing } room
|
{ content = E.object []
|
||||||
]
|
, eventType = "com.example.foo"
|
||||||
|> sendMultipleEvents
|
, stateKey = Nothing
|
||||||
|> Task.sequence
|
, onResponse = EventSent
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMultipleEvents [ data, data ] someRoom
|
||||||
|
|
||||||
-}
|
-}
|
||||||
sendMultipleEvents : List { content : D.Value, eventType : String, stateKey : Maybe String, onResponse : VaultUpdate -> msg } -> Room -> Cmd msg
|
sendMultipleEvents : List { content : D.Value, eventType : String, stateKey : Maybe String, onResponse : VaultUpdate -> msg } -> Room -> Cmd msg
|
||||||
|
|
Loading…
Reference in New Issue