diff --git a/net/web/src/context/useCardContext.hook.js b/net/web/src/context/useCardContext.hook.js index 8c779bf0..40c0c094 100644 --- a/net/web/src/context/useCardContext.hook.js +++ b/net/web/src/context/useCardContext.hook.js @@ -311,6 +311,22 @@ export function useCardContext() { console.log(err); } }, + isUnsealed: (cardId, channelId, sealKey) => { + try { + const card = cards.current.get(cardId); + const channel = card.channels.get(channelId); + const { seals } = JSON.parse(channel.data.channelDetail.data); + for (let i = 0; i < seals.length; i++) { + if (seals[i].publicKey === sealKey.public) { + return sealKey.private != null; + } + } + } + catch(err) { + console.log(err); + } + return false; + }, unsealChannelSummary: (cardId, channelId, sealKey) => { try { const card = cards.current.get(cardId); diff --git a/net/web/src/context/useChannelContext.hook.js b/net/web/src/context/useChannelContext.hook.js index 06a2448d..7a476d4c 100644 --- a/net/web/src/context/useChannelContext.hook.js +++ b/net/web/src/context/useChannelContext.hook.js @@ -164,6 +164,21 @@ export function useChannelContext() { console.log(err); } }, + isUnsealed: (channelId, sealKey) => { + try { + const channel = channels.current.get(channelId); + const { seals } = JSON.parse(channel.data.channelDetail.data); + for (let i = 0; i < seals.length; i++) { + if (seals[i].publicKey === sealKey.public) { + return sealKey.private != null; + } + } + } + catch(err) { + console.log(err); + } + return false; + }, unsealChannelSummary: (channelId, sealKey) => { try { const channel = channels.current.get(channelId); diff --git a/net/web/src/session/channels/channelItem/ChannelItem.jsx b/net/web/src/session/channels/channelItem/ChannelItem.jsx index dc78bcf2..11a6d690 100644 --- a/net/web/src/session/channels/channelItem/ChannelItem.jsx +++ b/net/web/src/session/channels/channelItem/ChannelItem.jsx @@ -21,7 +21,15 @@ export function ChannelItem({ item, openChannel, active }) {
-
{ item.subject }
+
+ { item.locked && !item.unlocked && ( + + )} + { item.locked && item.unlocked && ( + + )} + { item.subject } +
{ item.message }
diff --git a/net/web/src/session/channels/useChannels.hook.js b/net/web/src/session/channels/useChannels.hook.js index e48b3e80..220fc909 100644 --- a/net/web/src/session/channels/useChannels.hook.js +++ b/net/web/src/session/channels/useChannels.hook.js @@ -166,7 +166,12 @@ export function useChannels() { } } else { - chan.unlocked = true; + if (chan.cardId) { + chan.unlocked = card.actions.isUnsealed(chan.cardId, chan.id, account.state.sealKey); + } + else { + chan.unlocked = channel.actions.isUnsealed(chan.id, account.state.sealKey); + } subject = chan.data.unsealedChannel.subject; } } @@ -200,7 +205,7 @@ export function useChannels() { } const setMessage = (chan) => { - let message; + let message = ''; if (chan.data.channelSummary?.lastTopic?.dataType === 'superbasictopic') { try { message = JSON.parse(chan.data.channelSummary.lastTopic.data).text; @@ -211,17 +216,20 @@ export function useChannels() { } if (chan.data.channelSummary?.lastTopic?.dataType === 'sealedtopic') { try { - if (chan.data.unsealedSummary == null) { - if (chan.cardId) { - card.actions.unsealChannelSummary(chan.cardId, chan.id, account.state.sealKey); + if (chan.unlocked) { + message = "..."; + if (chan.data.unsealedSummary == null) { + if (chan.cardId) { + card.actions.unsealChannelSummary(chan.cardId, chan.id, account.state.sealKey); + } + else { + channel.actions.unsealChannelSummary(chan.id, account.state.sealKey); + } } else { - channel.actions.unsealChannelSummary(chan.id, account.state.sealKey); - } - } - else { - if (typeof chan.data.unsealedSummary.message.text === 'string') { - chan.message = chan.data.unsealedSummary.message.text; + if (typeof chan.data.unsealedSummary.message.text === 'string') { + message = chan.data.unsealedSummary.message.text; + } } } } @@ -269,7 +277,7 @@ export function useChannels() { updateState({ channels: filtered }); // eslint-disable-next-line - }, [channel, card, store, filter, state.sealable]); + }, [account, channel, card, store, filter, state.sealable]); useEffect(() => { updateState({ display: viewport.state.display });