From 1c4baea62f66bbf353bb69038801b7e98ad10e21 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Fri, 12 Feb 2021 11:48:50 -0600 Subject: [PATCH 1/2] interface: profiles would intermittently show contact information when they should not, fixes this --- .../src/views/apps/chat/ChatResource.tsx | 82 +++++++++++-------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/pkg/interface/src/views/apps/chat/ChatResource.tsx b/pkg/interface/src/views/apps/chat/ChatResource.tsx index 5e8a35e95..6b47a4409 100644 --- a/pkg/interface/src/views/apps/chat/ChatResource.tsx +++ b/pkg/interface/src/views/apps/chat/ChatResource.tsx @@ -80,49 +80,52 @@ export function ChatResource(props: ChatResourceProps) { }, [station]); const [showBanner, setShowBanner] = useState(false); + const [hasLoadedAllowed, setHasLoadedAllowed] = useState(false); const [recipients, setRecipients] = useState([]); const res = resourceFromPath(groupPath); useEffect(() => { (async () => { - if (!res) { return; } - if (!group) { return; } - if (group.hidden) { - 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 (!res) { return; } + if (!group) { return; } + if (group.hidden) { + 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); + } - if(members.length > 0) { - setShowBanner(true); - setRecipients(members); } else { - setShowBanner(false); + const groupShared = await props.api.contacts.fetchIsAllowed( + `~${window.ship}`, + 'personal', + res.ship, + true + ); + setShowBanner(!groupShared); } - } else { - const groupShared = await props.api.contacts.fetchIsAllowed( - `~${window.ship}`, - 'personal', - res.ship, - true - ); - setShowBanner(!groupShared); - } + setHasLoadedAllowed(true); })(); }, [groupPath]); @@ -151,7 +154,10 @@ export function ChatResource(props: ChatResourceProps) { history={props.history} graph={graph} unreadCount={unreadCount} - contacts={!showBanner ? contacts : modifiedContacts} + contacts={ + (!showBanner && hasLoadedAllowed) ? + contacts : modifiedContacts + } association={props.association} associations={props.associations} groups={props.groups} @@ -166,9 +172,13 @@ export function ChatResource(props: ChatResourceProps) { ref={chatInput} api={props.api} station={station} - ourContact={!showBanner ? ourContact : null} + ourContact={ + (!showBanner && hasLoadedAllowed) ? ourContact : null + } envelopes={[]} - contacts={contacts} + contacts={ + (!showBanner && hasLoadedAllowed) ? contacts : modifiedContacts + } onUnmount={appendUnsent} s3={props.s3} placeholder="Message..." From 144178165c98ec7866d91850205c2967cbceff57 Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Fri, 12 Feb 2021 12:02:52 -0600 Subject: [PATCH 2/2] interface: simplify edit reducer --- pkg/interface/src/logic/reducers/contact-update.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/interface/src/logic/reducers/contact-update.ts b/pkg/interface/src/logic/reducers/contact-update.ts index 44cbc6cfb..932852ece 100644 --- a/pkg/interface/src/logic/reducers/contact-update.ts +++ b/pkg/interface/src/logic/reducers/contact-update.ts @@ -59,18 +59,16 @@ const edit = (json: ContactUpdate, state: S) => { if (!field) { return; } - const contact = state.contacts?.[ship]; + const value = data['edit-field'][field]; - if(!contact) { - return; - } if(field === 'add-group') { - contact.groups.push(value); + state.contacts[ship].groups.push(value); } 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 { - contact[field] = value; + state.contacts[ship][field] = value; } } };