<commit_before>const processedString = require('./helpers/stringHelpers').processedString;
const generalChatId = require('./siteConfig').generalChatId;
const pool = require('./pool');

module.exports = function(io) {
  let connections = [];
  io.on('connection', socket => {
    connections.push({
      socketId: socket.id,
      username: '',
      userId: null,
      channels: []
    });

    socket.on('enter_my_notification_channel', userId => {
      socket.join('notificationChannel' + userId)
    })

    socket.on('leave_my_notification_channel', userId => {
      socket.leave('notificationChannel' + userId);
    })

    socket.on('check_online_members', (channelId, callback) => {
      io.of('/').in('chatChannel' + channelId).clients((error, clients) => {
        let membersOnline = clients.map(client => {
          let member = {};
          for (let i = 0; i < connections.length; i++) {
            if (connections[i].socketId === client) {
              member = {
                userId: connections[i].userId,
                username: connections[i].username
              }
            }
          }
          return member;
        })
        membersOnline = membersOnline.reduce(
          (resultingArray, member) => {
            if (resultingArray.length === 0) {
              return resultingArray.concat(member)
            }
            else if (resultingArray[Math.max(resultingArray.length - 1, 0)].userId !== member.userId) {
              return resultingArray.concat(member)
            }
            else {
              return resultingArray;
            }
          }, []
        )
        let data = {channelId, membersOnline}
        callback(error, data);
      })
    })

    socket.on('join_chat_channel', (channelId, callback) => {
      socket.join('chatChannel' + channelId);
      for (let i = 0; i < connections.length; i++) {
        if (connections[i].socketId === socket.id) {
          if (connections[i].channels.indexOf(Number(channelId)) === -1) {
            connections[i].channels.push(Number(channelId));
          }
          break;
        }
      }
      notifyChannelMembersChanged(channelId);
    })<commit_msg>number online bug fix<commit_after>const processedString = require('./helpers/stringHelpers').processedString;
const generalChatId = require('./siteConfig').generalChatId;
const pool = require('./pool');

module.exports = function(io) {
  let connections = [];
  io.on('connection', socket => {
    connections.push({
      socketId: socket.id,
      username: '',
      userId: null,
      channels: []
    });

    socket.on('enter_my_notification_channel', userId => {
      socket.join('notificationChannel' + userId)
    })

    socket.on('leave_my_notification_channel', userId => {
      socket.leave('notificationChannel' + userId);
    })

    socket.on('check_online_members', (channelId, callback) => {
      io.of('/').in('chatChannel' + channelId).clients((error, clients) => {
        let membersOnline = clients.map(client => {
          let member = {};
          for (let i = 0; i < connections.length; i++) {
            if (connections[i].socketId === client) {
              member = {
                userId: connections[i].userId,
                username: connections[i].username
              }
            }
          }
          return member;
        })
        membersOnline = membersOnline.reduce(
          (resultingArray, member) => {
            if (resultingArray.length === 0) {
              return resultingArray.concat(member)
            }
            else if (Number(resultingArray[Math.max(resultingArray.length - 1, 0)].userId) !== Number(member.userId)) {
              return resultingArray.concat(member)
            }
            else {
              return resultingArray;
            }
          }, []
        )
        let data = {channelId, membersOnline}
        callback(error, data);
      })
    })

    socket.on('join_chat_channel', (channelId, callback) => {
      socket.join('chatChannel' + channelId);
      for (let i = 0; i < connections.length; i++) {
        if (connections[i].socketId === socket.id) {
          if (connections[i].channels.indexOf(Number(channelId)) === -1) {
            connections[i].channels.push(Number(channelId));
          }
          break;
        }
      }
      notifyChannelMembersChanged(channelId);
    })
{'fraction_non_alphanumeric': 0.14057507987220447, 'fraction_numerical': 0.0027384755819260614, 'mean_word_length': 2.0866197183098594, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '1011206', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1178, 'n_words': 213}