From: jamesjulich <51384945+jamesjulich@users.noreply.github.com> Date: Mon, 13 Sep 2021 14:34:08 +0000 (-0500) Subject: Support pasting images as attachments. Fixes #87. X-Git-Tag: v1.3.0^2~6^2 X-Git-Url: https://git.wafflesoft.org/?a=commitdiff_plain;h=6434d10e5287282d13b7e8ca9c2891d8736797e2;p=cinny.git Support pasting images as attachments. Fixes #87. --- diff --git a/src/app/organisms/room/RoomViewInput.jsx b/src/app/organisms/room/RoomViewInput.jsx index a72f1e3..1e0f126 100644 --- a/src/app/organisms/room/RoomViewInput.jsx +++ b/src/app/organisms/room/RoomViewInput.jsx @@ -285,6 +285,32 @@ function RoomViewInput({ } } + function handlePaste(e) { + if (e.clipboardData === false) { + return; + } + + if (e.clipboardData.items === undefined) { + return; + } + + for (let i = 0; i < e.clipboardData.items.length; i += 1) { + const item = e.clipboardData.items[i]; + if (item.type.indexOf('image') !== -1) { + const image = item.getAsFile(); + if (attachment === null) { + setAttachment(image); + if (image !== null) { + roomsInput.setAttachment(roomId, image); + return; + } + } else { + return; + } + } + } + } + function addEmoji(emoji) { textAreaRef.current.value += emoji.unicode; } @@ -315,6 +341,7 @@ function RoomViewInput({ timelineScroll.autoReachBottom()} onKeyDown={handleKeyDown} placeholder="Send a message..."