From 1703c091a76e74ca4fbbd8e688003e0303a45245 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 21 Feb 2019 23:03:01 -0800 Subject: [PATCH] Send file names as captions when sending files and images. --- src/Main.elm | 6 +++--- src/Scylla/Http.elm | 20 ++++++++++---------- src/Scylla/Model.elm | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Main.elm b/src/Main.elm index a19a184..d38999f 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -110,7 +110,7 @@ updateMarkdown m { roomId, text, markdown } = in ({ m | transactionId = m.transactionId + 1 }, Cmd.batch [ storeValueCmd, sendMessageCmd ]) -updateFileUploadComplete : Model -> RoomId -> String -> (Result Http.Error String) -> (Model, Cmd Msg) +updateFileUploadComplete : Model -> RoomId -> File -> (Result Http.Error String) -> (Model, Cmd Msg) updateFileUploadComplete m rid mime ur = let command = case ur of @@ -122,7 +122,7 @@ updateFileUploadComplete m rid mime ur = in ({ m | errors = newErrors ++ m.errors, transactionId = m.transactionId + 1}, command) -updateImageUploadComplete : Model -> RoomId -> String -> (Result Http.Error String) -> (Model, Cmd Msg) +updateImageUploadComplete : Model -> RoomId -> File -> (Result Http.Error String) -> (Model, Cmd Msg) updateImageUploadComplete m rid mime ur = let command = case ur of @@ -134,7 +134,7 @@ updateImageUploadComplete m rid mime ur = in ({ m | transactionId = m.transactionId + 1}, command) -updateUploadSelected : Model -> RoomId -> File -> List File -> (String -> Result Http.Error String -> Msg) -> (Model, Cmd Msg) +updateUploadSelected : Model -> RoomId -> File -> List File -> (File -> Result Http.Error String -> Msg) -> (Model, Cmd Msg) updateUploadSelected m rid f fs msg = let uploadCmds = List.map (uploadMediaFile m.apiUrl (Maybe.withDefault "" m.token) msg) (f::fs) diff --git a/src/Scylla/Http.elm b/src/Scylla/Http.elm index 8f32c59..94ffc3f 100644 --- a/src/Scylla/Http.elm +++ b/src/Scylla/Http.elm @@ -53,13 +53,13 @@ sync apiUrl token nextBatch = request , tracker = Nothing } -uploadMediaFile : ApiUrl -> ApiToken -> (String -> Result Http.Error String -> Msg) -> File -> Cmd Msg +uploadMediaFile : ApiUrl -> ApiToken -> (File -> Result Http.Error String -> Msg) -> File -> Cmd Msg uploadMediaFile apiUrl token msg file = request { method = "POST" , headers = authenticatedHeaders token , url = Builder.crossOrigin (fullMediaUrl apiUrl) [ "upload" ] [ Builder.string "filename" (name file) ] , body = fileBody file - , expect = expectJson (msg <| mime file) <| Json.Decode.field "content_uri" Json.Decode.string + , expect = expectJson (msg file) <| Json.Decode.field "content_uri" Json.Decode.string , timeout = Nothing , tracker = Nothing } @@ -103,20 +103,20 @@ sendTextMessage apiUrl token transactionId room message = sendMessage apiUrl tok , ("body", string message) ] -sendImageMessage : ApiUrl -> ApiToken -> Int -> RoomId -> String -> String -> Cmd Msg -sendImageMessage apiUrl token transactionId room mime message = sendMessage apiUrl token transactionId room SendImageResponse +sendImageMessage : ApiUrl -> ApiToken -> Int -> RoomId -> File -> String -> Cmd Msg +sendImageMessage apiUrl token transactionId room file message = sendMessage apiUrl token transactionId room SendImageResponse [ ("msgtype", string "m.image") - , ("body", string "Image") + , ("body", string <| name file) , ("url", string message) - , ("info", object [ ("mimetype", string mime) ]) + , ("info", object [ ("mimetype", string <| mime file) ]) ] -sendFileMessage : ApiUrl -> ApiToken -> Int -> RoomId -> String -> String -> Cmd Msg -sendFileMessage apiUrl token transactionId room mime message = sendMessage apiUrl token transactionId room SendFileResponse +sendFileMessage : ApiUrl -> ApiToken -> Int -> RoomId -> File -> String -> Cmd Msg +sendFileMessage apiUrl token transactionId room file message = sendMessage apiUrl token transactionId room SendFileResponse [ ("msgtype", string "m.file") - , ("body", string "File") + , ("body", string <| name file) , ("url", string message) - , ("info", object [ ("mimetype", string mime) ]) + , ("info", object [ ("mimetype", string <| mime file) ]) ] login : ApiUrl -> Username -> Password -> Cmd Msg diff --git a/src/Scylla/Model.elm b/src/Scylla/Model.elm index 150be74..ea59521 100644 --- a/src/Scylla/Model.elm +++ b/src/Scylla/Model.elm @@ -59,8 +59,8 @@ type Msg = | SendFiles RoomId | ImagesSelected RoomId File (List File) | FilesSelected RoomId File (List File) - | ImageUploadComplete RoomId String (Result Http.Error String) - | FileUploadComplete RoomId String (Result Http.Error String) + | ImageUploadComplete RoomId File (Result Http.Error String) + | FileUploadComplete RoomId File (Result Http.Error String) | SendImageResponse (Result Http.Error ()) | SendFileResponse (Result Http.Error ()) | ReceiveMarkdown MarkdownResponse