diff --git a/src/Scylla/Http.elm b/src/Scylla/Http.elm index d1ee4b8..a95bbfd 100644 --- a/src/Scylla/Http.elm +++ b/src/Scylla/Http.elm @@ -7,6 +7,7 @@ import Scylla.Login exposing (loginResponseDecoder, Username, Password) import Scylla.UserData exposing (userDataDecoder, UserData) import Url.Builder import Json.Encode exposing (object, string, int, bool, list) +import Json.Decode as Decode exposing (field) import Http exposing (request, emptyBody, jsonBody, fileBody, expectJson, expectWhatever) import File exposing (File, name, mime) import Url.Builder as Builder @@ -75,7 +76,7 @@ getHistory apiUrl token room prevBatch = request , tracker = Nothing } -sendMessage : ApiUrl -> ApiToken -> Int -> RoomId -> (Result Http.Error () -> Msg) -> List (String, Json.Encode.Value) -> Cmd Msg +sendMessage : ApiUrl -> ApiToken -> Int -> RoomId -> (Result Http.Error String -> Msg) -> List (String, Json.Encode.Value) -> Cmd Msg sendMessage apiUrl token transactionId room msg contents = request { method = "PUT" , headers = authenticatedHeaders token @@ -84,7 +85,7 @@ sendMessage apiUrl token transactionId room msg contents = request ++ "/send/" ++ "m.room.message" ++ "/" ++ (String.fromInt transactionId) , body = jsonBody <| object contents - , expect = expectWhatever msg + , expect = expectJson msg (field "event_id" Decode.string) , timeout = Nothing , tracker = Nothing } diff --git a/src/Scylla/Model.elm b/src/Scylla/Model.elm index 84094ab..d1df57c 100644 --- a/src/Scylla/Model.elm +++ b/src/Scylla/Model.elm @@ -44,7 +44,7 @@ type Msg = | ChangeRoute Route -- URL changes | ChangeRoomText String String -- Change to a room's input text | SendRoomText String -- Sends a message typed into a given room's input - | SendRoomTextResponse Int (Result Http.Error ()) -- A send message response finished + | SendRoomTextResponse Int (Result Http.Error String) -- A send message response finished | ViewportAfterMessage (Result Browser.Dom.Error Viewport) -- A message has been received, try scroll (maybe) | ViewportChangeComplete (Result Browser.Dom.Error ()) -- We're done changing the viewport. | ReceiveFirstSyncResponse (Result Http.Error SyncResponse) -- HTTP, Sync has finished @@ -63,8 +63,8 @@ type Msg = | FilesSelected RoomId File (List File) | ImageUploadComplete RoomId File (Result Http.Error String) | FileUploadComplete RoomId File (Result Http.Error String) - | SendImageResponse (Result Http.Error ()) - | SendFileResponse (Result Http.Error ()) + | SendImageResponse (Result Http.Error String) + | SendFileResponse (Result Http.Error String) | ReceiveMarkdown MarkdownResponse | DismissError Int | AttemptReconnect