<commit_before>/*
 * These functions provide interaction for the freedom.js chat demo.
 */
window.onload = function() {
  document.getElementById('msg-input').focus();
  // If messages are going to a specific user, store that here.
  var activeId;

  function clearLog() {
    var log = document.getElementById('messagelist');
    log.innerHTML = "";
  }

  function appendLog(elt) {
    var log = document.getElementById('messagelist');
    //Trim old messages
    while (log.childNodes.length > 36) {
      log.removeChild(log.firstChild);
    }
    log.appendChild(elt);
    var br = document.createElement('br');
    log.appendChild(br);
    br.scrollIntoView();
  }
  
  // on changes to the buddylist, redraw entire buddylist
  window.freedom.on('recv-buddylist', function(val) {
    var onClick = function(jid, child) {
      if (activeId != jid) {
        activeId = jid;
        child.innerHTML = "[" + jid + "]";
      } else {
        activeId = undefined;
        child.innerHTML = jid;
      }
      console.log("Messages will be sent to: " + activeId);
      document.getElementById('msg-input').focus();
    };

    var buddylist = document.getElementById('buddylist');
    // Remove all elements in there now
    buddylist.innerHTML = "<b>Buddylist</b>";

    // Create a new element for each buddy
    for (var i in val) {
      var child = document.createElement('div');
      child.innerHTML = val[i];
      // If the user clicks on a buddy, change our current destination for messages
      child.addEventListener('click', onClick.bind(this, val[i], child), true);
      buddylist.appendChild(child);
    }
  });
  // On new messages, append it to our message log
  window.freedom.on('recv-message', function(data) {
    var message = data.from.userId + ": " + data.message;
    appendLog(document.createTextNode(message));
  });

  // Display our own userId when we get it
  window.freedom.on('recv-uid', function(data) {
    document.getElementById('uid').innerText = "Logged in as: "+data;
  });

  // Display the current status of our connection to the Social provider
  window.freedom.on('recv-status', function(msg) {
    if (msg && msg == 'online') {<commit_msg>Fixed chat buddylist display bug<commit_after>/*
 * These functions provide interaction for the freedom.js chat demo.
 */
window.onload = function() {
  document.getElementById('msg-input').focus();
  // If messages are going to a specific user, store that here.
  var activeId;
  var buddylist;

  function clearLog() {
    var log = document.getElementById('messagelist');
    log.innerHTML = "";
  }

  function appendLog(elt) {
    var log = document.getElementById('messagelist');
    //Trim old messages
    while (log.childNodes.length > 36) {
      log.removeChild(log.firstChild);
    }
    log.appendChild(elt);
    var br = document.createElement('br');
    log.appendChild(br);
    br.scrollIntoView();
  }

  function redrawBuddylist() {
    var onClick = function(jid, child) {
      console.log("Messages will be sent to: " + activeId);
      activeId = jid;
      redrawBuddylist();
      document.getElementById('msg-input').focus();
    };

    var buddylistDiv = document.getElementById('buddylist');
    // Remove all elements in there now
    buddylistDiv.innerHTML = "<b>Buddylist</b>";

    // Create a new element for each buddy
    for (var i in buddylist) {
      var child = document.createElement('div');
      if (activeId == buddylist[i]) {
        child.innerHTML = "[" + buddylist[i] + "]";
      } else {
        child.innerHTML = buddylist[i];
      }
      // If the user clicks on a buddy, change our current destination for messages
      child.addEventListener('click', onClick.bind(this, buddylist[i], child), true);
      buddylistDiv.appendChild(child);
    }

  }
  
  // on changes to the buddylist, redraw entire buddylist
  window.freedom.on('recv-buddylist', function(val) {
    buddylist = val;
    redrawBuddylist();
  });

  // On new messages, append it to our message log
  window.freedom.on('recv-message', function(data) {
    var message = data.from.userId + ": " + data.message;
    appendLog(document.createTextNode(message));
  });

  // Display our own userId when we get it
  window.freedom.on('recv-uid', function(data) {
    document.getElementById('uid').innerText = "Logged in as: "+data;
  });

  // Display the current status of our connection to the Social provider
  window.freedom.on('recv-status', function(msg) {
    if (msg && msg == 'online') {
{'fraction_non_alphanumeric': 0.13407325194228634, 'fraction_numerical': 0.0008879023307436182, 'mean_word_length': 3.0815217391304346, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 9, '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': '1625371', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1347, 'n_words': 364}