Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
67 changes: 67 additions & 0 deletions app/containers/message/Message.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,73 @@ export const WithFile = () => (
</>
);

export const WithUrl = () => (
<>
<Message
msg='Single URL'
urls={[
{
title: 'Better code structure · Issue #1 · RocketChat/Rocket.Chat.ReactNative',
description:
'There are some options to improve the code structure: Read the Building Chatty to get ideas Add redux Rename file meteor.js to RocketChat to encapsulate the API to populate realm Separate views to ...',
url: 'https://github.com/RocketChat/Rocket.Chat.ReactNative/pull/1',
image:
'https://opengraph.githubassets.com/3279b1c919656914846f7e133d6b77526f1182ffd64e7f7d67a01258bb7c190f/RocketChat/Rocket.Chat.ReactNative/issues/1'
}
]}
/>
<Message
msg='Multiple URLs'
urls={[
{
title: 'Better code structure · Issue #1 · RocketChat/Rocket.Chat.ReactNative',
description:
'There are some options to improve the code structure: Read the Building Chatty to get ideas Add redux Rename file meteor.js to RocketChat to encapsulate the API to populate realm Separate views to ...',
url: 'https://github.com/RocketChat/Rocket.Chat.ReactNative/pull/1',
image:
'https://opengraph.githubassets.com/3279b1c919656914846f7e133d6b77526f1182ffd64e7f7d67a01258bb7c190f/RocketChat/Rocket.Chat.ReactNative/issues/1'
},
{
title: 'Better code structure · Issue #1 · RocketChat/Rocket.Chat.ReactNative',
description:
'There are some options to improve the code structure: Read the Building Chatty to get ideas Add redux Rename file meteor.js to RocketChat to encapsulate the API to populate realm Separate views to ...',
url: 'https://github.com/RocketChat/Rocket.Chat.ReactNative/pull/1',
image:
'https://opengraph.githubassets.com/3279b1c919656914846f7e133d6b77526f1182ffd64e7f7d67a01258bb7c190f/RocketChat/Rocket.Chat.ReactNative/issues/1'
}
]}
/>
<Message
msg='URL with no image'
urls={[
{
title: 'Better code structure · Issue #1 · RocketChat/Rocket.Chat.ReactNative',
description:
'There are some options to improve the code structure: Read the Building Chatty to get ideas Add redux Rename file meteor.js to RocketChat to encapsulate the API to populate realm Separate views to ...',
url: 'https://github.com/RocketChat/Rocket.Chat.ReactNative/pull/1'
}
]}
/>
<Message
msg='URL with only title'
urls={[
{
title: 'Better code structure · Issue #1 · RocketChat/Rocket.Chat.ReactNative'
}
]}
/>
<Message
msg='URL with only description'
urls={[
{
description:
'There are some options to improve the code structure: Read the Building Chatty to get ideas Add redux Rename file meteor.js to RocketChat to encapsulate the API to populate realm Separate views to ...'
}
]}
/>
</>
);

export const WithFileLargeFont = () => (
<>
<MessageLargeFont
Expand Down
12 changes: 9 additions & 3 deletions app/containers/message/Urls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { StyleSheet, Text, View, type ViewStyle } from 'react-native';
import Clipboard from '@react-native-clipboard/clipboard';
import { Image } from 'expo-image';
import { dequal } from 'dequal';
import axios from 'axios';

import { useAppSelector } from '../../lib/hooks/useAppSelector';
import Touchable from './Touchable';
Expand Down Expand Up @@ -139,8 +138,15 @@ const Url = ({ url }: { url: IUrl }) => {
const _imageUrl = getImageUrl();
if (!_imageUrl || !API_Embed) return;

const response = await axios.head(_imageUrl);
const contentType = response.headers['content-type'];
const response = await fetch(_imageUrl, {
method: 'HEAD'
});

if (!response.ok) {
return;
}

const contentType = response.headers.get('content-type');
if (contentType?.startsWith?.('image/')) {
setImageUrl(_imageUrl);
}
Expand Down
Loading