more channels webapp refactor

This commit is contained in:
Roland Osborne 2023-01-18 21:28:00 -08:00
parent e405f46330
commit b348e38fd1
4 changed files with 11 additions and 8 deletions

View File

@ -37,10 +37,10 @@ export function encryptChannelSubject(subject, publicKeys) {
let seals = []; let seals = [];
let crypto = new JSEncrypt(); let crypto = new JSEncrypt();
publicKeys.forEach(key => { publicKeys.forEach(publicKey => {
crypto.setPublicKey(key); crypto.setPublicKey(publicKey);
const sealedKey = crypto.encrypt(keyHex); const sealedKey = crypto.encrypt(keyHex);
seals.push({ key, sealedKey }); seals.push({ publicKey, sealedKey });
}); });
return { subjectEncrypted, subjectIv, seals }; return { subjectEncrypted, subjectIv, seals };

View File

@ -195,7 +195,9 @@ export function useConversationContext() {
updateState({ channel: channelSync }); updateState({ channel: channelSync });
} }
else { else {
syncing.current = false;
console.log("converstaion not found"); console.log("converstaion not found");
return;
} }
} }

View File

@ -2,13 +2,13 @@ import { useContext, useState, useEffect } from 'react';
import { ChannelContext } from 'context/ChannelContext'; import { ChannelContext } from 'context/ChannelContext';
import { CardContext } from 'context/CardContext'; import { CardContext } from 'context/CardContext';
import { AccountContext } from 'context/AccountContext'; import { AccountContext } from 'context/AccountContext';
import { encryptChannelSubject } from 'context/sealUtil';
export function useAddChannel() { export function useAddChannel() {
const [state, setState] = useState({ const [state, setState] = useState({
sealable: false, sealable: false,
busy: false, busy: false,
showAdd: false, showAdd: false,
subject: null, subject: null,
members: new Set(), members: new Set(),
@ -45,11 +45,12 @@ export function useAddChannel() {
cards.forEach(id => { cards.forEach(id => {
keys.push(card.state.cards.get(id).data.cardProfile.seal); keys.push(card.state.cards.get(id).data.cardProfile.seal);
}); });
const sealed = encryptChannelSubject(state.subject, keys);
throw new Error("TODO"); conversation = await channel.actions.addChannel('sealed', sealed, cards);
} }
else { 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 }); updateState({ busy: false });
} }

View File

@ -125,7 +125,7 @@ export function useChannels() {
item.subject = null; item.subject = null;
} }
} }
if (item.subject == null) { if (item.subject == null || typeof item.subject !== 'string') {
item.subject = item.label; item.subject = item.label;
} }