merging back sealed channel support

This commit is contained in:
balzack 2023-02-27 11:32:53 -08:00
parent 9ffd2f6c7f
commit 84d8598f29
3 changed files with 28 additions and 16 deletions

View File

@ -93,6 +93,7 @@ export function useCardContext() {
} }
card.channels.set(channelId, { ...channel }); card.channels.set(channelId, { ...channel });
cards.current.set(cardId, { ...card }); cards.current.set(cardId, { ...card });
updateState({ cards: cards.current });
} }
} }
}; };
@ -507,10 +508,12 @@ export function useCardContext() {
setUnsealedChannelSubject: async (cardId, channelId, revision, unsealed) => { setUnsealedChannelSubject: async (cardId, channelId, revision, unsealed) => {
const { guid } = access.current; const { guid } = access.current;
await store.actions.setCardChannelItemUnsealedDetail(guid, cardId, channelId, revision, unsealed); await store.actions.setCardChannelItemUnsealedDetail(guid, cardId, channelId, revision, unsealed);
setCardChannelField(cardId, channelId, 'unsealedDetail', unsealed);
}, },
setUnsealedChannelSummary: async (cardId, channelId, revision, unsealed) => { setUnsealedChannelSummary: async (cardId, channelId, revision, unsealed) => {
const { guid } = access.current; const { guid } = access.current;
await store.actions.setCardChannelItemUnsealedSummary(guid, cardId, channelId, revision, unsealed); await store.actions.setCardChannelItemUnsealedSummary(guid, cardId, channelId, revision, unsealed);
setCardChannelField(cardId, channelId, 'unsealedSummary', unsealed);
}, },
setUnsealedTopicSubject: async (cardId, channelId, topicId, revision, unsealed) => { setUnsealedTopicSubject: async (cardId, channelId, topicId, revision, unsealed) => {
const { guid } = access.current; const { guid } = access.current;

View File

@ -274,10 +274,12 @@ export function useChannelContext() {
setUnsealedChannelSubject: async (channelId, revision, unsealed) => { setUnsealedChannelSubject: async (channelId, revision, unsealed) => {
const { guid } = access.current; const { guid } = access.current;
await store.actions.setChannelItemUnsealedDetail(guid, channelId, revision, unsealed); await store.actions.setChannelItemUnsealedDetail(guid, channelId, revision, unsealed);
setChannelField(channelId, 'unsealedDetail', unsealed);
}, },
setUnsealedChannelSummary: async (channelId, revision, unsealed) => { setUnsealedChannelSummary: async (channelId, revision, unsealed) => {
const { guid } = access.current; const { guid } = access.current;
await store.actions.setChannelItemUnsealedSummary(guid, channelId, revision, unsealed); await store.actions.setChannelItemUnsealedSummary(guid, channelId, revision, unsealed);
setChannelField(channelId, 'unsealedSummary', unsealed);
}, },
setUnsealedTopicSubject: async (channelId, topicId, revision, unsealed) => { setUnsealedTopicSubject: async (channelId, topicId, revision, unsealed) => {
const { guid } = access.current; const { guid } = access.current;

View File

@ -4,7 +4,7 @@ import { CardContext } from 'context/CardContext';
import { AccountContext } from 'context/AccountContext'; import { AccountContext } from 'context/AccountContext';
import { AppContext } from 'context/AppContext'; import { AppContext } from 'context/AppContext';
import { ProfileContext } from 'context/ProfileContext'; import { ProfileContext } from 'context/ProfileContext';
import { getChannelSeals, isUnsealed, getContentKey, decryptChannelSubject } from 'context/sealUtil'; import { getChannelSeals, isUnsealed, getContentKey, decryptChannelSubject, decryptTopicSubject } from 'context/sealUtil';
import { getCardByGuid } from 'context/cardUtil'; import { getCardByGuid } from 'context/cardUtil';
export function useChannels() { export function useChannels() {
@ -27,8 +27,6 @@ export function useChannels() {
} }
const setChannelItem = async (loginTimestamp, cardId, channelId, item) => { const setChannelItem = async (loginTimestamp, cardId, channelId, item) => {
console.log('set channel item', cardId, channelId);
const timestamp = item.summary.lastTopic.created; const timestamp = item.summary.lastTopic.created;
const { readRevision, topicRevision } = item; const { readRevision, topicRevision } = item;
@ -38,40 +36,46 @@ console.log('set channel item', cardId, channelId);
let message; let message;
let subject; let subject;
if (item.detail.dataType === 'sealed') { if (item.detail.dataType === 'sealed') {
console.log("SEALED TYPE");
locked = true; locked = true;
console.log("CHECK1");
const seals = getChannelSeals(item.detail.data); const seals = getChannelSeals(item.detail.data);
console.log("CHECK2");
if (isUnsealed(seals, account.state.sealKey)) { if (isUnsealed(seals, account.state.sealKey)) {
console.log("CHECK3");
unlocked = true; unlocked = true;
if (item.unsealedDetail) { if (item.unsealedDetail) {
subject = item.detail.unsealedDetail.subject; subject = item.unsealedDetail.subject;
} }
else { else {
console.log("TRYING");
try { try {
const contentKey = await getContentKey(seals, account.state.sealKey); const contentKey = await getContentKey(seals, account.state.sealKey);
const unsealed = decryptChannelSubject(item.detail.data, contentKey); const unsealed = decryptChannelSubject(item.detail.data, contentKey);
if (cardId) { if (cardId) {
await card.actions.setUnsealedChannelSubject(cardId, channelId, item.revision, unsealed); await card.actions.setUnsealedChannelSubject(cardId, channelId, item.detailRevision, unsealed);
} }
else { else {
await channel.actions.setUnsealedChannelSubject(channelId, item.detailRevision, unsealed); await channel.actions.setUnsealedChannelSubject(channelId, item.detailRevision, unsealed);
} }
subject = unsealed.subject;
} }
catch(err) { catch(err) {
console.log(err); console.log(err);
} }
} }
if (item.summary.lastTopic.dataType === 'sealedtopic') { if (item.summary.lastTopic.dataType === 'sealedtopic') {
if (item.summary.unsealedSummary) { if (item.unsealedSummary) {
message = item.detail.unsealedSummary.message; message = item.unsealedSummary.message.text;
} }
else { else {
// decrypt message try {
const contentKey = await getContentKey(seals, account.state.sealKey);
const unsealed = decryptTopicSubject(item.summary.lastTopic.data, contentKey);
if (cardId) {
await card.actions.setUnsealedChannelSummary(cardId, channelId, item.topicRevision, unsealed);
}
else {
await channel.actions.setUnsealedChannelSummary(channelId, item.topicRevision, unsealed);
}
}
catch(err) {
console.log(err);
}
} }
} }
} }
@ -142,7 +146,7 @@ console.log("TRYING");
const updated = (loginTimestamp < timestamp) && (readRevision < topicRevision); const updated = (loginTimestamp < timestamp) && (readRevision < topicRevision);
return { cardId, channelId, subject, message, logo, updated, locked, unlocked }; return { cardId, channelId, subject, message, logo, timestamp, updated, locked, unlocked };
} }
useEffect(() => { useEffect(() => {
@ -150,7 +154,10 @@ console.log("TRYING");
}, [app.state, card.state, channel.state, state.filter]); }, [app.state, card.state, channel.state, state.filter]);
const syncChannels = async () => { const syncChannels = async () => {
if (!syncing.current) { if (syncing.current) {
resync.current = true;
}
else {
syncing.current = true; syncing.current = true;
const { loginTimestamp } = app.state; const { loginTimestamp } = app.state;