This commit is contained in:
Roland Osborne 2022-12-17 10:51:40 -08:00
commit 1a0a9bca69
6 changed files with 36 additions and 14 deletions

View File

@ -669,7 +669,7 @@ SPEC CHECKSUMS:
FirebaseInstallations: 99d24bac0243cf8b0e96cf5426340d211f0bcc80
FirebaseMessaging: 4487bbff9b9b927ba1dd3ea40d1ceb58e4ee3cb5
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
glog: 3d02b25ca00c2d456734d0bcff864cbc62f6ae1a
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
GoogleUtilities: 1d20a6ad97ef46f67bbdec158ce00563a671ebb7
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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';

View File

@ -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 });