mirror of
https://github.com/owncast/owncast.git
synced 2024-12-23 01:31:10 +03:00
084a01fb02
* ActivityPub admin pages for configuration * Fix dev build * Add support for requiring follow approval. Closes https://github.com/owncast/owncast/issues/1208 * Point at admin version of followers endpoint * Add setting for toggling displaying fediverse engagement in admin. https://github.com/owncast/owncast/issues/1404 * Add instance URL textfield to federation config and disable federation if it is empty * If instance URL is not https disable federation * Tweak federation toggle text. Make go live message optional * Add federation info modal. Closes https://github.com/owncast/owncast/issues/1544 * Add support for blocked federated domains. For https://github.com/owncast/owncast/issues/1209 * Simplify fediverse post input * Add placeholder Fediverse icon * Tweak federation logo in admin menu. Closes https://github.com/owncast/owncast/issues/1603 * Add global button for composing a fediverse post. Closes https://github.com/owncast/owncast/issues/1610 * Federation -> Social * Add page for listing federated actions. Closes https://github.com/owncast/owncast/issues/1573 * Auto-close social post modal after success * Make user modal action buttons look nicer * Center and reduce width and center count column. Closes https://github.com/owncast/owncast/issues/1580 * Update the followers table to be clearer * Fix exception thrown when passing undefined * Disable federation settings if feature is disabled * Update enable social modal. For https://github.com/owncast/owncast/issues/1594 * Fix type props * Quiet, linter * Move compose button to the left * Add tooltip for compose button * Add NSFW toggle to federation config. Closes https://github.com/owncast/owncast/issues/1628 * Add support for blocking/removing followers. For https://github.com/owncast/owncast/issues/1630 * Allow editing the server url field even when federation is disabled * Continue to update the copy around the social features * Use relative path to action images. Fixes https://github.com/owncast/owncast/issues/1646 * Link IRIs and make action verbse present tense * Update caniuse
151 lines
4.9 KiB
TypeScript
151 lines
4.9 KiB
TypeScript
// This displays a clickable user name (or whatever children element you provide), and displays a simple tooltip of created time. OnClick a modal with more information about the user is displayed.
|
|
|
|
import { useState, ReactNode } from 'react';
|
|
import { Divider, Modal, Tooltip, Typography, Row, Col, Space } from 'antd';
|
|
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
|
|
import format from 'date-fns/format';
|
|
import { uniq } from 'lodash';
|
|
|
|
import BlockUserbutton from './ban-user-button';
|
|
import ModeratorUserbutton from './moderator-user-button';
|
|
|
|
import { User, UserConnectionInfo } from '../types/chat';
|
|
import { formatDisplayDate } from './user-table';
|
|
import { formatUAstring } from '../utils/format';
|
|
|
|
interface UserPopoverProps {
|
|
user: User;
|
|
connectionInfo?: UserConnectionInfo | null;
|
|
children: ReactNode;
|
|
}
|
|
|
|
export default function UserPopover({ user, connectionInfo, children }: UserPopoverProps) {
|
|
const [isModalVisible, setIsModalVisible] = useState(false);
|
|
const handleShowModal = () => {
|
|
setIsModalVisible(true);
|
|
};
|
|
const handleCloseModal = () => {
|
|
setIsModalVisible(false);
|
|
};
|
|
|
|
const { displayName, createdAt, previousNames, nameChangedAt, disabledAt } = user;
|
|
const { connectedAt, messageCount, userAgent } = connectionInfo || {};
|
|
|
|
let lastNameChangeDate = null;
|
|
const nameList = previousNames && [...previousNames];
|
|
|
|
if (previousNames && previousNames.length > 1 && nameChangedAt) {
|
|
lastNameChangeDate = new Date(nameChangedAt);
|
|
// reverse prev names for display purposes
|
|
nameList.reverse();
|
|
}
|
|
|
|
const dateObject = new Date(createdAt);
|
|
const createdAtDate = format(dateObject, 'PP pp');
|
|
|
|
const lastNameChangeDuration = lastNameChangeDate
|
|
? formatDistanceToNow(lastNameChangeDate)
|
|
: null;
|
|
|
|
return (
|
|
<>
|
|
<Tooltip
|
|
title={
|
|
<>
|
|
Created at: {createdAtDate}.
|
|
<br /> Click for more info.
|
|
</>
|
|
}
|
|
placement="bottomLeft"
|
|
>
|
|
<button
|
|
type="button"
|
|
aria-label="Display more details about this user"
|
|
className="user-item-container"
|
|
onClick={handleShowModal}
|
|
>
|
|
{children}
|
|
</button>
|
|
</Tooltip>
|
|
|
|
<Modal
|
|
destroyOnClose
|
|
width={600}
|
|
cancelText="Close"
|
|
okButtonProps={{ style: { display: 'none' } }}
|
|
title={`User details: ${displayName}`}
|
|
visible={isModalVisible}
|
|
onOk={handleCloseModal}
|
|
onCancel={handleCloseModal}
|
|
>
|
|
<div className="user-details">
|
|
<Typography.Title level={4}>{displayName}</Typography.Title>
|
|
<p className="created-at">User created at {createdAtDate}.</p>
|
|
<Row gutter={16}>
|
|
{connectionInfo && (
|
|
<Col md={lastNameChangeDate ? 12 : 24}>
|
|
<Typography.Title level={5}>
|
|
This user is currently connected to Chat.
|
|
</Typography.Title>
|
|
<ul className="connection-info">
|
|
<li>
|
|
<strong>Active for:</strong> {formatDistanceToNow(new Date(connectedAt))}
|
|
</li>
|
|
<li>
|
|
<strong>Messages sent:</strong> {messageCount}
|
|
</li>
|
|
<li>
|
|
<strong>User Agent:</strong>
|
|
<br />
|
|
{formatUAstring(userAgent)}
|
|
</li>
|
|
</ul>
|
|
</Col>
|
|
)}
|
|
{lastNameChangeDate && (
|
|
<Col md={connectionInfo ? 12 : 24}>
|
|
<Typography.Title level={5}>This user is also seen as:</Typography.Title>
|
|
<ul className="previous-names-list">
|
|
{uniq(nameList).map((name, index) => (
|
|
<li className={index === 0 ? 'latest' : ''}>
|
|
<span className="user-name-item">{name}</span>
|
|
{index === 0 ? ` (Changed ${lastNameChangeDuration} ago)` : ''}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</Col>
|
|
)}
|
|
</Row>
|
|
<Divider />
|
|
<Space direction="horizontal">
|
|
{disabledAt ? (
|
|
<>
|
|
This user was banned on <code>{formatDisplayDate(disabledAt)}</code>.
|
|
<br />
|
|
<br />
|
|
<BlockUserbutton
|
|
label="Unban this user"
|
|
user={user}
|
|
isEnabled={false}
|
|
onClick={handleCloseModal}
|
|
/>
|
|
</>
|
|
) : (
|
|
<BlockUserbutton
|
|
label="Ban this user"
|
|
user={user}
|
|
isEnabled
|
|
onClick={handleCloseModal}
|
|
/>
|
|
)}
|
|
<ModeratorUserbutton user={user} onClick={handleCloseModal} />
|
|
</Space>
|
|
</div>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|
|
|
|
UserPopover.defaultProps = {
|
|
connectionInfo: null,
|
|
};
|