<commit_before>var m = require('mithril');

function userFullName(u) {
  return u.title ? u.title + ' ' + u.name : u.name;
}

function genericNotification(notification, url, icon, content) {
  return m('a.site_notification', {
    class: notification.type + (notification.read ? '' : ' new'),
    href: url
  }, [
    m('i', {
      'data-icon': icon
    }),
    m('span.content', content)
  ]);
}

function drawTime(notification) {
  return m('time', {
    class: "moment-from-now",
    datetime: new Date(notification.date).toISOString()
  });
};

var handlers = {
  mentioned: {
    html: function(notification) {
      var content = notification.content;
      var url = "/forum/redirect/post/" + content.postId

      return genericNotification(notification, url, 'd', [
        m('span', [
          m('strong', userFullName(content.mentionedBy)),
          drawTime(notification)
        ]),
        m('span', ' mentioned you in « ' + content.topic + ' ».')
      ]);
    },
    text: function(n) {
      return userFullName(n.content.mentionedBy) +
        ' mentioned you in « ' + n.content.topic + ' ».';
    }
  },
  invitedStudy: {
    html: function(notification) {
      var content = notification.content;
      var url = "/study/" + content.studyId;

      return genericNotification(notification, url, '', [
        m('span', [
          m('strong', userFullName(content.invitedBy)),
          drawTime(notification)
        ]),
        m('span', ' invited you to « ' + content.studyName + ' ».')
      ]);
    },
    text: function(n) {
      return userFullName(n.content.invitedBy) +
        ' invited you to « ' + n.content.studyName + ' ».';
    }
  },
  privateMessage: {
    html: function(notification) {
      var content = notification.content;
      var url = "/inbox/" + content.thread.id + '#bottom';

      return genericNotification(notification, url, 'c', [
        m('span', [
          m('strong', userFullName(content.sender)),
          drawTime(notification)
        ]),
        m('span', content.text)
      ]);
    },
    text: function(n) {
      return userFullName(n.content.sender) + ': ' + n.content.text;
    }
  },
  qaAnswer: {
    html: function(notification) {
        var content = notification.content
        var url = "/qa/" + content.questionId + "/" + content.questionSlug + "#" + "answer-" + content.answerId;

        return genericNotification(notification, url, '&', [
             m('span', [
                 m('strong', userFullName(content.answerer)),
                 drawTime(notification)
             ]),
             m('span', " answered your question « " + content.title + "  ».")
          ]);
        }
  },
  teamJoined: {
    html: function(notification) {
        var content = notification.content
        var url = "/team/" + content.teamId;

        return genericNotification(notification, url, '&',
             m('span', " You have joined « " + content.teamName + "  ».")
          );
        }<commit_msg>Add text for the browser notifications for team joins and qa answers.<commit_after>var m = require('mithril');

function userFullName(u) {
  return u.title ? u.title + ' ' + u.name : u.name;
}

function genericNotification(notification, url, icon, content) {
  return m('a.site_notification', {
    class: notification.type + (notification.read ? '' : ' new'),
    href: url
  }, [
    m('i', {
      'data-icon': icon
    }),
    m('span.content', content)
  ]);
}

function drawTime(notification) {
  return m('time', {
    class: "moment-from-now",
    datetime: new Date(notification.date).toISOString()
  });
};

var handlers = {
  mentioned: {
    html: function(notification) {
      var content = notification.content;
      var url = "/forum/redirect/post/" + content.postId

      return genericNotification(notification, url, 'd', [
        m('span', [
          m('strong', userFullName(content.mentionedBy)),
          drawTime(notification)
        ]),
        m('span', ' mentioned you in « ' + content.topic + ' ».')
      ]);
    },
    text: function(n) {
      return userFullName(n.content.mentionedBy) +
        ' mentioned you in « ' + n.content.topic + ' ».';
    }
  },
  invitedStudy: {
    html: function(notification) {
      var content = notification.content;
      var url = "/study/" + content.studyId;

      return genericNotification(notification, url, '', [
        m('span', [
          m('strong', userFullName(content.invitedBy)),
          drawTime(notification)
        ]),
        m('span', ' invited you to « ' + content.studyName + ' ».')
      ]);
    },
    text: function(n) {
      return userFullName(n.content.invitedBy) +
        ' invited you to « ' + n.content.studyName + ' ».';
    }
  },
  privateMessage: {
    html: function(notification) {
      var content = notification.content;
      var url = "/inbox/" + content.thread.id + '#bottom';

      return genericNotification(notification, url, 'c', [
        m('span', [
          m('strong', userFullName(content.sender)),
          drawTime(notification)
        ]),
        m('span', content.text)
      ]);
    },
    text: function(n) {
      return userFullName(n.content.sender) + ': ' + n.content.text;
    }
  },
  qaAnswer: {
    html: function(notification) {
        var content = notification.content
        var url = "/qa/" + content.questionId + "/" + content.questionSlug + "#" + "answer-" + content.answerId;

        return genericNotification(notification, url, '&', [
             m('span', [
                 m('strong', userFullName(content.answerer)),
                 drawTime(notification)
             ]),
             m('span', " answered your question « " + content.title + "  ».")
          ]);
        },
    text: function(n) {
        return userFullName(n.content.answerer) + " answered « " + n.content.title + "  »."
    }
  },
  teamJoined: {
    html: function(notification) {
        var content = notification.content
        var url = "/team/" + content.teamId;

        return genericNotification(notification, url, 'f',
             m('span', " You have joined « " + content.teamName + "  ».")
          );
        },
    text: function(n) {
        return " You have joined  « " + n.content.teamName + "  »."
    }
{'fraction_non_alphanumeric': 0.15909817716661337, 'fraction_numerical': 0.0, 'mean_word_length': 2.251039501039501, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3910893', 'n_tokens_mistral': 1877, 'n_tokens_neox': 1840, 'n_words': 393}