2018-03-12 20:57:28 -04:00
|
|
|
// Package imports.
|
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 10:38:10 -04:00
|
|
|
import { PureComponent } from 'react';
|
|
|
|
|
2018-03-12 20:57:28 -04:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
|
2023-05-28 10:38:10 -04:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
|
2024-01-16 05:27:26 -05:00
|
|
|
import ForumIcon from '@/material-icons/400-24px/forum.svg?react';
|
|
|
|
import HomeIcon from '@/material-icons/400-24px/home.svg?react';
|
|
|
|
import ImageIcon from '@/material-icons/400-24px/image.svg?react';
|
|
|
|
import InsertChartIcon from '@/material-icons/400-24px/insert_chart.svg?react';
|
|
|
|
import LinkIcon from '@/material-icons/400-24px/link.svg?react';
|
|
|
|
import MovieIcon from '@/material-icons/400-24px/movie.svg?react';
|
|
|
|
import MusicNoteIcon from '@/material-icons/400-24px/music_note.svg?react';
|
2023-05-08 21:11:56 -04:00
|
|
|
import { Icon } from 'flavours/glitch/components/icon';
|
2022-10-11 04:17:04 -04:00
|
|
|
import { languages } from 'flavours/glitch/initial_state';
|
2024-01-12 15:16:48 -05:00
|
|
|
|
2024-02-20 12:49:59 -05:00
|
|
|
import { CollapseButton } from './collapse_button';
|
2023-10-24 13:45:08 -04:00
|
|
|
import { VisibilityIcon } from './visibility_icon';
|
2023-05-28 10:38:10 -04:00
|
|
|
|
2018-03-12 20:57:28 -04:00
|
|
|
const messages = defineMessages({
|
|
|
|
collapse: { id: 'status.collapse', defaultMessage: 'Collapse' },
|
|
|
|
uncollapse: { id: 'status.uncollapse', defaultMessage: 'Uncollapse' },
|
2019-07-16 09:06:30 -04:00
|
|
|
inReplyTo: { id: 'status.in_reply_to', defaultMessage: 'This toot is a reply' },
|
2019-07-16 09:23:39 -04:00
|
|
|
previewCard: { id: 'status.has_preview_card', defaultMessage: 'Features an attached preview card' },
|
|
|
|
pictures: { id: 'status.has_pictures', defaultMessage: 'Features attached pictures' },
|
2019-07-16 09:06:30 -04:00
|
|
|
poll: { id: 'status.is_poll', defaultMessage: 'This toot is a poll' },
|
2019-07-16 09:23:39 -04:00
|
|
|
video: { id: 'status.has_video', defaultMessage: 'Features attached videos' },
|
|
|
|
audio: { id: 'status.has_audio', defaultMessage: 'Features attached audio files' },
|
|
|
|
localOnly: { id: 'status.local_only', defaultMessage: 'Only visible from your instance' },
|
2018-03-12 20:57:28 -04:00
|
|
|
});
|
|
|
|
|
2022-05-27 10:34:29 -04:00
|
|
|
const LanguageIcon = ({ language }) => {
|
|
|
|
if (!languages) return null;
|
|
|
|
|
|
|
|
const lang = languages.find((lang) => lang[0] === language);
|
|
|
|
if (!lang) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className='text-icon' title={`${lang[2]} (${lang[1]})`} aria-hidden='true'>
|
|
|
|
{lang[0].toUpperCase()}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
LanguageIcon.propTypes = {
|
|
|
|
language: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
2023-05-28 08:18:23 -04:00
|
|
|
class StatusIcons extends PureComponent {
|
2018-03-12 20:57:28 -04:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
status: ImmutablePropTypes.map.isRequired,
|
2021-09-08 08:39:14 -04:00
|
|
|
mediaIcons: PropTypes.arrayOf(PropTypes.string),
|
2018-03-12 20:57:28 -04:00
|
|
|
collapsible: PropTypes.bool,
|
|
|
|
collapsed: PropTypes.bool,
|
2018-03-28 09:40:34 -04:00
|
|
|
setCollapsed: PropTypes.func.isRequired,
|
2018-03-12 20:57:28 -04:00
|
|
|
intl: PropTypes.object.isRequired,
|
2022-05-27 10:34:29 -04:00
|
|
|
settings: ImmutablePropTypes.map.isRequired,
|
2018-03-12 20:57:28 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Handles clicks on collapsed button
|
|
|
|
handleCollapsedClick = (e) => {
|
2018-03-28 09:40:34 -04:00
|
|
|
const { collapsed, setCollapsed } = this.props;
|
2018-03-12 20:57:28 -04:00
|
|
|
if (e.button === 0) {
|
2018-03-28 09:40:34 -04:00
|
|
|
setCollapsed(!collapsed);
|
2018-03-12 20:57:28 -04:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
2023-02-03 14:52:07 -05:00
|
|
|
};
|
2018-03-12 20:57:28 -04:00
|
|
|
|
2024-01-13 17:35:53 -05:00
|
|
|
renderIcon (mediaIcon) {
|
2021-09-08 08:39:14 -04:00
|
|
|
const { intl } = this.props;
|
2019-07-16 09:06:30 -04:00
|
|
|
|
2024-01-13 17:35:53 -05:00
|
|
|
let title, iconComponent;
|
|
|
|
|
|
|
|
switch (mediaIcon) {
|
|
|
|
case 'link':
|
|
|
|
title = messages.previewCard;
|
|
|
|
iconComponent = LinkIcon;
|
|
|
|
break;
|
|
|
|
case 'picture-o':
|
|
|
|
title = messages.pictures;
|
|
|
|
iconComponent = ImageIcon;
|
|
|
|
break;
|
|
|
|
case 'tasks':
|
|
|
|
title = messages.poll;
|
|
|
|
iconComponent = InsertChartIcon;
|
|
|
|
break;
|
|
|
|
case 'video-camera':
|
|
|
|
title = messages.video;
|
|
|
|
iconComponent = MovieIcon;
|
|
|
|
break;
|
|
|
|
case 'music':
|
|
|
|
title = messages.audio;
|
|
|
|
iconComponent = MusicNoteIcon;
|
|
|
|
break;
|
|
|
|
}
|
2019-07-16 09:06:30 -04:00
|
|
|
|
2021-09-08 08:39:14 -04:00
|
|
|
return (
|
|
|
|
<Icon
|
|
|
|
fixedWidth
|
|
|
|
className='status__media-icon'
|
|
|
|
key={`media-icon--${mediaIcon}`}
|
|
|
|
id={mediaIcon}
|
2024-01-13 17:35:53 -05:00
|
|
|
icon={iconComponent}
|
2021-09-08 08:39:14 -04:00
|
|
|
aria-hidden='true'
|
2024-01-13 17:35:53 -05:00
|
|
|
title={title && intl.formatMessage(title)}
|
2021-09-08 08:39:14 -04:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-03-12 20:57:28 -04:00
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
status,
|
2021-09-08 08:39:14 -04:00
|
|
|
mediaIcons,
|
2018-03-12 20:57:28 -04:00
|
|
|
collapsible,
|
|
|
|
collapsed,
|
2024-02-20 12:49:59 -05:00
|
|
|
setCollapsed,
|
2022-05-27 10:34:29 -04:00
|
|
|
settings,
|
2018-03-12 20:57:28 -04:00
|
|
|
intl,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='status__info__icons'>
|
2022-05-27 10:34:29 -04:00
|
|
|
{settings.get('language') && status.get('language') && <LanguageIcon language={status.get('language')} />}
|
|
|
|
{settings.get('reply') && status.get('in_reply_to_id', null) !== null ? (
|
2019-09-09 10:41:41 -04:00
|
|
|
<Icon
|
|
|
|
className='status__reply-icon'
|
|
|
|
id='comment'
|
2023-10-24 13:45:08 -04:00
|
|
|
icon={ForumIcon}
|
2018-05-08 01:10:34 -04:00
|
|
|
aria-hidden='true'
|
2019-07-16 09:06:30 -04:00
|
|
|
title={intl.formatMessage(messages.inReplyTo)}
|
2018-05-08 01:10:34 -04:00
|
|
|
/>
|
|
|
|
) : null}
|
2022-05-27 10:34:29 -04:00
|
|
|
{settings.get('local_only') && status.get('local_only') &&
|
2019-09-09 10:41:41 -04:00
|
|
|
<Icon
|
|
|
|
id='home'
|
2023-10-24 13:45:08 -04:00
|
|
|
icon={HomeIcon}
|
2019-07-16 09:08:03 -04:00
|
|
|
aria-hidden='true'
|
|
|
|
title={intl.formatMessage(messages.localOnly)}
|
|
|
|
/>}
|
2022-05-27 10:34:29 -04:00
|
|
|
{settings.get('media') && !!mediaIcons && mediaIcons.map(icon => this.renderIcon(icon))}
|
2022-05-30 11:10:13 -04:00
|
|
|
{settings.get('visibility') && <VisibilityIcon visibility={status.get('visibility')} />}
|
2024-02-20 12:49:59 -05:00
|
|
|
{collapsible && <CollapseButton collapsed={collapsed} setCollapsed={setCollapsed} />}
|
2018-03-12 20:57:28 -04:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 18:15:25 -04:00
|
|
|
|
|
|
|
export default injectIntl(StatusIcons);
|