diff --git a/app/mobile/src/context/useCardContext.hook.js b/app/mobile/src/context/useCardContext.hook.js index 8379eb3e..619d45c3 100644 --- a/app/mobile/src/context/useCardContext.hook.js +++ b/app/mobile/src/context/useCardContext.hook.js @@ -93,6 +93,7 @@ export function useCardContext() { } card.channels.set(channelId, { ...channel }); cards.current.set(cardId, { ...card }); + updateState({ cards: cards.current }); } } }; @@ -507,10 +508,12 @@ export function useCardContext() { setUnsealedChannelSubject: async (cardId, channelId, revision, unsealed) => { const { guid } = access.current; await store.actions.setCardChannelItemUnsealedDetail(guid, cardId, channelId, revision, unsealed); + setCardChannelField(cardId, channelId, 'unsealedDetail', unsealed); }, setUnsealedChannelSummary: async (cardId, channelId, revision, unsealed) => { const { guid } = access.current; await store.actions.setCardChannelItemUnsealedSummary(guid, cardId, channelId, revision, unsealed); + setCardChannelField(cardId, channelId, 'unsealedSummary', unsealed); }, setUnsealedTopicSubject: async (cardId, channelId, topicId, revision, unsealed) => { const { guid } = access.current; diff --git a/app/mobile/src/context/useChannelContext.hook.js b/app/mobile/src/context/useChannelContext.hook.js index 90b2119f..c8d15361 100644 --- a/app/mobile/src/context/useChannelContext.hook.js +++ b/app/mobile/src/context/useChannelContext.hook.js @@ -274,10 +274,12 @@ export function useChannelContext() { setUnsealedChannelSubject: async (channelId, revision, unsealed) => { const { guid } = access.current; await store.actions.setChannelItemUnsealedDetail(guid, channelId, revision, unsealed); + setChannelField(channelId, 'unsealedDetail', unsealed); }, setUnsealedChannelSummary: async (channelId, revision, unsealed) => { const { guid } = access.current; await store.actions.setChannelItemUnsealedSummary(guid, channelId, revision, unsealed); + setChannelField(channelId, 'unsealedSummary', unsealed); }, setUnsealedTopicSubject: async (channelId, topicId, revision, unsealed) => { const { guid } = access.current; diff --git a/app/mobile/src/session/channels/useChannels.hook.js b/app/mobile/src/session/channels/useChannels.hook.js index eee7ba11..bd5bf13e 100644 --- a/app/mobile/src/session/channels/useChannels.hook.js +++ b/app/mobile/src/session/channels/useChannels.hook.js @@ -4,7 +4,7 @@ import { CardContext } from 'context/CardContext'; import { AccountContext } from 'context/AccountContext'; import { AppContext } from 'context/AppContext'; 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'; export function useChannels() { @@ -27,8 +27,6 @@ export function useChannels() { } const setChannelItem = async (loginTimestamp, cardId, channelId, item) => { -console.log('set channel item', cardId, channelId); - const timestamp = item.summary.lastTopic.created; const { readRevision, topicRevision } = item; @@ -38,40 +36,46 @@ console.log('set channel item', cardId, channelId); let message; let subject; if (item.detail.dataType === 'sealed') { -console.log("SEALED TYPE"); locked = true; -console.log("CHECK1"); const seals = getChannelSeals(item.detail.data); -console.log("CHECK2"); if (isUnsealed(seals, account.state.sealKey)) { -console.log("CHECK3"); unlocked = true; if (item.unsealedDetail) { - subject = item.detail.unsealedDetail.subject; + subject = item.unsealedDetail.subject; } else { -console.log("TRYING"); try { const contentKey = await getContentKey(seals, account.state.sealKey); const unsealed = decryptChannelSubject(item.detail.data, contentKey); if (cardId) { - await card.actions.setUnsealedChannelSubject(cardId, channelId, item.revision, unsealed); + await card.actions.setUnsealedChannelSubject(cardId, channelId, item.detailRevision, unsealed); } else { await channel.actions.setUnsealedChannelSubject(channelId, item.detailRevision, unsealed); } - subject = unsealed.subject; } catch(err) { console.log(err); } } if (item.summary.lastTopic.dataType === 'sealedtopic') { - if (item.summary.unsealedSummary) { - message = item.detail.unsealedSummary.message; + if (item.unsealedSummary) { + message = item.unsealedSummary.message.text; } 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); - return { cardId, channelId, subject, message, logo, updated, locked, unlocked }; + return { cardId, channelId, subject, message, logo, timestamp, updated, locked, unlocked }; } useEffect(() => { @@ -150,7 +154,10 @@ console.log("TRYING"); }, [app.state, card.state, channel.state, state.filter]); const syncChannels = async () => { - if (!syncing.current) { + if (syncing.current) { + resync.current = true; + } + else { syncing.current = true; const { loginTimestamp } = app.state;