about summary refs log tree commit diff
path: root/app/assets/javascripts/components/features/notifications/components/notification.jsx
blob: 0607466d093d3c9f4597ce1e0ea69885ca511d87 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import PureRenderMixin from 'react-addons-pure-render-mixin';
import ImmutablePropTypes from 'react-immutable-proptypes';
import StatusContainer from '../../../containers/status_container';
import AccountContainer from '../../../containers/account_container';
import { FormattedMessage } from 'react-intl';
import Permalink from '../../../components/permalink';
import emojify from '../../../emoji';
import escapeTextContentForBrowser from 'escape-html';

const linkStyle = {
  fontWeight: '500'
};

const Notification = React.createClass({

  propTypes: {
    notification: ImmutablePropTypes.map.isRequired
  },

  mixins: [PureRenderMixin],

  renderFollow (account, link) {
    return (
      <div className='notification notification-follow'>
        <div className='notification__message'>
          <div style={{ position: 'absolute', 'left': '-26px'}}>
            <i className='fa fa-fw fa-user-plus' />
          </div>

          <FormattedMessage id='notification.follow' defaultMessage='{name} followed you' values={{ name: link }} />
        </div>

        <AccountContainer id={account.get('id')} withNote={false} />
      </div>
    );
  },

  renderMention (notification) {
    return <StatusContainer id={notification.get('status')} />;
  },

  renderFavourite (notification, link) {
    return (
      <div className='notification notification-favourite'>
        <div className='notification__message'>
          <div style={{ position: 'absolute', 'left': '-26px'}}>
            <i className='fa fa-fw fa-star' style={{ color: '#ca8f04' }} />
          </div>

          <FormattedMessage id='notification.favourite' defaultMessage='{name} favourited your status' values={{ name: link }} />
        </div>

        <StatusContainer id={notification.get('status')} muted={true} />
      </div>
    );
  },

  renderReblog (notification, link) {
    return (
      <div className='notification notification-reblog'>
        <div className='notification__message'>
          <div style={{ position: 'absolute', 'left': '-26px'}}>
            <i className='fa fa-fw fa-retweet' />
          </div>

          <FormattedMessage id='notification.reblog' defaultMessage='{name} boosted your status' values={{ name: link }} />
        </div>

        <StatusContainer id={notification.get('status')} muted={true} />
      </div>
    );
  },

  render () {
    const { notification } = this.props;
    const account          = notification.get('account');
    const displayName      = account.get('display_name').length > 0 ? account.get('display_name') : account.get('username');
    const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
    const link             = <Permalink className='notification__display-name' style={linkStyle} href={account.get('url')} title={account.get('acct')} to={`/accounts/${account.get('id')}`} dangerouslySetInnerHTML={displayNameHTML} />;

    switch(notification.get('type')) {
      case 'follow':
        return this.renderFollow(account, link);
      case 'mention':
        return this.renderMention(notification);
      case 'favourite':
        return this.renderFavourite(notification, link);
      case 'reblog':
        return this.renderReblog(notification, link);
    }
  }

});

export default Notification;