<commit_before>import jwt from 'jsonwebtoken';
import config from '../../../config/config';
import User from '../models/user.model';

const debug = true;

const socketConnection = (io) => {
  io.on('connection', (client) => {

    client.on('authenticate', async (data) => {
      try {
        const decoded = jwt.verify(data.token, config.jwtSecret);
        if (decoded !== undefined) {
          client.authenticated = true; // eslint-disable-line
          // join user to a room according to his unique id
          client.join(decoded.id);
          client.id = decoded.id;
          // mark user as online
          const user = await User.get(decoded.id);
          user.online = true;
          await user.save();

          client.emit('authenticated', { auth: true });
        } else {
          client.emit('authenticated', { auth: false });
        }
      } catch (err) {
        client.emit('authenticated', { auth: false });
        client.authenticated = false; // eslint-disable-line
        client.disconnect(); // force disconnect not authorized client
      }
    });
    client.on('disconnect', async () => {
      try {
        const user = await User.get(client.id);
        user.online = false;
        await user.save();
        client.disconnect();
      } catch (e) {
        client.authenticated = false; // eslint-disable-line
        client.disconnect();
      }
    });
  });
};

const socketEmitter = (io) => {
  const object = {
    sendToUser(follower, post) {
      console.log('sendingg', follower._id);
      console.log(io);
      io.sockets.socket(follower._id).emit('update_feed', post);
    }
  };
  return object;
};

export { socketConnection, socketEmitter };
<commit_msg>re add to emit<commit_after>import jwt from 'jsonwebtoken';
import config from '../../../config/config';
import User from '../models/user.model';

const debug = true;

const socketConnection = (io) => {
  io.on('connection', (client) => {

    client.on('authenticate', async (data) => {
      try {
        const decoded = jwt.verify(data.token, config.jwtSecret);
        if (decoded !== undefined) {
          client.authenticated = true; // eslint-disable-line
          // join user to a room according to his unique id
          client.join(decoded.id);
          client.id = decoded.id;
          // mark user as online
          const user = await User.get(decoded.id);
          user.online = true;
          await user.save();

          client.emit('authenticated', { auth: true });
        } else {
          client.emit('authenticated', { auth: false });
        }
      } catch (err) {
        client.emit('authenticated', { auth: false });
        client.authenticated = false; // eslint-disable-line
        client.disconnect(); // force disconnect not authorized client
      }
    });
    client.on('disconnect', async () => {
      try {
        const user = await User.get(client.id);
        user.online = false;
        await user.save();
        client.disconnect();
      } catch (e) {
        client.authenticated = false; // eslint-disable-line
        client.disconnect();
      }
    });
  });
};

const socketEmitter = (io) => {
  const object = {
    sendToUser(follower, post) {
      console.log('sendingg', follower._id);
      console.log(io);
      io.to(follower._id).emit('update_feed', post);
    }
  };
  return object;
};

export { socketConnection, socketEmitter };

{'fraction_non_alphanumeric': 0.14861313868613138, 'fraction_numerical': 0.0, 'mean_word_length': 2.1634349030470914, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '498444', 'n_tokens_mistral': 1015, 'n_tokens_neox': 992, 'n_words': 233}