|
@@ -1527,19 +1527,43 @@ const GroupChatScreen = ({ route }: { route: any }) => {
|
|
}
|
|
}
|
|
}, [replyMessage]);
|
|
}, [replyMessage]);
|
|
|
|
|
|
|
|
+ const handleOpenImage = async (uri: string, fileName: string) => {
|
|
|
|
+ const dirExist = await FileSystem.getInfoAsync(CACHED_ATTACHMENTS_DIR);
|
|
|
|
+ if (!dirExist.exists) {
|
|
|
|
+ await FileSystem.makeDirectoryAsync(CACHED_ATTACHMENTS_DIR, { intermediates: true });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const fileUri = `${CACHED_ATTACHMENTS_DIR}${fileName}`;
|
|
|
|
+
|
|
|
|
+ const fileExists = await FileSystem.getInfoAsync(fileUri);
|
|
|
|
+ if (fileExists.exists) {
|
|
|
|
+ setSelectedMedia(fileUri);
|
|
|
|
+
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ setSelectedMedia(uri);
|
|
|
|
+
|
|
|
|
+ const { uri: localUri } = await FileSystem.downloadAsync(uri, fileUri, {
|
|
|
|
+ headers: { Nmtoken: token }
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+
|
|
const renderMessageImage = (props: any) => {
|
|
const renderMessageImage = (props: any) => {
|
|
const { currentMessage } = props;
|
|
const { currentMessage } = props;
|
|
const leftMessage = currentMessage?.user?._id !== +currentUserId;
|
|
const leftMessage = currentMessage?.user?._id !== +currentUserId;
|
|
|
|
|
|
return (
|
|
return (
|
|
<TouchableOpacity
|
|
<TouchableOpacity
|
|
- onPress={() =>
|
|
|
|
- setSelectedMedia(
|
|
|
|
- currentMessage.attachment.attachment_full_url?.startsWith('/')
|
|
|
|
- ? API_HOST + currentMessage.attachment.attachment_full_url
|
|
|
|
- : currentMessage.attachment.attachment_full_url
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
|
|
+ onPress={() => {
|
|
|
|
+ if (!currentMessage.attachment.attachment_full_url?.startsWith('/')) {
|
|
|
|
+ setSelectedMedia(currentMessage.attachment.attachment_full_url);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ handleOpenImage(
|
|
|
|
+ API_HOST + currentMessage.attachment.attachment_full_url,
|
|
|
|
+ currentMessage.attachment?.filename
|
|
|
|
+ );
|
|
|
|
+ }}
|
|
onLongPress={() => handleLongPress(currentMessage, props)}
|
|
onLongPress={() => handleLongPress(currentMessage, props)}
|
|
style={styles.imageContainer}
|
|
style={styles.imageContainer}
|
|
disabled={currentMessage.isSending}
|
|
disabled={currentMessage.isSending}
|