interface: profiles would intermittently show contact information when they should not, fixes this

This commit is contained in:
Logan Allen 2021-02-12 11:48:50 -06:00
parent 38ac5f191f
commit 1c4baea62f

View File

@ -80,49 +80,52 @@ export function ChatResource(props: ChatResourceProps) {
}, [station]); }, [station]);
const [showBanner, setShowBanner] = useState(false); const [showBanner, setShowBanner] = useState(false);
const [hasLoadedAllowed, setHasLoadedAllowed] = useState(false);
const [recipients, setRecipients] = useState([]); const [recipients, setRecipients] = useState([]);
const res = resourceFromPath(groupPath); const res = resourceFromPath(groupPath);
useEffect(() => { useEffect(() => {
(async () => { (async () => {
if (!res) { return; } if (!res) { return; }
if (!group) { return; } if (!group) { return; }
if (group.hidden) { if (group.hidden) {
const members = _.compact(await Promise.all( const members = _.compact(await Promise.all(
Array.from(group.members) Array.from(group.members)
.map(s => { .map(s => {
const ship = `~${s}`; const ship = `~${s}`;
if(s === window.ship) { if(s === window.ship) {
return Promise.resolve(null); return Promise.resolve(null);
} }
return props.api.contacts.fetchIsAllowed( return props.api.contacts.fetchIsAllowed(
`~${window.ship}`, `~${window.ship}`,
'personal', 'personal',
ship, ship,
true true
).then(isAllowed => { ).then(isAllowed => {
return isAllowed ? null : ship; return isAllowed ? null : ship;
}); });
}) })
)); ));
if(members.length > 0) {
setShowBanner(true);
setRecipients(members);
} else {
setShowBanner(false);
}
if(members.length > 0) {
setShowBanner(true);
setRecipients(members);
} else { } else {
setShowBanner(false); const groupShared = await props.api.contacts.fetchIsAllowed(
`~${window.ship}`,
'personal',
res.ship,
true
);
setShowBanner(!groupShared);
} }
} else { setHasLoadedAllowed(true);
const groupShared = await props.api.contacts.fetchIsAllowed(
`~${window.ship}`,
'personal',
res.ship,
true
);
setShowBanner(!groupShared);
}
})(); })();
}, [groupPath]); }, [groupPath]);
@ -151,7 +154,10 @@ export function ChatResource(props: ChatResourceProps) {
history={props.history} history={props.history}
graph={graph} graph={graph}
unreadCount={unreadCount} unreadCount={unreadCount}
contacts={!showBanner ? contacts : modifiedContacts} contacts={
(!showBanner && hasLoadedAllowed) ?
contacts : modifiedContacts
}
association={props.association} association={props.association}
associations={props.associations} associations={props.associations}
groups={props.groups} groups={props.groups}
@ -166,9 +172,13 @@ export function ChatResource(props: ChatResourceProps) {
ref={chatInput} ref={chatInput}
api={props.api} api={props.api}
station={station} station={station}
ourContact={!showBanner ? ourContact : null} ourContact={
(!showBanner && hasLoadedAllowed) ? ourContact : null
}
envelopes={[]} envelopes={[]}
contacts={contacts} contacts={
(!showBanner && hasLoadedAllowed) ? contacts : modifiedContacts
}
onUnmount={appendUnsent} onUnmount={appendUnsent}
s3={props.s3} s3={props.s3}
placeholder="Message..." placeholder="Message..."