diff --git a/app/mobile/ios/Podfile.lock b/app/mobile/ios/Podfile.lock index 2e908c83..e1bdc265 100644 --- a/app/mobile/ios/Podfile.lock +++ b/app/mobile/ios/Podfile.lock @@ -669,7 +669,7 @@ SPEC CHECKSUMS: FirebaseInstallations: 99d24bac0243cf8b0e96cf5426340d211f0bcc80 FirebaseMessaging: 4487bbff9b9b927ba1dd3ea40d1ceb58e4ee3cb5 fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 - glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b + glog: 3d02b25ca00c2d456734d0bcff864cbc62f6ae1a GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f GoogleUtilities: 1d20a6ad97ef46f67bbdec158ce00563a671ebb7 nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431 diff --git a/app/mobile/src/context/useCardContext.hook.js b/app/mobile/src/context/useCardContext.hook.js index bbad6b87..5e2f9680 100644 --- a/app/mobile/src/context/useCardContext.hook.js +++ b/app/mobile/src/context/useCardContext.hook.js @@ -581,9 +581,9 @@ export function useCardContext() { const messageIv = iv.toString(); await addContactChannelTopic(node, token, channelId, 'sealedtopic', { messageEncrypted, messageIv }); }, - setChannelTopicSubject: async (cardId, channelId, topicId, data) => { + setChannelTopicSubject: async (cardId, channelId, topicId, dataType, data) => { const { detail, profile } = getCardEntry(cardId); - return await setContactChannelTopicSubject(profile.node, `${profile.guid}.${detail.token}`, channelId, topicId, data); + return await setContactChannelTopicSubject(profile.node, `${profile.guid}.${detail.token}`, channelId, topicId, dataType, data); }, setChannelTopicUnsealedDetail: async (cardId, channelId, topicId, revision, unsealed) => { const { guid } = session.current; diff --git a/app/mobile/src/context/useChannelContext.hook.js b/app/mobile/src/context/useChannelContext.hook.js index 59ec6275..1fce52bb 100644 --- a/app/mobile/src/context/useChannelContext.hook.js +++ b/app/mobile/src/context/useChannelContext.hook.js @@ -278,9 +278,9 @@ export function useChannelContext() { const messageIv = iv.toString(); await addChannelTopic(server, appToken, channelId, 'sealedtopic', { messageEncrypted, messageIv }); }, - setTopicSubject: async (channelId, topicId, data) => { + setTopicSubject: async (channelId, topicId, dataType, data) => { const { server, appToken } = session.current; - return await setChannelTopicSubject(server, appToken, channelId, topicId, data); + return await setChannelTopicSubject(server, appToken, channelId, topicId, dataType, data); }, setTopicUnsealedDetail: async (channelId, topicId, revision, unsealed) => { const { guid } = session.current; diff --git a/app/mobile/src/context/useConversationContext.hook.js b/app/mobile/src/context/useConversationContext.hook.js index 8723a358..7a9c2c0d 100644 --- a/app/mobile/src/context/useConversationContext.hook.js +++ b/app/mobile/src/context/useConversationContext.hook.js @@ -131,11 +131,11 @@ export function useConversationContext() { } return await channel.actions.addTopic(channelId, message, assetId); } - const setTopicSubject = async (cardId, channelId, topicId, data) => { + const setTopicSubject = async (cardId, channelId, topicId, dataType, data) => { if (cardId) { - return await card.actions.setChannelTopicSubject(cardId, channelId, topicId, data); + return await card.actions.setChannelTopicSubject(cardId, channelId, topicId, dataType, data); } - return await channel.actions.setTopicSubject(channelId, topicId, data); + return await channel.actions.setTopicSubject(channelId, topicId, dataType, data); } const remove = async (cardId, channelId) => { if (cardId) { @@ -448,7 +448,6 @@ export function useConversationContext() { } }, unsealTopic: async (topicId, sealKey) => { -console.log("UNSEAL TOPIC"); try { const topic = topics.current.get(topicId); const { messageEncrypted, messageIv } = JSON.parse(topic.detail.data); @@ -466,7 +465,6 @@ console.log("UNSEAL TOPIC"); await card.actions.setChannelTopicUnsealedDetail(cardId, channelId, topic.topicId, topic.detailRevision, topic.unsealedDetial); } else { -console.log("channel topic", topic); await channel.actions.setTopicUnsealedDetail(channelId, topic.topicId, topic.detailRevision, topic.unsealedDetail); } } @@ -522,15 +520,34 @@ console.log("channel topic", topic); if (conversationId.current) { const { cardId, channelId } = conversationId.current; if (cardId) { - return await card.actions.setChannelTopicSubject(cardId, channelId, topicId, data); + return await card.actions.setChannelTopicSubject(cardId, channelId, topicId, 'superbasictopic', data); } else { - return await channel.actions.setTopicSubject(channelId, topicId, data); + return await channel.actions.setTopicSubject(channelId, topicId, 'superbasictopic', data); } } force.current = true; sync(); }, + setSealedTopicSubject: async (topicId, data, sealKey) => { + if (conversationId.current) { + const { cardId, channelId } = conversationId.current; + + const iv = CryptoJS.lib.WordArray.random(128 / 8); + const key = CryptoJS.enc.Hex.parse(sealKey); + const encrypted = CryptoJS.AES.encrypt(JSON.stringify({ message: data }), key, { iv: iv }); + const messageEncrypted = encrypted.ciphertext.toString(CryptoJS.enc.Base64) + const messageIv = iv.toString(); + + if (cardId) { + return await card.actions.setChannelTopicSubject(cardId, channelId, topicId, 'sealedtopic', { messageEncrypted, messageIv }); + } + else { + return await channel.actions.setTopicSubject(channelId, topicId, 'sealedtopic', { messageEncrypted, messageIv }); + } + + } + }, setCard: async (id) => { if (conversationId.current) { const { cardId, channelId } = conversationId.current; diff --git a/app/mobile/src/session/conversation/Conversation.jsx b/app/mobile/src/session/conversation/Conversation.jsx index 8df9fe35..25a9f983 100644 --- a/app/mobile/src/session/conversation/Conversation.jsx +++ b/app/mobile/src/session/conversation/Conversation.jsx @@ -1,4 +1,4 @@ -import { Keyboard, KeyboardAvoidingView, ActivityIndicator, Modal, Platform, TextInput, View, TouchableOpacity, Text, } from 'react-native'; +import { Alert, Keyboard, KeyboardAvoidingView, ActivityIndicator, Modal, Platform, TextInput, View, TouchableOpacity, Text, } from 'react-native'; import { FlatList, ScrollView } from '@stream-io/flat-list-mvcp'; import { memo, useState, useRef, useEffect } from 'react'; import { useConversation } from './useConversation.hook'; diff --git a/app/mobile/src/session/conversation/useConversation.hook.js b/app/mobile/src/session/conversation/useConversation.hook.js index 019646c4..4d3d82ef 100644 --- a/app/mobile/src/session/conversation/useConversation.hook.js +++ b/app/mobile/src/session/conversation/useConversation.hook.js @@ -103,7 +103,12 @@ export function useConversation() { updateState({ editing: false }); }, updateTopic: async () => { - await conversation.actions.setTopicSubject(state.editTopicId, { ...state.editData, text: state.editMessage }); + if (state.locked) { + await conversation.actions.setSealedTopicSubject(state.editTopicId, { ...state.editData, text: state.editMessage }, state.sealKey); + } + else { + await conversation.actions.setTopicSubject(state.editTopicId, { ...state.editData, text: state.editMessage }); + } }, setEditMessage: (editMessage) => { updateState({ editMessage });