aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/kiwiirc/webview.js
blob: ef6c9305b30ca39b4cfd53a4e0bd1f6154b8c06e (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
function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

const _path = _interopRequireDefault(require('path'));

module.exports = Ferdium => {
  const getMessages = function getMessages() {
    // eslint-disable-next-line no-undef
    const unreadChannelsCount = kiwi.state.networks.reduce((count, network) => {
      // eslint-disable-next-line no-param-reassign
      return (count += network.buffers.filter(buffer => {
        return !buffer.name.startsWith('*') && buffer.flags.unread !== 0;
      }).length);
    }, 0);

    // eslint-disable-next-line no-undef
    const mentionedChannelsCount = kiwi.state.networks.reduce(
      (count, network) => {
        // eslint-disable-next-line no-param-reassign
        return (count += network.buffers.filter(buffer => {
          return (
            !buffer.name.startsWith('*') &&
            buffer.flags.unread !== 0 &&
            buffer.flags.highlight
          );
        }).length);
      },
      0,
    );

    // set Ferdium badges
    Ferdium.setBadge(mentionedChannelsCount, unreadChannelsCount);
  };

  Ferdium.loop(getMessages);

  Ferdium.injectCSS(_path.default.join(__dirname, 'service.css'));
};