mirror of
https://github.com/balzack/databag.git
synced 2025-05-04 15:35:16 +00:00
support adding members to sealed channels
This commit is contained in:
parent
597b850be4
commit
9d45ff0e79
@ -6,7 +6,7 @@ import { Switch, Button, Modal, Divider, Text, Textarea, Image, TextInput, Actio
|
|||||||
import { Card } from '../card/Card';
|
import { Card } from '../card/Card';
|
||||||
import { modals } from '@mantine/modals'
|
import { modals } from '@mantine/modals'
|
||||||
|
|
||||||
export function Details({ close }: { close: () => void }) {
|
export function Details({ showClose, close }: { showClose: boolean, close: () => void }) {
|
||||||
const { state, actions } = useDetails()
|
const { state, actions } = useDetails()
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [removing, setRemoving] = useState(false);
|
const [removing, setRemoving] = useState(false);
|
||||||
@ -163,34 +163,39 @@ export function Details({ close }: { close: () => void }) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}).map((card, index) => {
|
}).map((card, index) => {
|
||||||
const enable = (
|
const enable = !state.detail ? [] : [
|
||||||
<Switch
|
<Switch
|
||||||
key="enable"
|
key="enable"
|
||||||
className={classes.setMember}
|
className={classes.setMember}
|
||||||
size="sm"
|
size="sm"
|
||||||
checked={Boolean(state.detail.members.find(member => member.guid === card.guid))}
|
checked={Boolean(state.detail.members.find(member => member.guid === card.guid))}
|
||||||
onChange={(ev) => {
|
onChange={async (ev) => {
|
||||||
if (ev.currentTarget.checked) {
|
try {
|
||||||
console.log("ADD MEMBER");
|
if (ev.currentTarget.checked) {
|
||||||
} else {
|
await actions.setMember(card.cardId);
|
||||||
console.log("REMOVE MEMBER");
|
} else {
|
||||||
|
await actions.clearMember(card.cardId);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
showError();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className={classes.card} key={index} imageUrl={card.imageUrl} name={card.name} placeholder={state.strings.name}
|
<Card className={classes.card} key={index} imageUrl={card.imageUrl} name={card.name} placeholder={state.strings.name}
|
||||||
handle={card.handle} node={card.node} actions={[enable]} />
|
handle={card.handle} node={card.node} actions={enable} />
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.details}>
|
<div className={classes.details}>
|
||||||
<div className={classes.header}>
|
<div className={classes.header}>
|
||||||
<IconX className={classes.match} />
|
{ showClose && (<IconX className={classes.match} />)}
|
||||||
<Text className={classes.label}>{ state.strings.details }</Text>
|
<Text className={classes.label}>{ state.strings.details }</Text>
|
||||||
<IconX className={classes.close} onClick={close} />
|
{ showClose && (<IconX className={classes.close} onClick={close} />)}
|
||||||
</div>
|
</div>
|
||||||
{ state.access && (
|
{ state.access && (
|
||||||
<div className={classes.body}>
|
<div className={classes.body}>
|
||||||
|
@ -139,6 +139,14 @@ export function useDetails() {
|
|||||||
const content = app.state.session.getContent();
|
const content = app.state.session.getContent();
|
||||||
await content.flagChannel(state.cardId, state.channelId);
|
await content.flagChannel(state.cardId, state.channelId);
|
||||||
},
|
},
|
||||||
|
setMember: async (cardId: string) => {
|
||||||
|
const content = app.state.session.getContent();
|
||||||
|
await content.setChannelCard(state.channelId, cardId);
|
||||||
|
},
|
||||||
|
clearMember: async (cardId: string) => {
|
||||||
|
const content = app.state.session.getContent();
|
||||||
|
await content.clearChannelCard(state.channelId, cardId);
|
||||||
|
},
|
||||||
setEditSubject: (editSubject: string) => {
|
setEditSubject: (editSubject: string) => {
|
||||||
updateState({ editSubject });
|
updateState({ editSubject });
|
||||||
},
|
},
|
||||||
|
@ -53,7 +53,7 @@ export function Session() {
|
|||||||
)}
|
)}
|
||||||
{details && (
|
{details && (
|
||||||
<div className={classes.screen}>
|
<div className={classes.screen}>
|
||||||
<Details close={closeDetails} />
|
<Details showClose={true} close={closeDetails} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@ -166,7 +166,7 @@ export function Session() {
|
|||||||
</Drawer>
|
</Drawer>
|
||||||
<Drawer opened={details} onClose={closeDetails} withCloseButton={false} size="xs" padding="0" position="right" trapFocus={false}>
|
<Drawer opened={details} onClose={closeDetails} withCloseButton={false} size="xs" padding="0" position="right" trapFocus={false}>
|
||||||
<div style={{ height: '100vh' }}>
|
<div style={{ height: '100vh' }}>
|
||||||
<Details close={closeDetails} />
|
<Details showClose={false} close={closeDetails} />
|
||||||
</div>
|
</div>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
<Drawer opened={settings} onClose={closeSettings} withCloseButton={false} size="sm" padding="0" position="right">
|
<Drawer opened={settings} onClose={closeSettings} withCloseButton={false} size="sm" padding="0" position="right">
|
||||||
|
@ -44,7 +44,10 @@ export class ContentModule implements Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async setChannelCard(channelId: string, cardId: string): Promise<void> {
|
public async setChannelCard(channelId: string, cardId: string): Promise<void> {
|
||||||
return await this.stream.setChannelCard(channelId, cardId);
|
const getSeal = async (aesKey: string) => {
|
||||||
|
return await this.contact.getSeal(cardId, aesKey);
|
||||||
|
}
|
||||||
|
return await this.stream.setChannelCard(channelId, cardId, getSeal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async clearChannelCard(channelId: string, cardId: string): Promise<void> {
|
public async clearChannelCard(channelId: string, cardId: string): Promise<void> {
|
||||||
|
@ -341,14 +341,22 @@ export class StreamModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async setChannelCard(channelId: string, cardId: string): Promise<void> {
|
public async setChannelCard(channelId: string, cardId: string, getSeal: (aesKey: string)=>Promise<{publicKey: string; sealedKey: string}>): Promise<void> {
|
||||||
const { node, secure, token } = this;
|
const { node, secure, token } = this;
|
||||||
const channel = this.channelEntries.get(channelId);
|
const channel = this.channelEntries.get(channelId);
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
throw new Error('channel not found');
|
throw new Error('channel not found');
|
||||||
}
|
}
|
||||||
if (channel.item.detail.sealed) {
|
if (channel.item.detail.sealed) {
|
||||||
throw new Error('sealed channels cannot add members');
|
const channelKey = channel.item.channelKey;
|
||||||
|
if (!channelKey) {
|
||||||
|
throw new Error('cannot add members to locked channels');
|
||||||
|
}
|
||||||
|
const seal = await getSeal(channelKey);
|
||||||
|
const data = JSON.parse(channel.item.detail.data);
|
||||||
|
const seals = [...data.seals, seal];
|
||||||
|
const subject = { ...data, seals };
|
||||||
|
await setChannelSubject(node, secure, token, channelId, channel.item.detail.dataType, subject);
|
||||||
}
|
}
|
||||||
await setChannelCard(node, secure, token, channelId, cardId);
|
await setChannelCard(node, secure, token, channelId, cardId);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user