gab-social/app/javascript/gabsocial/components/notification.js

162 lines
5.3 KiB
JavaScript
Raw Normal View History

2020-03-04 03:45:16 +00:00
import { NavLink } from 'react-router-dom'
import { injectIntl, defineMessages } from 'react-intl'
2020-03-02 22:26:25 +00:00
import ImmutablePureComponent from 'react-immutable-pure-component'
import { HotKeys } from 'react-hotkeys'
import ImmutablePropTypes from 'react-immutable-proptypes'
2020-05-01 06:50:27 +01:00
import { me } from '../initial_state'
2020-04-24 04:17:27 +01:00
import StatusContainer from '../containers/status_container'
import Avatar from './avatar'
import Icon from './icon'
import Text from './text'
import DisplayName from './display_name'
2020-03-04 03:45:16 +00:00
const messages = defineMessages({
2020-04-03 02:05:49 +01:00
poll: { id: 'notification.poll', defaultMessage: 'A poll you have voted in has ended' },
2020-05-01 06:50:27 +01:00
ownPoll: { id: 'notification.own_poll', defaultMessage: 'Your poll has ended' },
2020-04-03 02:05:49 +01:00
mentionedInPost: { id: 'mentioned_in_post', defaultMessage: 'mentioned you in their post' },
mentionedInComment: { id: 'mentioned_in_comment', defaultMessage: 'mentioned you in their comment' },
followedYouOne: { id: 'followed_you_one', defaultMessage: 'followed you' },
followedYouMultiple: { id: 'followed_you_multiple', defaultMessage: 'and {count} others followed you' },
likedStatusOne: { id: 'liked_status_one', defaultMessage: 'liked your status' },
likedStatusMultiple: { id: 'liked_status_multiple', defaultMessage: 'and {count} others liked your status' },
repostedStatusOne: { id: 'reposted_status_one', defaultMessage: 'reposted your status' },
repostedStatusMultiple: { id: 'reposted_status_multiple', defaultMessage: 'and {count} others reposted your status' },
2020-03-04 03:45:16 +00:00
})
2020-03-02 22:26:25 +00:00
2020-05-01 06:50:27 +01:00
// : todo :
2020-03-02 22:26:25 +00:00
const notificationForScreenReader = (intl, message, timestamp) => {
const output = [message]
output.push(intl.formatDate(timestamp, { hour: '2-digit', minute: '2-digit', month: 'short', day: 'numeric' }))
return output.join(', ')
}
export default
@injectIntl
class Notification extends ImmutablePureComponent {
static contextTypes = {
router: PropTypes.object,
}
static propTypes = {
intl: PropTypes.object.isRequired,
2020-04-03 02:05:49 +01:00
accounts: ImmutablePropTypes.list.isRequired,
createdAt: PropTypes.string,
statusId: PropTypes.string,
type: PropTypes.string.isRequired,
2020-04-28 06:33:58 +01:00
isHidden: PropTypes.bool,
2020-03-02 22:26:25 +00:00
}
2020-04-11 23:29:19 +01:00
render() {
2020-04-28 06:33:58 +01:00
const {
intl,
accounts,
createdAt,
type,
statusId,
isHidden,
} = this.props
2020-04-11 23:29:19 +01:00
const count = !!accounts ? accounts.size : 0
2020-04-03 02:05:49 +01:00
2020-04-11 23:29:19 +01:00
let message
let icon
switch (type) {
case 'follow':
icon = 'group'
message = intl.formatMessage(count > 1 ? messages.followedYouMultiple : messages.followedYouOne, {
count: count - 1,
})
break
case 'mention':
icon = 'comment'
message = intl.formatMessage(messages.mentionedInPost)
break
case 'like':
icon = 'like'
message = intl.formatMessage(count > 1 ? messages.likedStatusMultiple : messages.likedStatusOne, {
count: count - 1,
})
break
case 'repost':
icon = 'repost'
message = intl.formatMessage(count > 1 ? messages.repostedStatusMultiple : messages.repostedStatusOne, {
count: count - 1,
})
break
case 'poll':
2020-05-01 06:50:27 +01:00
let msg = messages.poll
if (accounts.size === 1) {
if (accounts.first().get('id') === me) {
msg = messages.ownPoll
}
}
2020-04-11 23:29:19 +01:00
icon = 'poll'
2020-05-01 06:50:27 +01:00
message = intl.formatMessage(msg)
2020-04-11 23:29:19 +01:00
break
default:
return null
}
2020-04-03 02:05:49 +01:00
2020-04-28 06:33:58 +01:00
if (isHidden) {
// : todo :
}
2020-04-03 02:05:49 +01:00
return (
2020-04-29 23:32:49 +01:00
<div className={[_s.default, _s.px10, _s.cursorPointer, _s.bgSubtle_onHover].join(' ')}>
2020-04-03 02:05:49 +01:00
<div className={[_s.default, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}>
<div className={[_s.default, _s.flexRow, _s.my10, _s.py10, _s.px10].join(' ')}>
2020-03-04 03:45:16 +00:00
2020-04-29 23:32:49 +01:00
<Icon id={icon} size='20px' className={[_s.fillPrimary, _s.mt5].join(' ')} />
2020-04-03 02:05:49 +01:00
2020-04-11 23:29:19 +01:00
<div className={[_s.default, _s.ml15, _s.flexNormal].join(' ')}>
2020-04-03 02:05:49 +01:00
<div className={[_s.default, _s.flexRow].join(' ')}>
{
accounts.slice(0, 8).map((account, i) => (
<NavLink
to={`/${account.get('acct')}`}
key={`fav-avatar-${i}`}
className={_s.mr5}
>
2020-04-11 23:29:19 +01:00
<Avatar size={30} account={account} />
2020-04-03 02:05:49 +01:00
</NavLink>
))
}
</div>
2020-03-11 23:56:18 +00:00
<div className={[_s.default, _s.pt10].join(' ')}>
2020-04-03 02:05:49 +01:00
<div className={[_s.default, _s.flexRow].join(' ')}>
<div className={_s.text}>
{
accounts.slice(0, 1).map((account, i) => (
<DisplayName key={i} account={account} noUsername />
))
}
</div>
<Text size='medium'>
{' '}
2020-04-11 23:29:19 +01:00
{message}
2020-04-03 02:05:49 +01:00
</Text>
</div>
</div>
2020-04-11 23:29:19 +01:00
{
!!statusId &&
<div className={[_s.default, _s.pt10, _s.mt5].join(' ')}>
<StatusContainer
2020-05-05 06:16:01 +01:00
contextType='notification'
2020-04-11 23:29:19 +01:00
id={statusId}
isChild
/>
2020-03-04 03:45:16 +00:00
</div>
2020-04-11 23:29:19 +01:00
}
2020-03-04 03:45:16 +00:00
</div>
2020-03-02 22:26:25 +00:00
2020-03-04 03:45:16 +00:00
</div>
</div>
2020-04-03 02:05:49 +01:00
</div>
2020-03-04 03:45:16 +00:00
)
2020-03-02 22:26:25 +00:00
}
}