Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Support Insert from iPhone or iPad in Safari #10851

Merged
merged 24 commits into from
May 25, 2023
Merged
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
87e816f
Handle `insertFromPaste` properly for wider ranging paste support
t3chguy May 10, 2023
0e60b97
Support `Insert from iPhone or iPad` in Safari
SuperKenVery May 10, 2023
20f5339
Support Safari `Insert from iPhone or iPad`
SuperKenVery May 11, 2023
745ed2a
Handle `insertFromPaste` properly for wider ranging paste support
t3chguy May 10, 2023
caa13fd
Support `Insert from iPhone or iPad` in Safari
SuperKenVery May 10, 2023
7fdf900
Support Safari `Insert from iPhone or iPad`
SuperKenVery May 11, 2023
7dabe87
Merge branch 't3chguy/onbeforeinput' of github.com:SuperKenVery/matri…
SuperKenVery May 11, 2023
b30a357
Use the MIMEType filter
SuperKenVery May 11, 2023
a07f4ff
Respect reply; don't leak source
SuperKenVery May 17, 2023
88cc152
Merge branch 'develop' into t3chguy/onbeforeinput
t3chguy May 17, 2023
5444b99
Check null; Run prettier
SuperKenVery May 17, 2023
ebc53ed
Add more check to ensure it's inserted from Safari
SuperKenVery May 17, 2023
07a3c7a
Pass strict null checks
SuperKenVery May 17, 2023
ad99392
tsconfig.json: Enable strict null check
SuperKenVery May 17, 2023
5188490
Revert tsconfig change
SuperKenVery May 21, 2023
4a82341
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
SuperKenVery May 22, 2023
1bd0db0
Merge branch 't3chguy/onbeforeinput' of github.com:SuperKenVery/matri…
SuperKenVery May 22, 2023
e53505f
Update src/components/views/rooms/SendMessageComposer.tsx: Simplify c…
SuperKenVery May 23, 2023
511d2a1
Disallow nodes other than an image
SuperKenVery May 23, 2023
f4c7a0b
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
SuperKenVery May 23, 2023
e1755b8
Use blob url as filename
SuperKenVery May 24, 2023
fccd197
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
SuperKenVery May 24, 2023
48ff504
Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into…
SuperKenVery May 25, 2023
0c2e985
Merge branch 't3chguy/onbeforeinput' of github.com:SuperKenVery/matri…
SuperKenVery May 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/components/views/rooms/SendMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { addReplyToMessageContent } from "../../../utils/Reply";
import { doMaybeLocalRoomAction } from "../../../utils/local-room";
import { Caret } from "../../../editor/caret";
import { IDiff } from "../../../editor/diff";
import { getBlobSafeMimeType } from "../../../utils/blobs";

/**
* Build the mentions information based on the editor model (and any related events):
Expand Down Expand Up @@ -682,6 +683,38 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
return true; // to skip internal onPaste handler
}

// Safari `Insert from iPhone or iPad`
// data.getData("text/html") returns a string like: <img src="blob:https://...">
if (data.types.includes("text/html")) {
const imgElementStr=data.getData("text/html");
const parser = new DOMParser();
const imgDoc=parser.parseFromString(imgElementStr,"text/html");

const imgSrc = imgDoc.querySelector("img").src;
SuperKenVery marked this conversation as resolved.
Show resolved Hide resolved

fetch(imgSrc).then((response) => {
response.blob().then((imgBlob) => {
const type = imgBlob.type;
const safetype = getBlobSafeMimeType(type);
const ext=type.split("/")[1];
const file = new File([imgBlob],"safari_inserted_content."+ext,{type:safetype});
SuperKenVery marked this conversation as resolved.
Show resolved Hide resolved
ContentMessages.sharedInstance().sendContentToRoom(
file,
this.props.room.roomId,
this.props.relation,
this.props.mxClient,
null,
SuperKenVery marked this conversation as resolved.
Show resolved Hide resolved
);
},
(error) => {
console.log(error);
}
);
}, (error) => {
console.log(error);
});
}

return false;
};

Expand Down