DMs: reply functionality with blockquotes

Fixes urbit/landscape#932
This commit is contained in:
Liam Fitzgerald 2021-06-03 11:05:39 +10:00
parent 00aeb6c17c
commit ecdfa36fe4
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
3 changed files with 45 additions and 13 deletions

View File

@ -1,5 +1,6 @@
import { cite, Content } from '@urbit/api';
import { cite, Content, Post } from '@urbit/api';
import React, { useCallback, useEffect } from 'react';
import _ from 'lodash';
import bigInt from 'big-integer';
import { Box, Row, Col, Text } from '@tlon/indigo-react';
import { Link } from 'react-router-dom';
@ -27,6 +28,27 @@ const getCurrDmSize = (ship: string) => {
return shipGraph?.children?.size ?? 0;
};
function quoteReply(post: Post) {
const reply = _.reduce(
post.contents,
(acc, content) => {
if ('text' in content) {
return `${acc}${content.text}`;
} else if ('url' in content) {
return `${acc}${content.url}`;
} else if ('mention' in content) {
return `${acc}${content.mention}`;
}
return acc;
},
''
)
.split('\n')
.map(l => `> ${l}`)
.join('\n');
return `${reply}\n\n~${post.author}:`;
}
export function DmResource(props: DmResourceProps) {
const { ship, api } = props;
const dm = useDM(ship);
@ -38,7 +60,12 @@ export function DmResource(props: DmResourceProps) {
const nickname = showNickname ? contact!.nickname : cite(ship) ?? ship;
useEffect(() => {
api.graph.getNewest(`~${window.ship}`, 'dm-inbox', 100, `/${patpToUd(ship)}`);
api.graph.getNewest(
`~${window.ship}`,
'dm-inbox',
100,
`/${patpToUd(ship)}`
);
}, [ship]);
const fetchMessages = useCallback(
@ -75,7 +102,10 @@ export function DmResource(props: DmResourceProps) {
);
const dismissUnread = useCallback(() => {
api.hark.dismissReadCount(`/ship/~${window.ship}/dm-inbox`, `/${patp2dec(ship)}`);
api.hark.dismissReadCount(
`/ship/~${window.ship}/dm-inbox`,
`/${patp2dec(ship)}`
);
}, [ship]);
const onSubmit = useCallback(
@ -99,13 +129,13 @@ export function DmResource(props: DmResourceProps) {
<Row alignItems="baseline">
<Box
borderRight={1}
borderRightColor='gray'
borderRightColor="gray"
pr={3}
fontSize={1}
mr={3}
my={1}
flexShrink={0}
display={['block','none']}
display={['block', 'none']}
>
<Link to={'/~landscape/messages'}>
<Text>{'<- Back'}</Text>
@ -131,10 +161,10 @@ export function DmResource(props: DmResourceProps) {
id={ship}
graph={dm}
unreadCount={unreadCount}
onReply={() => ''}
onReply={quoteReply}
fetchMessages={fetchMessages}
dismissUnread={dismissUnread}
getPermalink={() => ''}
getPermalink={() => undefined}
isAdmin
onSubmit={onSubmit}
/>

View File

@ -329,9 +329,11 @@ const MessageActions = ({ onReply, onDelete, msg, isAdmin, permalink }) => {
<MessageActionItem onClick={() => onReply(msg)}>
Reply
</MessageActionItem>
<MessageActionItem onClick={doCopy}>
{copyDisplay}
</MessageActionItem>
{permalink ? (
<MessageActionItem onClick={doCopy}>
{copyDisplay}
</MessageActionItem>
) : null }
{(isAdmin || isOwn()) ? (
<MessageActionItem onClick={e => onDelete(msg)} color='red'>
Delete Message

View File

@ -25,7 +25,7 @@ type ChatWindowProps = {
dismissUnread: () => void;
pendingSize?: number;
showOurContact: boolean;
getPermalink: (index: BigInteger) => string;
getPermalink: (index: BigInteger) => string | undefined;
isAdmin: boolean;
};
@ -208,7 +208,7 @@ class ChatWindow extends Component<
This message has been deleted.
</Text>
);
};
}
if (!this.state.initialized) {
return (
<MessagePlaceholder
@ -239,7 +239,7 @@ class ChatWindow extends Component<
};
return (
// @ts-ignore
// @ts-ignore virt typings
<ChatMessage
key={index.toString()}
ref={ref}