Send file names as captions when sending files and images.

This commit is contained in:
Danila Fedorin 2019-02-21 23:03:01 -08:00
parent 28c829c2c8
commit 1703c091a7
3 changed files with 15 additions and 15 deletions

View File

@ -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)

View File

@ -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

View File

@ -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