From b348e38fd147cfca39b1dfc3873c20180512421e Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Wed, 18 Jan 2023 21:28:00 -0800 Subject: [PATCH] more channels webapp refactor --- net/web/src/context/sealUtil.js | 6 +++--- net/web/src/context/useConversationContext.hook.js | 2 ++ .../session/channels/addChannel/useAddChannel.hook.js | 9 +++++---- net/web/src/session/channels/useChannels.hook.js | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/net/web/src/context/sealUtil.js b/net/web/src/context/sealUtil.js index 54e79a53..d2e2c081 100644 --- a/net/web/src/context/sealUtil.js +++ b/net/web/src/context/sealUtil.js @@ -37,10 +37,10 @@ export function encryptChannelSubject(subject, publicKeys) { let seals = []; let crypto = new JSEncrypt(); - publicKeys.forEach(key => { - crypto.setPublicKey(key); + publicKeys.forEach(publicKey => { + crypto.setPublicKey(publicKey); const sealedKey = crypto.encrypt(keyHex); - seals.push({ key, sealedKey }); + seals.push({ publicKey, sealedKey }); }); return { subjectEncrypted, subjectIv, seals }; diff --git a/net/web/src/context/useConversationContext.hook.js b/net/web/src/context/useConversationContext.hook.js index 2b074102..d0c29c4d 100644 --- a/net/web/src/context/useConversationContext.hook.js +++ b/net/web/src/context/useConversationContext.hook.js @@ -195,7 +195,9 @@ export function useConversationContext() { updateState({ channel: channelSync }); } else { + syncing.current = false; console.log("converstaion not found"); + return; } } diff --git a/net/web/src/session/channels/addChannel/useAddChannel.hook.js b/net/web/src/session/channels/addChannel/useAddChannel.hook.js index aff17b95..291bcf68 100644 --- a/net/web/src/session/channels/addChannel/useAddChannel.hook.js +++ b/net/web/src/session/channels/addChannel/useAddChannel.hook.js @@ -2,13 +2,13 @@ import { useContext, useState, useEffect } from 'react'; import { ChannelContext } from 'context/ChannelContext'; import { CardContext } from 'context/CardContext'; import { AccountContext } from 'context/AccountContext'; +import { encryptChannelSubject } from 'context/sealUtil'; export function useAddChannel() { const [state, setState] = useState({ sealable: false, busy: false, - showAdd: false, subject: null, members: new Set(), @@ -45,11 +45,12 @@ export function useAddChannel() { cards.forEach(id => { keys.push(card.state.cards.get(id).data.cardProfile.seal); }); - - throw new Error("TODO"); + const sealed = encryptChannelSubject(state.subject, keys); + conversation = await channel.actions.addChannel('sealed', sealed, cards); } else { - conversation = await channel.actions.addChannel('superbasic', state.subject, cards); + const subject = { subject: state.subject }; + conversation = await channel.actions.addChannel('superbasic', subject, cards); } updateState({ busy: false }); } diff --git a/net/web/src/session/channels/useChannels.hook.js b/net/web/src/session/channels/useChannels.hook.js index 4c47df78..d9778e1f 100644 --- a/net/web/src/session/channels/useChannels.hook.js +++ b/net/web/src/session/channels/useChannels.hook.js @@ -125,7 +125,7 @@ export function useChannels() { item.subject = null; } } - if (item.subject == null) { + if (item.subject == null || typeof item.subject !== 'string') { item.subject = item.label; }