aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/ringcentral/webview.js
blob: ba4f50c5c40fc9e61647a96f0d3fb6a949a4cb55 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module.exports = Ferdi => {
  const getMessages = () => {
    let directCount = 0;
    let indirectCount = 0;

    const messageCountElement = document.querySelector('#Message-umi');
    if (messageCountElement) {
      directCount = Ferdi.safeParseInt(messageCountElement.textContent);
    }

    const unreadChats = document.querySelectorAll('.has-unread');
    // unreadChats includes direct messages - do not count them
    indirectCount = unreadChats.length - directCount;

    Ferdi.setBadge(directCount, indirectCount);
  };

  Ferdi.loop(getMessages);
};