From 7ed591abf47b5129bee164043d2a4687e5da92d2 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Thu, 4 May 2023 10:39:09 -0700 Subject: [PATCH] resizing images for sealed channel --- app/mobile/ios/Databag.xcodeproj/project.pbxproj | 4 ++-- .../conversation/addTopic/useAddTopic.hook.js | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/mobile/ios/Databag.xcodeproj/project.pbxproj b/app/mobile/ios/Databag.xcodeproj/project.pbxproj index 9b8a0ef7..c42384fa 100644 --- a/app/mobile/ios/Databag.xcodeproj/project.pbxproj +++ b/app/mobile/ios/Databag.xcodeproj/project.pbxproj @@ -622,7 +622,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.12; + MARKETING_VERSION = 1.13; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", @@ -656,7 +656,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.12; + MARKETING_VERSION = 1.13; OTHER_LDFLAGS = ( "$(inherited)", "-ObjC", diff --git a/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js b/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js index be249491..c1d760cb 100644 --- a/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js +++ b/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js @@ -6,6 +6,7 @@ import Colors from 'constants/Colors'; import { encryptBlock, decryptBlock, getChannelSeals, getContentKey, encryptTopicSubject } from 'context/sealUtil'; import { AccountContext } from 'context/AccountContext'; import RNFS from 'react-native-fs'; +import ImageResizer from '@bam.tech/react-native-image-resizer'; export function useAddTopic(contentKey) { @@ -102,15 +103,16 @@ export function useAddTopic(contentKey) { updateState({ enableImage, enableAudio, enableVideo, locked }); }, [conversation.state]); - const setAsset = async (file) => { + const setAsset = async (file, scale) => { const url = file.startsWith('file:') ? file : `file://${file}`; if (contentKey) { - const stat = await RNFS.stat(url); + const scaled = scale ? await scale(url) : url; + const stat = await RNFS.stat(scaled); const getEncryptedBlock = async (pos, len) => { if (pos + len > stat.size) { return null; } - const block = await RNFS.read(file, len, pos, 'base64'); + const block = await RNFS.read(scaled, len, pos, 'base64'); return encryptBlock(block, contentKey); } return { data: url, encrypted: true, size: stat.size, getEncryptedBlock }; @@ -126,7 +128,10 @@ export function useAddTopic(contentKey) { }, addImage: async (data) => { assetId.current++; - const asset = await setAsset(data); + const asset = await setAsset(data, async (file) => { + const scaled = await ImageResizer.createResizedImage(file, 1024, 1024, "JPEG", 50, 0, null); + return `file://${scaled.path}`; + }); asset.key = assetId.current; asset.type = 'image'; asset.ratio = 1;