File size: 2,368 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
96
97
98
99
100
101
102
import React from 'react';
import { Link } from 'react-router-dom';
import Icon from '../components/icon';
import { HorizontalRuleWithIcon } from '../components/globals';

const icons = {
  NEW_THREAD: 'post',
  NEW_MESSAGE: 'messages',
  default: 'notification',
};

const colors = {
  NEW_THREAD: 'success.alt',
  NEW_MESSAGE: 'warn.alt',
};

export const getIconByType = type => {
  return icons[type] || icons.default;
};

export const getColorByType = type => {
  // TODO: add "readState" handling to change color to light gray
  return colors[type];
};

export const constructMessage = notification => {
  const { type, sender, community, channel, thread } = notification;
  switch (type) {
    case 'NEW_THREAD':
      return (
        <span>
          <Link to={`/@${sender.username}`}>{sender.name}</Link> posted a new
          thread in{' '}
          <Link to={`/${community.slug}/${channel.slug}`}>
            {community.name}/{channel.name}
          </Link>
          :
        </span>
      );
    case 'NEW_MESSAGE':
      return (
        <span>
          <Link to={`/@${sender.username}`}>{sender.name}</Link> replied to your{' '}
          <Link
            to={{
              pathname: getThreadLink(thread),
              state: { modal: true },
            }}
          >
            thread
          </Link>
          :
        </span>
      );
    default:
      return;
  }
};

export const constructLinklessMessage = notification => {
  const { type, sender, community, channel } = notification;
  switch (type) {
    case 'NEW_THREAD':
      return (
        <span>
          <b>{sender.name}</b> posted a new thread in{' '}
          <b>
            {community.name}/{channel.name}
          </b>
        </span>
      );
    case 'NEW_MESSAGE':
      return (
        <span>
          <b>{sender.name}</b> replied to your <b>thread</b>
        </span>
      );
    default:
      return;
  }
};

export const constructContent = notification => {
  const { type, sender, content } = notification;
  switch (type) {
    case 'NEW_THREAD':
      return <p>{content.excerpt}</p>;
    case 'NEW_MESSAGE':
      return (
        <div>
          <HorizontalRuleWithIcon>
            <hr />
            <Icon glyph={'messages'} />
            <hr />
          </HorizontalRuleWithIcon>
        </div>
      );
    default:
      return;
  }
};