Skip to content

Commit

Permalink
fix the chat crash on missing pinned message
Browse files Browse the repository at this point in the history
  • Loading branch information
Tenari committed Jun 20, 2023
1 parent da67dfe commit a25d3c0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app/src/renderer/apps/Courier/components/PinnedMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const PinnedContainer = ({ message, onClick }: PinnedContainerProps) => {
const { getOptions, setOptions } = useContextMenu();
const [authorColor, setAuthorColor] = useState<string | undefined>();

const pinnedRowId = useMemo(() => `pinned-${message.id}`, [message.id]);
const pinnedRowId = useMemo(() => `pinned-${message?.id}`, [message?.id]);
const contextMenuOptions = useMemo(() => {
const menu: MenuItemProps[] = [];
if (!selectedChat || !loggedInAccount) return menu;
Expand All @@ -69,7 +69,7 @@ export const PinnedContainer = ({ message, onClick }: PinnedContainerProps) => {
disabled: false,
onClick: (evt: React.MouseEvent<HTMLDivElement>) => {
evt.stopPropagation();
selectedChat.clearPinnedMessage(message.id);
selectedChat.clearPinnedMessage(message?.id);
},
});
}
Expand All @@ -83,16 +83,17 @@ export const PinnedContainer = ({ message, onClick }: PinnedContainerProps) => {
}, [contextMenuOptions, getOptions, setOptions, pinnedRowId]);

useEffect(() => {
const contact = friends.getContactAvatarMetadata(message.sender);
const contact = friends.getContactAvatarMetadata(message?.sender);
// NOTE: #000 is the default color, so we want to default to undefined
// and use the accent color instead
const authorColorDisplay =
(contact.color && flipColorIfLowContrast(contact.color, theme.mode)) ||
'rgba(var(--rlm-text-rgba))';

setAuthorColor(authorColorDisplay);
}, [message.sender]);
}, [message?.sender]);

if (!message) return null;
return (
<Flex
width="100%"
Expand Down

0 comments on commit a25d3c0

Please sign in to comment.