landscape: mentions respect calmengine

Fixes #4130.
This commit is contained in:
Matilde Park 2020-12-11 12:09:57 -05:00
parent 3662df0e73
commit 4530b59dd9
3 changed files with 27 additions and 10 deletions

View File

@ -261,6 +261,8 @@ export class MessageWithSigil extends PureComponent<MessageProps> {
measure={measure} measure={measure}
fontSize={fontSize} fontSize={fontSize}
group={group} group={group}
hideNicknames={hideNicknames}
hideAvatars={hideAvatars}
/>)} />)}
</ContentBox> </ContentBox>
</Box> </Box>
@ -276,16 +278,25 @@ const ContentBox = styled(Box)`
`; `;
export const MessageWithoutSigil = ({ timestamp, contacts, msg, remoteContentPolicy, measure, group }) => ( export const MessageWithoutSigil = ({ timestamp, contacts, msg, remoteContentPolicy, measure, group, hideNicknames, hideAvatars }) => (
<> <>
<Text flexShrink={0} mono gray display='inline-block' pt='2px' lineHeight='tall' className="child">{timestamp}</Text> <Text flexShrink={0} mono gray display='inline-block' pt='2px' lineHeight='tall' className="child">{timestamp}</Text>
<ContentBox flexShrink={0} fontSize='14px' className="clamp-message" style={{ flexGrow: 1 }}> <ContentBox flexShrink={0} fontSize='14px' className="clamp-message" style={{ flexGrow: 1 }}>
{msg.contents.map(c => (<MessageContent contacts={contacts} content={c} group={group} remoteContentPolicy={remoteContentPolicy} measure={measure}/>))} {msg.contents.map((c, i) => (
<MessageContent
key={i}
contacts={contacts}
content={c}
group={group}
remoteContentPolicy={remoteContentPolicy}
measure={measure}
hideNicknames={hideNicknames}
hideAvatars={hideAvatars}/>))}
</ContentBox> </ContentBox>
</> </>
); );
export const MessageContent = ({ content, contacts, remoteContentPolicy, measure, fontSize, group }) => { export const MessageContent = ({ content, contacts, remoteContentPolicy, measure, fontSize, group, hideNicknames, hideAvatars }) => {
if ('code' in content) { if ('code' in content) {
return <CodeContent content={content} />; return <CodeContent content={content} />;
} else if ('url' in content) { } else if ('url' in content) {
@ -314,7 +325,7 @@ export const MessageContent = ({ content, contacts, remoteContentPolicy, measure
} else if ('text' in content) { } else if ('text' in content) {
return <TextContent fontSize={fontSize} content={content} />; return <TextContent fontSize={fontSize} content={content} />;
} else if ('mention' in content) { } else if ('mention' in content) {
return <Mention group={group} ship={content.mention} contacts={contacts} /> return <Mention group={group} ship={content.mention} contacts={contacts} hideNicknames={hideNicknames} hideAvatars={hideAvatars} />
} else { } else {
return null; return null;
} }

View File

@ -82,6 +82,8 @@ export function CommentItem(props: CommentItemProps) {
group={group} group={group}
content={post?.contents} content={post?.contents}
remoteContentPolicy={remoteContentPolicy} remoteContentPolicy={remoteContentPolicy}
hideNicknames={props.hideNicknames}
hideAvatars={props.hideAvatars}
/> />
</Box> </Box>
</Box> </Box>

View File

@ -17,9 +17,11 @@ interface MentionTextProps {
content: Content[]; content: Content[];
group: Group; group: Group;
remoteContentPolicy: LocalUpdateRemoteContentPolicy; remoteContentPolicy: LocalUpdateRemoteContentPolicy;
hideNicknames: boolean;
hideAvatars: boolean;
} }
export function MentionText(props: MentionTextProps) { export function MentionText(props: MentionTextProps) {
const { content, contacts, group } = props; const { content, contacts, group, hideNicknames } = props;
return ( return (
<> <>
@ -36,7 +38,7 @@ export function MentionText(props: MentionTextProps) {
); );
} else if ("mention" in c) { } else if ("mention" in c) {
return ( return (
<Mention key={idx} contacts={contacts || {}} group={group} ship={c.mention} /> <Mention key={idx} contacts={contacts || {}} group={group} ship={c.mention} hideNicknames={hideNicknames} hideAvatars={hideAvatars} />
); );
} }
return null; return null;
@ -49,10 +51,12 @@ export function Mention(props: {
ship: string; ship: string;
contacts: Contacts; contacts: Contacts;
group: Group; group: Group;
hideNicknames: boolean;
hideAvatars: boolean;
}) { }) {
const { contacts, ship } = props; const { contacts, ship, hideNicknames, hideAvatars } = props;
const contact = contacts[ship]; const contact = contacts[ship];
const showNickname = !!contact?.nickname; const showNickname = (Boolean(contact?.nickname) && !hideNicknames);
const name = showNickname ? contact?.nickname : cite(ship); const name = showNickname ? contact?.nickname : cite(ship);
const [showOverlay, setShowOverlay] = useState(false); const [showOverlay, setShowOverlay] = useState(false);
const onDismiss = useCallback(() => { const onDismiss = useCallback(() => {
@ -79,8 +83,8 @@ export function Mention(props: {
color={`#${uxToHex(contact?.color ?? '0x0')}`} color={`#${uxToHex(contact?.color ?? '0x0')}`}
group={group} group={group}
onDismiss={onDismiss} onDismiss={onDismiss}
hideAvatars={false} hideAvatars={hideAvatars || false}
hideNicknames={false} hideNicknames={hideNicknames}
history={history} history={history}
/> />
)} )}