mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-09-21 07:28:30 +03:00
parent
00aeb6c17c
commit
ecdfa36fe4
@ -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}
|
||||
/>
|
||||
|
@ -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
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user