<commit_before>var $ = os.jQuery;

var rcIntroduceYourself = "friend/introduce-yourself";

var initMessagesUI = function(container, showHideMessages) {
  if (container.attr('class') !== 'bfriendr-messages') { debugger; }

  // handles to UI elements; wackiness with classNames
  var msgs = container.find('ul:first');
  var friendNameElt = container.find('.bfriendr-message-friendname');
  var textMsgTemplate = msgs.find('.bfriendr-message:first');
  var capMsgTemplate = msgs.find('.bfriendr-message:eq(1)');
  var sendButton = msgs.find('button:eq(0)');
  var composeTextArea = msgs.find('textarea:eq(0)');
  var showFriendPane = container.find('.bfriendr-nav');

  showFriendPane.click(function() { showHideMessages(false); return false; });

  var showMsg = function(msg) {

    // TODO(arjun): account for a capability
    var msgElt = textMsgTemplate.clone();
    msgElt.find('p:eq(1)').text(msg.message || 'Received blank message.');
    msgElt.find('.bfriendr-date:first').text(msg.when);
    msgs.append(msgElt);

  };

  var refresh = function(friendName, conversationCap, postCap) {

    // Clear old messages and event handlers.
    msgs.find('.bfriendr-message').detach();
    sendButton.unbind('click');

    showHideMessages(true);

    friendNameElt.text(friendName);
    conversationCap.get(function (msgs) { msgs.items.forEach(showMsg); });

    sendButton.click(function() {
      postCap.post({ 'message' : composeTextArea.val() });
    });
    
  };

  return {
    refresh: refresh,
    shm: showHideMessages
  }; 
    
};


var initCardUI = function(container, messageUI) {
  var template = container.find('.bfriendr-card:first');
  container.find('.bfriendr-card').detach(); // removes extra templates too

  var updateCard = function(ui) {<commit_msg>poll for new messages every 2 seconds, on send success, and on message pane load<commit_after>var $ = os.jQuery;

var rcIntroduceYourself = "friend/introduce-yourself";

var initMessagesUI = function(container, showHideMessages) {
  if (container.attr('class') !== 'bfriendr-messages') { debugger; }

  // handles to UI elements; wackiness with classNames
  var msgs = container.find('ul:first');
  var friendNameElt = container.find('.bfriendr-message-friendname');
  var textMsgTemplate = msgs.find('.bfriendr-message:first');
  var capMsgTemplate = msgs.find('.bfriendr-message:eq(1)');
  var sendButton = msgs.find('button:eq(0)');
  var composeTextArea = msgs.find('textarea:eq(0)');
  var showFriendPane = container.find('.bfriendr-nav');

  var pollIntervalID = false;

  showFriendPane.click(function() { 
    if (pollIntervalID !== false) {
      os.clearInterval(pollIntervalID);
      pollIntervalID = false;
    }

    showHideMessages(false); 
    return false; 
  });

  var showMsg = function(msg) {

    // TODO(arjun): account for a capability
    var msgElt = textMsgTemplate.clone();
    msgElt.find('p:eq(1)').text(msg.message || 'Received blank message.');
    msgElt.find('.bfriendr-date:first').text(msg.when);
    msgs.append(msgElt);

  };

  var mkRefreshConvHandler = function(conversationCap) {
    return function() {
      conversationCap.get(function(conv) {
      msgs.find('.bfriendr-message').detach();
      conv.items.forEach(showMsg);
      });
    };
  };

  var refresh = function(friendName, conversationCap, postCap) {  
    var handler = mkRefreshConvHandler(conversationCap);
    handler();

    pollIntervalID = os.setInterval(handler, 2000);
    sendButton.unbind('click');

    showHideMessages(true);
    friendNameElt.text(friendName);

    sendButton.click(function() {
      postCap.post({ 'message' : composeTextArea.val() }, 
                   function() { handler(); });
    });
    
  };

  return {
    refresh: refresh,
    shm: showHideMessages
  }; 
    
};


var initCardUI = function(container, messageUI) {
  var template = container.find('.bfriendr-card:first');
  container.find('.bfriendr-card').detach(); // removes extra templates too

  var updateCard = function(ui) {
{'fraction_non_alphanumeric': 0.149514079242462, 'fraction_numerical': 0.00323947171692001, 'mean_word_length': 3.9312039312039313, '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': '5152408', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1247, 'n_words': 238}