Add ability to DM from profile
This commit is contained in:
parent
be136fe6cf
commit
df2f38a60f
1 changed files with 40 additions and 27 deletions
|
@ -1,5 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
import { useMutation } from '@tanstack/react-query';
|
||||||
|
import { AxiosError } from 'axios';
|
||||||
import { List as ImmutableList } from 'immutable';
|
import { List as ImmutableList } from 'immutable';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||||
|
@ -24,6 +26,8 @@ import ActionButton from 'soapbox/features/ui/components/action-button';
|
||||||
import SubscriptionButton from 'soapbox/features/ui/components/subscription-button';
|
import SubscriptionButton from 'soapbox/features/ui/components/subscription-button';
|
||||||
import { useAppDispatch, useFeatures, useOwnAccount } from 'soapbox/hooks';
|
import { useAppDispatch, useFeatures, useOwnAccount } from 'soapbox/hooks';
|
||||||
import { normalizeAttachment } from 'soapbox/normalizers';
|
import { normalizeAttachment } from 'soapbox/normalizers';
|
||||||
|
import { ChatKeys, useChats } from 'soapbox/queries/chats';
|
||||||
|
import { queryClient } from 'soapbox/queries/client';
|
||||||
import { Account } from 'soapbox/types/entities';
|
import { Account } from 'soapbox/types/entities';
|
||||||
import { isRemote } from 'soapbox/utils/accounts';
|
import { isRemote } from 'soapbox/utils/accounts';
|
||||||
|
|
||||||
|
@ -80,6 +84,21 @@ const Header: React.FC<IHeader> = ({ account }) => {
|
||||||
const features = useFeatures();
|
const features = useFeatures();
|
||||||
const ownAccount = useOwnAccount();
|
const ownAccount = useOwnAccount();
|
||||||
|
|
||||||
|
const { getOrCreateChatByAccountId } = useChats();
|
||||||
|
|
||||||
|
const createAndNavigateToChat = useMutation((accountId: string) => {
|
||||||
|
return getOrCreateChatByAccountId(accountId);
|
||||||
|
}, {
|
||||||
|
onError: (error: AxiosError) => {
|
||||||
|
const data = error.response?.data as any;
|
||||||
|
dispatch(snackbar.error(data?.error));
|
||||||
|
},
|
||||||
|
onSuccess: (response) => {
|
||||||
|
history.push(`/chats/${response.data.id}`);
|
||||||
|
queryClient.invalidateQueries(ChatKeys.chatSearch());
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (!account) {
|
if (!account) {
|
||||||
return (
|
return (
|
||||||
<div className='-mt-4 -mx-4'>
|
<div className='-mt-4 -mx-4'>
|
||||||
|
@ -480,34 +499,28 @@ const Header: React.FC<IHeader> = ({ account }) => {
|
||||||
return info;
|
return info;
|
||||||
};
|
};
|
||||||
|
|
||||||
// const renderMessageButton = () => {
|
const renderMessageButton = () => {
|
||||||
// if (!ownAccount || !account || account.id === ownAccount?.id) {
|
if (!ownAccount || !account || account.id === ownAccount?.id) {
|
||||||
// return null;
|
return null;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// const canChat = account.getIn(['pleroma', 'accepts_chat_messages']) === true;
|
const canChat = account.relationship?.followed_by;
|
||||||
|
if (!canChat) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// if (canChat) {
|
return (
|
||||||
// return (
|
<IconButton
|
||||||
// <IconButton
|
src={require('@tabler/icons/mail.svg')}
|
||||||
// src={require('@tabler/icons/messages.svg')}
|
onClick={() => createAndNavigateToChat.mutate(account.id)}
|
||||||
// onClick={onChat}
|
title={intl.formatMessage(messages.chat, { name: account.username })}
|
||||||
// title={intl.formatMessage(messages.chat, { name: account.username })}
|
theme='outlined'
|
||||||
// />
|
className='px-2'
|
||||||
// );
|
iconClassName='w-4 h-4'
|
||||||
// } else {
|
disabled={createAndNavigateToChat.isLoading}
|
||||||
// return (
|
/>
|
||||||
// <IconButton
|
);
|
||||||
// src={require('@tabler/icons/mail.svg')}
|
};
|
||||||
// onClick={onDirect}
|
|
||||||
// title={intl.formatMessage(messages.direct, { name: account.username })}
|
|
||||||
// theme='outlined'
|
|
||||||
// className='px-2'
|
|
||||||
// iconClassName='w-4 h-4'
|
|
||||||
// />
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
const renderShareButton = () => {
|
const renderShareButton = () => {
|
||||||
const canShare = 'share' in navigator;
|
const canShare = 'share' in navigator;
|
||||||
|
@ -610,7 +623,7 @@ const Header: React.FC<IHeader> = ({ account }) => {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{renderShareButton()}
|
{renderShareButton()}
|
||||||
{/* {renderMessageButton()} */}
|
{renderMessageButton()}
|
||||||
|
|
||||||
<ActionButton account={account} />
|
<ActionButton account={account} />
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue