<commit_before>mutiny = {
  channel_log: [],
  seen: '0',

  trim_log: function() {
    /* FIXME: If log has grown too long, play nice and delete some events. */
  },

  render_text: function(re, data, template) {
    if (data) {
      /* FIXME: Find URLs etc? */
      return template.replace(re, data.replace(/&/g, '&amp;')
                                      .replace(/"/g, '&quot;')
                                      .replace(/'/g, '&#39;')
                                      .replace(/</g, '&lt;')
                                      .replace(/>/g, '&gt;')
              .replace(/([A-Za-z0-9_-]+)\*(\s+)/g,
                       '<a href="javascript:mutiny.click_tag(\'$1\')">$1</a>$2')
              .replace(/(^|\s+)\(([A-Za-z0-9_-]+\*\s+)*[A-Za-z0-9_-]+\*\)/g, '')
.replace(/(^|\s+)((?:https?:\/\/|www\.)(?:[\w]+\.)(?:\.?[\w]{2,})+(?:\/[^\s\)\>]*)?)/g,
                                        '$1<a target=_blank href=\'$2\'>$2</a>')
           .replace(/(<a target=_blank href=\')(?!(?:http|java))/g, '$1http://')
                                      .replace('/\n/g', '\n<br>'));
    }
    else
      return template;
  },

  render_nick: function(nick, uid, template) {
    var color = '#';
    var avatar = '/_skin/avatar_'+uid[uid.length-1]+'.jpg';
    var max = 'f'.charCodeAt(0);
    if (nick)
      for (var n in [0, 1, 2, 3, 4, 5]) {
        var c = nick[n % nick.length];
        color += String.fromCharCode(max - (c.charCodeAt(0) % 6));
      }
    else
      color = '#aaa'
    return mutiny.render_text(/_NICK_/g, nick,
             template.replace(/mutiny_style=/g, 'style="background: '+color+';" x=')
                     .replace(/mutiny_avatar=/g, 'src="'+avatar+'" x='))
  },

  render_time: function(iid, template) {
    var dt = new Date(parseInt(iid.substring(0, iid.indexOf('-')))*1000);
    var mm = (' 0'+dt.getMinutes());
    var hh = (' 0'+dt.getHours());
    return template.replace(/_HH_MM_/g,
             hh.substring(hh.length-2) +':'+ mm.substring(mm.length-2));
  },

  render: function(data) {
    /* Schedule refresh first, in case we crash and burn. */
    setTimeout('mutiny.load_data(60)', 50);

    for (idx in data) {
      mutiny.channel_log.push(data[idx]);
      var iid = data[idx][0];
      var info = data[idx][1];
      var tpl = $('#template-'+info.event).html();
      var dom_id = iid;
      var target = 'channel';

      if (info.update) {
        iid = dom_id = info.update;
      }
      if (info.event == 'whois') {
        iid = dom_id = info.uid;
        target = 'people';
        tpl = mutiny.render_text(/_INFO_/g, info.userinfo, tpl);
      }
      var oi = $('#'+dom_id);
      if (info.event == 'delete') {
        $('#'+info.target).remove();
      }
      else if (tpl) {
        tpl = mutiny.render_time(iid,
                mutiny.render_nick(info.nick || '', info.uid || '',
                  mutiny.render_text(/_UID_/g, info.uid,
                    mutiny.render_text(/_STAT_/g, info.stat,
                      mutiny.render_text(/_TEXT_/g, info.text, tpl)))));
        if (oi.html()) {
          oi.html($(tpl).html());
        } else {
          var td = document.getElementById(target);
          var scroll = (td.scrollHeight - td.scrollTop == mutiny.scroll_diff);
          var jqObj = $(tpl).attr('id', dom_id);
          $('#'+target).append(jqObj);
          if (target == 'channel') {
            mutiny.apply_filters(jqObj);
            if (scroll || !mutiny.scroll_diff) {
              td.scrollTop = td.scrollHeight;
              mutiny.scroll_diff = (td.scrollHeight - td.scrollTop);
            }
          }
        }
      }
      if (iid > mutiny.seen) mutiny.seen = iid;
    }
    mutiny.trim_log();
  },

  load_data: function(timeout) {
    var api_url = (mutiny_host+'/_api/v1/'+mutiny_network+'/'+mutiny_channel
                   ).replace(/#/g, '');
    $.getJSON(api_url, {
      'a': 'log',
      'uid': mutiny_uid,
      'seen': mutiny.seen,
      'timeout': timeout
    }, function(data, textStatus, jqXHR) {
      mutiny.render(data);
    });
  },

  apply_filters: function(jqObj) {<commit_msg>Retry if there are errors<commit_after>mutiny = {
  channel_log: [],
  seen: '0',

  retry: 1,
  max_retry: 60,

  trim_log: function() {
    /* FIXME: If log has grown too long, play nice and delete some events. */
  },

  render_text: function(re, data, template) {
    if (data) {
      /* FIXME: Find URLs etc? */
      return template.replace(re, data.replace(/&/g, '&amp;')
                                      .replace(/"/g, '&quot;')
                                      .replace(/'/g, '&#39;')
                                      .replace(/</g, '&lt;')
                                      .replace(/>/g, '&gt;')
              .replace(/([A-Za-z0-9_-]+)\*(\s+)/g,
                       '<a href="javascript:mutiny.click_tag(\'$1\')">$1</a>$2')
              .replace(/(^|\s+)\(([A-Za-z0-9_-]+\*\s+)*[A-Za-z0-9_-]+\*\)/g, '')
.replace(/(^|\s+)((?:https?:\/\/|www\.)(?:[\w]+\.)(?:\.?[\w]{2,})+(?:\/[^\s\)\>]*)?)/g,
                                        '$1<a target=_blank href=\'$2\'>$2</a>')
           .replace(/(<a target=_blank href=\')(?!(?:http|java))/g, '$1http://')
                                      .replace('/\n/g', '\n<br>'));
    }
    else
      return template;
  },

  render_nick: function(nick, uid, template) {
    var color = '#';
    var avatar = '/_skin/avatar_'+uid[uid.length-1]+'.jpg';
    var max = 'f'.charCodeAt(0);
    if (nick)
      for (var n in [0, 1, 2, 3, 4, 5]) {
        var c = nick[n % nick.length];
        color += String.fromCharCode(max - (c.charCodeAt(0) % 6));
      }
    else
      color = '#aaa'
    return mutiny.render_text(/_NICK_/g, nick,
             template.replace(/mutiny_style=/g, 'style="background: '+color+';" x=')
                     .replace(/mutiny_avatar=/g, 'src="'+avatar+'" x='))
  },

  render_time: function(iid, template) {
    var dt = new Date(parseInt(iid.substring(0, iid.indexOf('-')))*1000);
    var mm = (' 0'+dt.getMinutes());
    var hh = (' 0'+dt.getHours());
    return template.replace(/_HH_MM_/g,
             hh.substring(hh.length-2) +':'+ mm.substring(mm.length-2));
  },

  render: function(data) {
    /* Schedule refresh first, in case we crash and burn. */
    setTimeout('mutiny.load_data(60)', 50);

    for (idx in data) {
      mutiny.channel_log.push(data[idx]);
      var iid = data[idx][0];
      var info = data[idx][1];
      var tpl = $('#template-'+info.event).html();
      var dom_id = iid;
      var target = 'channel';

      if (info.update) {
        iid = dom_id = info.update;
      }
      if (info.event == 'whois') {
        iid = dom_id = info.uid;
        target = 'people';
        tpl = mutiny.render_text(/_INFO_/g, info.userinfo, tpl);
      }
      var oi = $('#'+dom_id);
      if (info.event == 'delete') {
        $('#'+info.target).remove();
      }
      else if (tpl) {
        tpl = mutiny.render_time(iid,
                mutiny.render_nick(info.nick || '', info.uid || '',
                  mutiny.render_text(/_UID_/g, info.uid,
                    mutiny.render_text(/_STAT_/g, info.stat,
                      mutiny.render_text(/_TEXT_/g, info.text, tpl)))));
        if (oi.html()) {
          oi.html($(tpl).html());
        } else {
          var td = document.getElementById(target);
          var scroll = (td.scrollHeight - td.scrollTop == mutiny.scroll_diff);
          var jqObj = $(tpl).attr('id', dom_id);
          $('#'+target).append(jqObj);
          if (target == 'channel') {
            mutiny.apply_filters(jqObj);
            if (scroll || !mutiny.scroll_diff) {
              td.scrollTop = td.scrollHeight;
              mutiny.scroll_diff = (td.scrollHeight - td.scrollTop);
            }
          }
        }
      }
      if (iid > mutiny.seen) mutiny.seen = iid;
    }
    mutiny.trim_log();
  },

  load_data: function(timeout) {
    var api_url = (mutiny_host+'/_api/v1/'+mutiny_network+'/'+mutiny_channel
                   ).replace(/#/g, '');
    $.getJSON(api_url, {
      'a': 'log',
      'uid': mutiny_uid,
      'seen': mutiny.seen,
      'timeout': timeout
    }, function(data, textStatus, jqXHR) {
      mutiny.retry = 1;
      mutiny.render(data);
    }).error(function() {
      setTimeout('mutiny.load_data();', mutiny.retry);
      mutiny.retry = mutiny.retry * 2;
      if (mutiny.retry > mutiny.max_retry)
        mutiny_retry = mutiny.max_retry;
    });
  },

  apply_filters: function(jqObj) {
{'fraction_non_alphanumeric': 0.20267731329262564, 'fraction_numerical': 0.010685767966181306, 'mean_word_length': 1.80348913759052, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1846645', 'n_tokens_mistral': 3031, 'n_tokens_neox': 2950, 'n_words': 517}