<commit_before>var WebSocketReceiver = {
  initialize: function(url) {
    var ws = new WebSocket(url);
    WSR.socket = ws;

    //Attach onmessage to websocket
    ws.onmessage = WSR.onMessage;
    ws.onclose = function() {
      WSR.debug("socket closed");
    };
    ws.onopen = function() {
      ws.send(location.pathname);
      WSR.debug("connected...");
    };
  },

  onMessage: function(evt) {
      var obj = jQuery.parseJSON(evt.data);
      if(obj['class'] == 'notifications') {
        WebSocketReceiver.processNotification(obj);
      } else if (obj['class'] == 'people') {
        WSR.debug("got a " + obj['class']);
        WebSocketReceiver.processPerson(obj);

      } else {
        WSR.debug("got a " + obj['class'] + " for aspects " + obj.aspect_ids);

        if (obj['class']=="retractions") {
          WebSocketReceiver.processRetraction(obj.post_id);

        } else if (obj['class']=="comments") {
          WebSocketReceiver.processComment(obj.post_id, obj.comment_id, obj.html, {
            'notification': obj.notification,
            'mine?': obj['mine?'],
            'my_post?': obj['my_post?']
          });

        } else {
          WebSocketReceiver.processPost(obj['class'], obj.post_id, obj.html, obj.aspect_ids);
        }
      }
  },

  processPerson: function(response) {
    var form = $('.webfinger_form');
    form.siblings('#loader').hide();
    var result_ul = form.siblings('#request_result');
    if(response.status == 'fail') {
      result_ul.siblings('.error').show();
      result_ul.find('.error').text(response.response).show();
    } else {
      $('#people_stream').prepend(response.html).slideDown('slow', function(){});
      var first_li = result_ul.find('li:first');
      first_li.hide()
      first_li.after(response.html);
      result_ul.find("[name='request[into]']").val(result_ul.attr('aspect_id'));
      result_ul.children(':nth-child(2)').slideDown('fast', function(){});
    }
  },


  processNotification: function(notification){
    var nBadge = $("#notification_badge_number");

    nBadge.html().replace(/\d+/, function(num){
      nBadge.html(parseInt(num)+1);
    });<commit_msg>websocket js handler should know about different notification types<commit_after>var WebSocketReceiver = {
  initialize: function(url) {
    var ws = new WebSocket(url);
    WSR.socket = ws;

    //Attach onmessage to websocket
    ws.onmessage = WSR.onMessage;
    ws.onclose = function() {
      WSR.debug("socket closed");
    };
    ws.onopen = function() {
      ws.send(location.pathname);
      WSR.debug("connected...");
    };
  },

  onMessage: function(evt) {
      var obj = jQuery.parseJSON(evt.data);

      if(obj['class'].match(/^notifications/)) {
        WebSocketReceiver.processNotification(obj);
      } else if (obj['class'] == 'people') {
        WSR.debug("got a " + obj['class']);
        WebSocketReceiver.processPerson(obj);

      } else {
        WSR.debug("got a " + obj['class'] + " for aspects " + obj.aspect_ids);

        if (obj['class']=="retractions") {
          WebSocketReceiver.processRetraction(obj.post_id);

        } else if (obj['class']=="comments") {
          WebSocketReceiver.processComment(obj.post_id, obj.comment_id, obj.html, {
            'notification': obj.notification,
            'mine?': obj['mine?'],
            'my_post?': obj['my_post?']
          });

        } else {
          WebSocketReceiver.processPost(obj['class'], obj.post_id, obj.html, obj.aspect_ids);
        }
      }
  },

  processPerson: function(response) {
    var form = $('.webfinger_form');
    form.siblings('#loader').hide();
    var result_ul = form.siblings('#request_result');
    if(response.status == 'fail') {
      result_ul.siblings('.error').show();
      result_ul.find('.error').text(response.response).show();
    } else {
      $('#people_stream').prepend(response.html).slideDown('slow', function(){});
      var first_li = result_ul.find('li:first');
      first_li.hide()
      first_li.after(response.html);
      result_ul.find("[name='request[into]']").val(result_ul.attr('aspect_id'));
      result_ul.children(':nth-child(2)').slideDown('fast', function(){});
    }
  },


  processNotification: function(notification){
    var nBadge = $("#notification_badge div.badge_count");

    nBadge.html().replace(/\d+/, function(num){
      nBadge.html(parseInt(num)+1);
    });
{'fraction_non_alphanumeric': 0.17906712172923778, 'fraction_numerical': 0.0009101251422070534, 'mean_word_length': 2.963931469792606, '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': '2222290', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1385, 'n_words': 206}