mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-02 07:06:41 +03:00
contacts-fe: finish sharing interface
This commit is contained in:
parent
36202d5c86
commit
97a278ef05
@ -34,9 +34,20 @@ export default class ContactsApi extends BaseApi<StoreState> {
|
||||
});
|
||||
}
|
||||
|
||||
allow(ship) {
|
||||
allowShips(ships: Patp[]) {
|
||||
return this.storeAction({
|
||||
allow: ship
|
||||
allow: {
|
||||
ships
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
allowGroup(ship: string, name: string) {
|
||||
const group = { ship, name };
|
||||
return this.storeAction({
|
||||
allow: {
|
||||
group
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -46,12 +57,11 @@ export default class ContactsApi extends BaseApi<StoreState> {
|
||||
});
|
||||
}
|
||||
|
||||
share(recipient, us) {
|
||||
share(recipient: Patp) {
|
||||
return this.action(
|
||||
'contact-push-hook',
|
||||
'contact-share',
|
||||
{ share: us },
|
||||
recipient
|
||||
{ share: recipient },
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -96,9 +96,7 @@ export function ChatResource(props: ChatResourceProps) {
|
||||
recipient={owner}
|
||||
group={group}
|
||||
groupPath={groupPath}
|
||||
hideBanner={() => {
|
||||
setProfileAllowed(true);
|
||||
}} />
|
||||
/>
|
||||
{dragging && <SubmitDragger />}
|
||||
<ChatWindow
|
||||
mailboxSize={5}
|
||||
|
@ -22,48 +22,53 @@ const pathAsResource = (path) => {
|
||||
};
|
||||
|
||||
export const ShareProfile = (props) => {
|
||||
const { api, recipient, hideBanner, group, groupPath } = props;
|
||||
console.log(groupPath);
|
||||
// TODO: use isContactPublic somewhere
|
||||
const { api, hideBanner, group, groupPath } = props;
|
||||
|
||||
const [showBanner, setShowBanner] = useState(false);
|
||||
const res = pathAsResource(groupPath);
|
||||
const [recipients, setRecipients] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (!res) { return; }
|
||||
if (!group) { return; }
|
||||
console.log(group);
|
||||
if (group.hidden) {
|
||||
// TODO:
|
||||
// take the union of the pending set and the members set,
|
||||
// subtract ourselves, then if *anyone* has not already been shared with,
|
||||
// show the banner
|
||||
// Promise.all all the members of the set
|
||||
let check =
|
||||
Promise.all()
|
||||
props.api.contacts.fetchIsAllowed(
|
||||
`~${window.ship}`,
|
||||
'personal', // not used
|
||||
recipient,
|
||||
true
|
||||
).then((retVal) => {
|
||||
console.log(retVal);
|
||||
setShowBanner(!retVal);
|
||||
});
|
||||
const members = _.compact(await Promise.all(
|
||||
Array.from(group.members)
|
||||
.map(s => {
|
||||
const ship = `~${s}`;
|
||||
if(s === window.ship) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
return props.api.contacts.fetchIsAllowed(
|
||||
`~${window.ship}`,
|
||||
'personal',
|
||||
ship,
|
||||
true
|
||||
).then(isAllowed => {
|
||||
return isAllowed ? null : ship;
|
||||
});
|
||||
})
|
||||
));
|
||||
if(members.length > 0) {
|
||||
setShowBanner(true);
|
||||
setRecipients(members);
|
||||
} else {
|
||||
setShowBanner(false);
|
||||
}
|
||||
|
||||
} else {
|
||||
// TODO:
|
||||
// if the group is not in the allowed-groups set, then show the banner
|
||||
props.api.contacts.fetchIsAllowed(
|
||||
const groupShared = await props.api.contacts.fetchIsAllowed(
|
||||
res.entity,
|
||||
res.name,
|
||||
recipient,
|
||||
res.entity,
|
||||
false
|
||||
).then((retVal) => {
|
||||
console.log(retVal);
|
||||
setShowBanner(!retVal);
|
||||
});
|
||||
);
|
||||
setShowBanner(!groupShared);
|
||||
}
|
||||
}, [recipient, res, group]);
|
||||
})();
|
||||
|
||||
}, [groupPath]);
|
||||
|
||||
const image = (props?.our?.avatar)
|
||||
? (
|
||||
@ -87,11 +92,17 @@ export const ShareProfile = (props) => {
|
||||
</Row>
|
||||
);
|
||||
|
||||
const onClick = () => {
|
||||
api.contacts.allow(recipient).then(() => {
|
||||
api.contacts.share(recipient, window.ship);
|
||||
});
|
||||
hideBanner();
|
||||
const onClick = async () => {
|
||||
if(group.hidden && recipients.length > 0) {
|
||||
await api.contacts.allowShips(recipients);
|
||||
await Promise.all(recipients.map(r => api.contacts.share(r)))
|
||||
setShowBanner(false);
|
||||
} else if (!group.hidden) {
|
||||
const [,,ship,name] = groupPath.split('/');
|
||||
await api.contacts.allowGroup(ship,name);
|
||||
await api.contacts.share(ship);
|
||||
setShowBanner(false);
|
||||
}
|
||||
};
|
||||
|
||||
return showBanner ? (
|
||||
|
Loading…
Reference in New Issue
Block a user