(
});
};
+ const handleGifSelect = async (gif: GifData) => {
+ // Download the GIF data
+ const response = await fetch(gif.url);
+ if (response.status !== 200) {
+ throw new Error(`Failed to fetch GIF: ${response.status}`);
+ }
+
+ const data = await response.arrayBuffer();
+ const uint8Array = new Uint8Array(data);
+
+ // Create a File object for the GIF
+ const filename = `${gif.title}.gif`;
+ const file = new File([uint8Array], filename, { type: 'image/gif' });
+
+ // Upload to Matrix
+ const uploadResponse = await mx.uploadContent(file, {
+ name: filename,
+ type: 'image/gif',
+ });
+ const mxcUrl = uploadResponse.content_uri;
+
+ const content: IContent = {
+ body: filename,
+ url: mxcUrl,
+ info: {
+ w: gif.width,
+ h: gif.height,
+ mimetype: 'image/gif',
+ size: data.byteLength,
+ },
+ };
+
+ // Handle replies if there's a reply draft
+ if (replyDraft) {
+ content['m.relates_to'] = {
+ 'm.in_reply_to': {
+ event_id: replyDraft.eventId,
+ },
+ };
+ if (replyDraft.relation?.rel_type === RelationType.Thread) {
+ content['m.relates_to'].event_id = replyDraft.relation.event_id;
+ content['m.relates_to'].rel_type = RelationType.Thread;
+ content['m.relates_to'].is_falling_back = false;
+ }
+ }
+
+ // Send the gif as sticker event.
+ await mx.sendEvent(roomId, EventType.Sticker, content);
+ setReplyDraft(undefined);
+ };
+
return (
{selectedFiles.length > 0 && (
@@ -607,6 +660,7 @@ export const RoomInput = forwardRef(
onEmojiSelect={handleEmoticonSelect}
onCustomEmojiSelect={handleEmoticonSelect}
onStickerSelect={handleStickerSelect}
+ onGifSelect={handleGifSelect}
requestClose={() => {
setEmojiBoardTab((t) => {
if (t) {
@@ -619,6 +673,18 @@ export const RoomInput = forwardRef(
/>
}
>
+ setEmojiBoardTab(EmojiBoardTab.Gif)}
+ variant="SurfaceVariant"
+ size="300"
+ radii="300"
+ >
+
+
+
{!hideStickerBtn && (
(
setEmojiBoardTab(EmojiBoardTab.Emoji)}
variant="SurfaceVariant"
@@ -646,7 +715,10 @@ export const RoomInput = forwardRef(
diff --git a/src/client/state/cons.js b/src/client/state/cons.js
index 1cb8b102..3e141c5f 100644
--- a/src/client/state/cons.js
+++ b/src/client/state/cons.js
@@ -35,6 +35,9 @@ const cons = {
REUSABLE_DIALOG_OPENED: 'REUSABLE_DIALOG_OPENED',
},
},
+ api: {
+ GIF_PROXY_URL: 'https://proxy.commet.chat',
+ },
};
Object.freeze(cons);