Skip to content

Commit

Permalink
[FIX] Make attachment validation compatible with web client (#2927)
Browse files Browse the repository at this point in the history
* [FIX] Make attachment validation compatible with web client

* Added stories

Co-authored-by: Diego Mello <diegolmello@gmail.com>
  • Loading branch information
aKn1ghtOut and diegolmello authored Apr 1, 2021
1 parent e32ed8b commit d620074
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 11 deletions.
275 changes: 275 additions & 0 deletions __tests__/__snapshots__/Storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29093,6 +29093,281 @@ exports[`Storyshots Message list message 1`] = `
</View>
</View>
</View>
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"opacity": 1,
}
}
>
<View>
<View
style={
Array [
Object {
"flexDirection": "column",
"paddingHorizontal": 14,
"paddingVertical": 4,
"width": "100%",
},
undefined,
]
}
>
<View
style={
Object {
"flexDirection": "row",
}
}
>
<View
style={
Array [
Object {
"borderRadius": 4,
"height": 36,
"width": 36,
},
Object {
"marginTop": 4,
},
]
}
>
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"opacity": 1,
}
}
>
<View
style={
Array [
Object {
"overflow": "hidden",
},
Object {
"borderRadius": 4,
"height": 36,
"width": 36,
},
]
}
>
<FastImageView
resizeMode="cover"
source={
Object {
"headers": undefined,
"priority": "high",
"uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=36",
}
}
style={
Object {
"bottom": 0,
"left": 0,
"position": "absolute",
"right": 0,
"top": 0,
}
}
/>
</View>
</View>
</View>
<View
style={
Array [
Object {
"flex": 1,
"marginLeft": 46,
},
Object {
"marginLeft": 10,
},
]
}
>
<View
style={
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
}
}
>
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"opacity": 1,
}
}
>
<Text
numberOfLines={1}
style={
Array [
Object {
"backgroundColor": "transparent",
"fontFamily": "System",
"fontSize": 16,
"fontWeight": "500",
"lineHeight": 22,
"textAlign": "left",
},
Object {
"color": "#0d0e12",
},
]
}
>
diego.mello
</Text>
</View>
<Text
style={
Array [
Object {
"backgroundColor": "transparent",
"fontFamily": "System",
"fontSize": 12,
"fontWeight": "400",
"marginLeft": 8,
"textAlign": "left",
},
Object {
"color": "#9ca2a8",
},
]
}
>
10:00 AM
</Text>
</View>
<View>
<Text
numberOfLines={0}
style={
Array [
Object {
"backgroundColor": "transparent",
"fontFamily": "System",
"fontSize": 16,
"fontWeight": "400",
"textAlign": "left",
},
undefined,
Object {
"color": "#2f343d",
},
]
}
>
<Text
accessibilityLabel="Image should not render"
numberOfLines={0}
style={
Array [
Object {
"backgroundColor": "transparent",
"fontFamily": "System",
"fontSize": 16,
"fontWeight": "400",
"textAlign": "left",
},
Array [
Object {},
Object {
"alignItems": "flex-start",
"flexDirection": "row",
"flexWrap": "wrap",
"justifyContent": "flex-start",
"marginBottom": 0,
"marginTop": 0,
},
],
]
}
>
Image should not render
</Text>
</Text>
</View>
<View
accessible={true}
focusable={true}
onClick={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
Object {
"alignItems": "center",
"alignSelf": "flex-start",
"backgroundColor": "#f3f4f5",
"borderColor": "#e1e5e8",
"borderRadius": 4,
"borderWidth": 1,
"flex": 1,
"flexDirection": "row",
"marginTop": 6,
"opacity": 1,
}
}
>
<View
style={
Object {
"borderRadius": 4,
"flex": 1,
"flexDirection": "column",
"padding": 15,
}
}
/>
</View>
</View>
</View>
</View>
</View>
</View>
<Text
style={
Array [
Expand Down
6 changes: 3 additions & 3 deletions app/containers/message/Attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const Attachments = React.memo(({
}

return attachments.map((file, index) => {
if (file.image_url) {
if (file.type === 'file' && file.image_url) {
return <Image key={file.image_url} file={file} showAttachment={showAttachment} getCustomEmoji={getCustomEmoji} theme={theme} />;
}
if (file.audio_url) {
if (file.type === 'file' && file.audio_url) {
return <Audio key={file.audio_url} file={file} getCustomEmoji={getCustomEmoji} theme={theme} />;
}
if (file.video_url) {
if (file.type === 'file' && file.video_url) {
return <Video key={file.video_url} file={file} showAttachment={showAttachment} getCustomEmoji={getCustomEmoji} theme={theme} />;
}

Expand Down
31 changes: 23 additions & 8 deletions storybook/stories/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,21 @@ export default ({ theme }) => {
attachments={[{
title: 'This is a title',
description: 'This is a description',
image_url: '/dummypath'
image_url: '/dummypath',
type: 'file'
}]}
/>
<Message
attachments={[{
title: 'This is a title',
description: 'This is a description :nyan_rocket:',
image_url: '/dummypath',
type: 'file'
}]}
/>
<Message
msg='Image should not render'
attachments={[{
image_url: '/dummypath'
}]}
/>
Expand All @@ -362,13 +370,15 @@ export default ({ theme }) => {
attachments={[{
title: 'This is a title',
description: 'This is a description :nyan_rocket:',
video_url: '/dummypath'
video_url: '/dummypath',
type: 'file'
}]}
/>
<Message
attachments={[{
title: 'This is a title',
video_url: '/dummypath'
video_url: '/dummypath',
type: 'file'
}]}
/>

Expand All @@ -377,29 +387,33 @@ export default ({ theme }) => {
attachments={[{
title: 'This is a title',
description: 'This is a description :nyan_rocket:',
audio_url: '/dummypath'
audio_url: '/dummypath',
type: 'file'
}]}
/>
<Message msg='First message' isHeader={false} />
<Message
attachments={[{
title: 'This is a title',
description: 'This is a description',
audio_url: '/dummypath'
audio_url: '/dummypath',
type: 'file'
}]}
isHeader={false}
/>
<Message
attachments={[{
title: 'This is a title',
audio_url: '/dummypath'
audio_url: '/dummypath',
type: 'file'
}]}
isHeader={false}
/>
<Message
attachments={[{
title: 'This is a title',
audio_url: '/dummypath'
audio_url: '/dummypath',
type: 'file'
}]}
isHeader={false}
/>
Expand Down Expand Up @@ -563,7 +577,8 @@ export default ({ theme }) => {
attachments={[{
title: 'This is a title',
description: 'This is a description',
audio_url: '/file-upload/c4wcNhrbXJLBvAJtN/1535569819516.aac'
audio_url: '/file-upload/c4wcNhrbXJLBvAJtN/1535569819516.aac',
type: 'file'
}]}
tmid='1'
isThreadSequential
Expand Down

0 comments on commit d620074

Please sign in to comment.