mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
rendering lock icon based on key state
This commit is contained in:
parent
c0942cb4ab
commit
a9840cbaec
@ -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);
|
||||||
|
@ -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);
|
||||||
|
@ -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>
|
||||||
|
@ -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,6 +216,8 @@ export function useChannels() {
|
|||||||
}
|
}
|
||||||
if (chan.data.channelSummary?.lastTopic?.dataType === 'sealedtopic') {
|
if (chan.data.channelSummary?.lastTopic?.dataType === 'sealedtopic') {
|
||||||
try {
|
try {
|
||||||
|
if (chan.unlocked) {
|
||||||
|
message = "...";
|
||||||
if (chan.data.unsealedSummary == null) {
|
if (chan.data.unsealedSummary == null) {
|
||||||
if (chan.cardId) {
|
if (chan.cardId) {
|
||||||
card.actions.unsealChannelSummary(chan.cardId, chan.id, account.state.sealKey);
|
card.actions.unsealChannelSummary(chan.cardId, chan.id, account.state.sealKey);
|
||||||
@ -221,7 +228,8 @@ export function useChannels() {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (typeof chan.data.unsealedSummary.message.text === 'string') {
|
if (typeof chan.data.unsealedSummary.message.text === 'string') {
|
||||||
chan.message = chan.data.unsealedSummary.message.text;
|
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 });
|
||||||
|
Loading…
Reference in New Issue
Block a user