<commit_before>const Message = require('../models/message.js')
const User = require('../models/user.js')


// Setup socket IO listeners
exports.listenSocket = function (io, redisClient) {
  io.on('connection', function (socket) {
    let username = socket.handshake.session.username

    let users = User(redisClient)
    let messages = Message(redisClient)

    users.attachSocket(username, socket, function (err) {
      if (err) {
        throw err
      }
    })

    socket.on('getUser', function () {
      users.getUser(username, function (err, user) {
        if (err) {
          throw err
        }
        socket.emit('user', user)
      })
    })

    socket.on('getMessages', function () {
      messages.getMessages(username, function (err, messages) {
        if (err) {
          throw err
        }
        socket.emit('messages', messages)
      })<commit_msg>Fix HGET error on promptUsername page<commit_after>const Message = require('../models/message.js')
const User = require('../models/user.js')


// Setup socket IO listeners
exports.listenSocket = function (io, redisClient) {
  io.on('connection', function (socket) {
    let username = socket.handshake.session.username

    let users = User(redisClient)
    let messages = Message(redisClient)

    if (username !== undefined) {
      users.attachSocket(username, socket, function (err) {
        if (err) {
          throw err
        }
      })
    }

    socket.on('getUser', function () {
      users.getUser(username, function (err, user) {
        if (err) {
          throw err
        }
        socket.emit('user', user)
      })
    })

    socket.on('getMessages', function () {
      messages.getMessages(username, function (err, messages) {
        if (err) {
          throw err
        }
        socket.emit('messages', messages)
      })
{'fraction_non_alphanumeric': 0.13278688524590163, 'fraction_numerical': 0.0, 'mean_word_length': 2.341240875912409, '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': '3338972', 'n_tokens_mistral': 528, 'n_tokens_neox': 517, 'n_words': 124}