Merge pull request #4432 from urbit/la/fix-363

interface: profiles would intermittently show contact information when they should not, fixes this
This commit is contained in:
matildepark 2021-02-12 14:21:32 -05:00 committed by GitHub
commit 73c0c7c2fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 43 deletions

View File

@ -59,18 +59,16 @@ const edit = (json: ContactUpdate, state: S) => {
if (!field) { if (!field) {
return; return;
} }
const contact = state.contacts?.[ship];
const value = data['edit-field'][field]; const value = data['edit-field'][field];
if(!contact) {
return;
}
if(field === 'add-group') { if(field === 'add-group') {
contact.groups.push(value); state.contacts[ship].groups.push(value);
} else if (field === 'remove-group') { } else if (field === 'remove-group') {
contact.groups = contact.groups.filter(g => g !== value); state.contacts[ship].groups =
state.contacts[ship].groups.filter(g => g !== value);
} else { } else {
contact[field] = value; state.contacts[ship][field] = value;
} }
} }
}; };

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..."