rendering lock icon based on key state

This commit is contained in:
Roland Osborne 2022-12-20 22:40:58 -08:00
parent c0942cb4ab
commit a9840cbaec
4 changed files with 60 additions and 13 deletions

View File

@ -311,6 +311,22 @@ export function useCardContext() {
console.log(err); 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) => { unsealChannelSummary: (cardId, channelId, sealKey) => {
try { try {
const card = cards.current.get(cardId); const card = cards.current.get(cardId);

View File

@ -164,6 +164,21 @@ export function useChannelContext() {
console.log(err); 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) => { unsealChannelSummary: (channelId, sealKey) => {
try { try {
const channel = channels.current.get(channelId); const channel = channels.current.get(channelId);

View File

@ -21,7 +21,15 @@ export function ChannelItem({ item, openChannel, active }) {
<SolutionOutlined /> <SolutionOutlined />
</div> </div>
<div class="details"> <div class="details">
<div class="subject">{ item.subject }</div> <div class="subject">
{ item.locked && !item.unlocked && (
<LockFilled style={{ paddingRight: 8 }}/>
)}
{ item.locked && item.unlocked && (
<UnlockOutlined style={{ paddingRight: 8 }}/>
)}
<span>{ item.subject }</span>
</div>
<div class="message">{ item.message }</div> <div class="message">{ item.message }</div>
</div> </div>
</div> </div>

View File

@ -166,7 +166,12 @@ export function useChannels() {
} }
} }
else { 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; subject = chan.data.unsealedChannel.subject;
} }
} }
@ -200,7 +205,7 @@ export function useChannels() {
} }
const setMessage = (chan) => { const setMessage = (chan) => {
let message; let message = '';
if (chan.data.channelSummary?.lastTopic?.dataType === 'superbasictopic') { if (chan.data.channelSummary?.lastTopic?.dataType === 'superbasictopic') {
try { try {
message = JSON.parse(chan.data.channelSummary.lastTopic.data).text; message = JSON.parse(chan.data.channelSummary.lastTopic.data).text;
@ -211,17 +216,20 @@ export function useChannels() {
} }
if (chan.data.channelSummary?.lastTopic?.dataType === 'sealedtopic') { if (chan.data.channelSummary?.lastTopic?.dataType === 'sealedtopic') {
try { try {
if (chan.data.unsealedSummary == null) { if (chan.unlocked) {
if (chan.cardId) { message = "...";
card.actions.unsealChannelSummary(chan.cardId, chan.id, account.state.sealKey); 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 { else {
channel.actions.unsealChannelSummary(chan.id, account.state.sealKey); if (typeof chan.data.unsealedSummary.message.text === 'string') {
} message = chan.data.unsealedSummary.message.text;
} }
else {
if (typeof chan.data.unsealedSummary.message.text === 'string') {
chan.message = chan.data.unsealedSummary.message.text;
} }
} }
} }
@ -269,7 +277,7 @@ export function useChannels() {
updateState({ channels: filtered }); updateState({ channels: filtered });
// eslint-disable-next-line // eslint-disable-next-line
}, [channel, card, store, filter, state.sealable]); }, [account, channel, card, store, filter, state.sealable]);
useEffect(() => { useEffect(() => {
updateState({ display: viewport.state.display }); updateState({ display: viewport.state.display });