From 70866fb7c51d001ad4eba069b4e4302b05620dfd Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Mon, 15 Mar 2021 12:46:01 -0500 Subject: [PATCH 1/2] interface: only display our contact when appropriate --- pkg/interface/src/views/apps/chat/ChatResource.tsx | 11 +---------- .../src/views/apps/chat/components/ChatMessage.tsx | 9 ++++++++- .../src/views/apps/chat/components/ChatWindow.tsx | 14 ++++++++++---- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pkg/interface/src/views/apps/chat/ChatResource.tsx b/pkg/interface/src/views/apps/chat/ChatResource.tsx index 8e3aa063e..66ef13b30 100644 --- a/pkg/interface/src/views/apps/chat/ChatResource.tsx +++ b/pkg/interface/src/views/apps/chat/ChatResource.tsx @@ -139,9 +139,6 @@ export function ChatResource(props: ChatResourceProps) { return ; } - const modifiedContacts = { ...contacts }; - delete modifiedContacts[`~${window.ship}`]; - return ( { history, api, highlighted, + showOurContact, fontSize } = this.props; @@ -295,6 +296,7 @@ class ChatMessage extends Component { style, containerClass, isPending, + showOurContact, history, api, scrollWindow, @@ -355,6 +357,7 @@ export const MessageAuthor = ({ api, history, scrollWindow, + showOurContact, ...rest }) => { const osDark = useLocalState((state) => state.dark); @@ -367,7 +370,11 @@ export const MessageAuthor = ({ .unix(msg['time-sent'] / 1000) .format(DATESTAMP_FORMAT); const contact = - `~${msg.author}` in contacts ? contacts[`~${msg.author}`] : false; + ( ( (msg.author === window.ship && showOurContact) || + msg.author !== window.ship) && + `~${msg.author}` in contacts + ) ? contacts[`~${msg.author}`] : false; + const showNickname = useShowNickname(contact); const { hideAvatars } = useSettingsState(selectCalmState); const shipName = showNickname ? contact.nickname : cite(msg.author); diff --git a/pkg/interface/src/views/apps/chat/components/ChatWindow.tsx b/pkg/interface/src/views/apps/chat/components/ChatWindow.tsx index 00fa30140..c7adc7001 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatWindow.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatWindow.tsx @@ -209,7 +209,7 @@ class ChatWindow extends Component< api, association, group, - contacts, + showOurContact, graph, history, groups, @@ -219,13 +219,14 @@ class ChatWindow extends Component< const messageProps = { association, group, - contacts, + showOurContact, unreadMarkerRef, history, api, groups, associations }; + const msg = graph.get(index)?.post; if (!msg) return null; if (!this.state.initialized) { @@ -256,6 +257,7 @@ class ChatWindow extends Component< msg, ...messageProps }; + return ( Date: Mon, 15 Mar 2021 15:21:02 -0500 Subject: [PATCH 2/2] interface: add a comment to document this hack --- pkg/interface/src/views/apps/chat/components/ChatWindow.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/interface/src/views/apps/chat/components/ChatWindow.tsx b/pkg/interface/src/views/apps/chat/components/ChatWindow.tsx index c7adc7001..5a20cbf9e 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatWindow.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatWindow.tsx @@ -295,6 +295,7 @@ class ChatWindow extends Component< const unreadIndex = graph.keys()[this.props.unreadCount]; const unreadMsg = unreadIndex && graph.get(unreadIndex); + // hack to force a re-render when we toggle showing contact const contactsModified = showOurContact ? 0 : 100;