<commit_before>var socket = null;
var app = null;

var expressWs = require('express-ws')

function initChatSocket(_app) {
  app = _app;
  expressWs = expressWs(app)
  app.ws('/chatWs', function(ws, request) {
    socket = ws
    // s// console.log(ws)
    ws.on('message', function(message) {
      var messageObject = JSON.parse(message)
      if (messageObject.type === 'chat') {
        expressWs.getWss('/chatWs')
          .clients.forEach(function(client) {
            client.send(message)
          })
      }
    })
  })
}

module.exports = {
  useChatWebsocket: initChatSocket
}<commit_msg>don't let people impersonate users in chat<commit_after>var expressWs = require('express-ws')

var app = null;

function initChatSocket(_app) {
  app = _app;
  expressWs = expressWs(app)
  app.ws('/chatWs', function(ws, request) {
    ws.on('message', function(message) {
      var messageObject = JSON.parse(message)
      if (messageObject.type === 'chat') {
        if(messageObject.data.userId !== request.user.id) {
          console.log('someone trying to impersonate chat messages?')
          return
        }
        expressWs.getWss('/chatWs')
          .clients.forEach(function(client) {
            client.send(message)
          })
      }
    })
  })
}

module.exports = {
  useChatWebsocket: initChatSocket
}
{'fraction_non_alphanumeric': 0.13897280966767372, 'fraction_numerical': 0.0, 'mean_word_length': 2.6908077994428967, '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': '3045892', 'n_tokens_mistral': 433, 'n_tokens_neox': 417, 'n_words': 80}