Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
RocketChat
Rocket.Chat.ReactNative
Commits
782bdda2
Unverified
Commit
782bdda2
authored
Jan 20, 2022
by
Diego Mello
Committed by
GitHub
Jan 20, 2022
Browse files
[IMPROVE] Convert HEIC images to JPG and remove compression (#3633)
parent
e91bb905
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/containers/MessageBox/index.tsx
View file @
782bdda2
...
...
@@ -2,7 +2,7 @@ import React, { Component } from 'react';
import
{
Alert
,
Keyboard
,
NativeModules
,
Text
,
View
}
from
'
react-native
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
KeyboardAccessoryView
}
from
'
react-native-ui-lib/keyboard
'
;
import
ImagePicker
from
'
react-native-image-crop-picker
'
;
import
ImagePicker
,
{
Image
,
ImageOrVideo
}
from
'
react-native-image-crop-picker
'
;
import
{
dequal
}
from
'
dequal
'
;
import
DocumentPicker
from
'
react-native-document-picker
'
;
import
{
Q
}
from
'
@nozbe/watermelondb
'
;
...
...
@@ -27,7 +27,7 @@ import LeftButtons from './LeftButtons';
// @ts-ignore
// eslint-disable-next-line import/extensions,import/no-unresolved
import
RightButtons
from
'
./RightButtons
'
;
import
{
isAndroid
,
isTablet
}
from
'
../../utils/deviceInfo
'
;
import
{
isAndroid
,
isIOS
,
isTablet
}
from
'
../../utils/deviceInfo
'
;
import
{
canUploadFile
}
from
'
../../utils/media
'
;
import
EventEmiter
from
'
../../utils/events
'
;
import
{
KEY_COMMAND
,
handleCommandShowUpload
,
handleCommandSubmit
,
handleCommandTyping
}
from
'
../../commands
'
;
...
...
@@ -54,15 +54,16 @@ if (isAndroid) {
const
imagePickerConfig
=
{
cropping
:
true
,
compressImageQuality
:
0.8
,
avoidEmptySpaceAroundImage
:
false
,
freeStyleCropEnabled
:
true
freeStyleCropEnabled
:
true
,
forceJpg
:
true
};
const
libraryPickerConfig
=
{
multiple
:
true
,
compressVideoPreset
:
'
Passthrough
'
,
mediaType
:
'
any
'
mediaType
:
'
any
'
,
forceJpg
:
true
};
const
videoPickerConfig
=
{
...
...
@@ -129,6 +130,18 @@ interface IMessageBoxState {
permissionToUpload
:
boolean
;
}
const
forceJpgExtension
=
(
attachment
:
ImageOrVideo
)
=>
{
if
(
isIOS
&&
attachment
.
mime
===
'
image/jpeg
'
&&
attachment
.
filename
)
{
const
regex
=
new
RegExp
(
/.heic$/i
);
if
(
attachment
.
filename
.
match
(
regex
))
{
attachment
.
filename
=
attachment
.
filename
.
replace
(
regex
,
'
.jpg
'
);
}
else
{
attachment
.
filename
+=
'
.jpg
'
;
}
}
return
attachment
;
};
class
MessageBox
extends
Component
<
IMessageBoxProps
,
IMessageBoxState
>
{
private
text
:
string
;
...
...
@@ -692,7 +705,8 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
takePhoto
=
async
()
=>
{
logEvent
(
events
.
ROOM_BOX_ACTION_PHOTO
);
try
{
const
image
=
await
ImagePicker
.
openCamera
(
this
.
imagePickerConfig
);
let
image
=
(
await
ImagePicker
.
openCamera
(
this
.
imagePickerConfig
))
as
Image
;
image
=
forceJpgExtension
(
image
);
if
(
this
.
canUploadFile
(
image
))
{
this
.
openShareView
([
image
]);
}
...
...
@@ -716,7 +730,8 @@ class MessageBox extends Component<IMessageBoxProps, IMessageBoxState> {
chooseFromLibrary
=
async
()
=>
{
logEvent
(
events
.
ROOM_BOX_ACTION_LIBRARY
);
try
{
const
attachments
=
await
ImagePicker
.
openPicker
(
this
.
libraryPickerConfig
);
let
attachments
=
(
await
ImagePicker
.
openPicker
(
this
.
libraryPickerConfig
))
as
ImageOrVideo
[];
attachments
=
attachments
.
map
(
att
=>
forceJpgExtension
(
att
));
this
.
openShareView
(
attachments
);
}
catch
(
e
)
{
logEvent
(
events
.
ROOM_BOX_ACTION_LIBRARY_F
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment