[
  {
    "path": "client/.gitignore",
    "content": "# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.\n\n# dependencies\n/node_modules\n/.pnp\n.pnp.js\n\n# testing\n/coverage\n\n# production\n/build\n\n# misc\n.DS_Store\n.env.local\n.env.development.local\n.env.test.local\n.env.production.local\n\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n"
  },
  {
    "path": "client/README.md",
    "content": "This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).\n\n## Available Scripts\n\nIn the project directory, you can run:\n\n### `npm start`\n\nRuns the app in the development mode.<br />\nOpen [http://localhost:3000](http://localhost:3000) to view it in the browser.\n\nThe page will reload if you make edits.<br />\nYou will also see any lint errors in the console.\n\n### `npm test`\n\nLaunches the test runner in the interactive watch mode.<br />\nSee the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.\n\n### `npm run build`\n\nBuilds the app for production to the `build` folder.<br />\nIt correctly bundles React in production mode and optimizes the build for the best performance.\n\nThe build is minified and the filenames include the hashes.<br />\nYour app is ready to be deployed!\n\nSee the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.\n\n### `npm run eject`\n\n**Note: this is a one-way operation. Once you `eject`, you can’t go back!**\n\nIf you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.\n\nInstead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.\n\nYou don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.\n\n## Learn More\n\nYou can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).\n\nTo learn React, check out the [React documentation](https://reactjs.org/).\n\n### Code Splitting\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting\n\n### Analyzing the Bundle Size\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size\n\n### Making a Progressive Web App\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app\n\n### Advanced Configuration\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration\n\n### Deployment\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/deployment\n\n### `npm run build` fails to minify\n\nThis section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify\n"
  },
  {
    "path": "client/package.json",
    "content": "{\n  \"name\": \"client\",\n  \"version\": \"0.1.0\",\n  \"private\": true,\n  \"dependencies\": {\n    \"@testing-library/jest-dom\": \"^4.2.4\",\n    \"@testing-library/react\": \"^9.5.0\",\n    \"@testing-library/user-event\": \"^7.2.1\",\n    \"bootstrap\": \"^4.5.2\",\n    \"react\": \"^16.13.1\",\n    \"react-bootstrap\": \"^1.3.0\",\n    \"react-dom\": \"^16.13.1\",\n    \"react-scripts\": \"3.4.3\",\n    \"socket.io-client\": \"^2.3.0\",\n    \"uuid\": \"^8.3.0\"\n  },\n  \"scripts\": {\n    \"start\": \"react-scripts start\",\n    \"build\": \"react-scripts build\",\n    \"test\": \"react-scripts test\",\n    \"eject\": \"react-scripts eject\"\n  },\n  \"eslintConfig\": {\n    \"extends\": \"react-app\"\n  },\n  \"browserslist\": {\n    \"production\": [\n      \">0.2%\",\n      \"not dead\",\n      \"not op_mini all\"\n    ],\n    \"development\": [\n      \"last 1 chrome version\",\n      \"last 1 firefox version\",\n      \"last 1 safari version\"\n    ]\n  }\n}\n"
  },
  {
    "path": "client/public/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n  <head>\n    <meta charset=\"utf-8\" />\n    <link rel=\"icon\" href=\"%PUBLIC_URL%/favicon.ico\" />\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n    <meta name=\"theme-color\" content=\"#000000\" />\n    <meta\n      name=\"description\"\n      content=\"Web site created using create-react-app\"\n    />\n    <link rel=\"apple-touch-icon\" href=\"%PUBLIC_URL%/logo192.png\" />\n    <!--\n      manifest.json provides metadata used when your web app is installed on a\n      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/\n    -->\n    <link rel=\"manifest\" href=\"%PUBLIC_URL%/manifest.json\" />\n    <!--\n      Notice the use of %PUBLIC_URL% in the tags above.\n      It will be replaced with the URL of the `public` folder during the build.\n      Only files inside the `public` folder can be referenced from the HTML.\n\n      Unlike \"/favicon.ico\" or \"favicon.ico\", \"%PUBLIC_URL%/favicon.ico\" will\n      work correctly both with client-side routing and a non-root public URL.\n      Learn how to configure a non-root public URL by running `npm run build`.\n    -->\n    <title>React App</title>\n  </head>\n  <body>\n    <noscript>You need to enable JavaScript to run this app.</noscript>\n    <div id=\"root\"></div>\n    <!--\n      This HTML file is a template.\n      If you open it directly in the browser, you will see an empty page.\n\n      You can add webfonts, meta tags, or analytics to this file.\n      The build step will place the bundled scripts into the <body> tag.\n\n      To begin the development, run `npm start` or `yarn start`.\n      To create a production bundle, use `npm run build` or `yarn build`.\n    -->\n  </body>\n</html>\n"
  },
  {
    "path": "client/public/manifest.json",
    "content": "{\n  \"short_name\": \"React App\",\n  \"name\": \"Create React App Sample\",\n  \"icons\": [\n    {\n      \"src\": \"favicon.ico\",\n      \"sizes\": \"64x64 32x32 24x24 16x16\",\n      \"type\": \"image/x-icon\"\n    },\n    {\n      \"src\": \"logo192.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"192x192\"\n    },\n    {\n      \"src\": \"logo512.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"512x512\"\n    }\n  ],\n  \"start_url\": \".\",\n  \"display\": \"standalone\",\n  \"theme_color\": \"#000000\",\n  \"background_color\": \"#ffffff\"\n}\n"
  },
  {
    "path": "client/public/robots.txt",
    "content": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n"
  },
  {
    "path": "client/src/components/App.js",
    "content": "import React from 'react'\nimport Login from './Login'\nimport useLocalStorage from '../hooks/useLocalStorage';\nimport Dashboard from './Dashboard'\nimport { ContactsProvider } from '../contexts/ContactsProvider'\nimport { ConversationsProvider } from '../contexts/ConversationsProvider';\nimport { SocketProvider } from '../contexts/SocketProvider';\n\nfunction App() {\n  const [id, setId] = useLocalStorage('id')\n\n  const dashboard = (\n    <SocketProvider id={id}>\n      <ContactsProvider>\n        <ConversationsProvider id={id}>\n          <Dashboard id={id} />\n        </ConversationsProvider>\n      </ContactsProvider>\n    </SocketProvider>\n  )\n\n  return (\n    id ? dashboard : <Login onIdSubmit={setId} />\n  )\n}\n\nexport default App;\n"
  },
  {
    "path": "client/src/components/Contacts.js",
    "content": "import React from 'react'\nimport { ListGroup } from 'react-bootstrap'\nimport { useContacts } from '../contexts/ContactsProvider';\n\nexport default function Contacts() {\n  const { contacts } = useContacts()\n\n  return (\n    <ListGroup variant=\"flush\">\n      {contacts.map(contact => (\n        <ListGroup.Item key={contact.id}>\n          {contact.name}\n        </ListGroup.Item>\n      ))}\n    </ListGroup>\n  )\n}\n"
  },
  {
    "path": "client/src/components/Conversations.js",
    "content": "import React from 'react'\nimport { ListGroup } from 'react-bootstrap'\nimport { useConversations } from '../contexts/ConversationsProvider';\n\nexport default function Conversations() {\n  const { conversations, selectConversationIndex } = useConversations()\n\n  return (\n    <ListGroup variant=\"flush\">\n      {conversations.map((conversation, index) => (\n        <ListGroup.Item\n          key={index}\n          action\n          onClick={() => selectConversationIndex(index)}\n          active={conversation.selected}\n        >\n          {conversation.recipients.map(r => r.name).join(', ')}\n        </ListGroup.Item>\n      ))}\n    </ListGroup>\n  )\n}\n"
  },
  {
    "path": "client/src/components/Dashboard.js",
    "content": "import React from 'react'\nimport Sidebar from './Sidebar';\nimport OpenConversation from './OpenConversation';\nimport { useConversations } from '../contexts/ConversationsProvider';\n\nexport default function Dashboard({ id }) {\n  const { selectedConversation } = useConversations()\n\n  return (\n    <div className=\"d-flex\" style={{ height: '100vh' }}>\n      <Sidebar id={id} />\n      {selectedConversation && <OpenConversation />}\n    </div>\n  )\n}\n"
  },
  {
    "path": "client/src/components/Login.js",
    "content": "import React, { useRef } from 'react'\nimport { Container, Form, Button } from 'react-bootstrap'\nimport { v4 as uuidV4 } from 'uuid'\n\nexport default function Login({ onIdSubmit }) {\n  const idRef = useRef()\n\n  function handleSubmit(e) {\n    e.preventDefault()\n\n    onIdSubmit(idRef.current.value)\n  }\n\n  function createNewId() {\n    onIdSubmit(uuidV4())\n  }\n\n  return (\n    <Container className=\"align-items-center d-flex\" style={{ height: '100vh' }}>\n      <Form onSubmit={handleSubmit} className=\"w-100\">\n        <Form.Group>\n          <Form.Label>Enter Your Id</Form.Label>\n          <Form.Control type=\"text\" ref={idRef} required />\n        </Form.Group>   \n        <Button type=\"submit\" className=\"mr-2\">Login</Button>\n        <Button onClick={createNewId} variant=\"secondary\">Create A New Id</Button>\n      </Form>\n    </Container>\n  )\n}\n"
  },
  {
    "path": "client/src/components/NewContactModal.js",
    "content": "import React, { useRef } from 'react'\nimport { Modal, Form, Button } from 'react-bootstrap'\nimport { useContacts } from '../contexts/ContactsProvider'\n\nexport default function NewContactModal({ closeModal }) {\n  const idRef = useRef()\n  const nameRef = useRef()\n  const { createContact } = useContacts()\n\n  function handleSubmit(e) {\n    e.preventDefault()\n\n    createContact(idRef.current.value, nameRef.current.value)\n    closeModal()\n  }\n\n  return (\n    <>\n      <Modal.Header closeButton>Create Contact</Modal.Header>\n      <Modal.Body>\n        <Form onSubmit={handleSubmit}>\n          <Form.Group>\n            <Form.Label>Id</Form.Label>\n            <Form.Control type=\"text\" ref={idRef} required />\n          </Form.Group>\n          <Form.Group>\n            <Form.Label>Name</Form.Label>\n            <Form.Control type=\"text\" ref={nameRef} required />\n          </Form.Group>\n          <Button type=\"submit\">Create</Button>\n        </Form>\n      </Modal.Body>\n    </>\n  )\n}\n"
  },
  {
    "path": "client/src/components/NewConversationModal.js",
    "content": "import React, { useState } from 'react'\nimport { Modal, Form, Button } from 'react-bootstrap'\nimport { useContacts } from '../contexts/ContactsProvider'\nimport { useConversations } from '../contexts/ConversationsProvider'\n\nexport default function NewConversationModal({ closeModal }) {\n  const [selectedContactIds, setSelectedContactIds] = useState([])\n  const { contacts } = useContacts()\n  const { createConversation } = useConversations()\n\n  function handleSubmit(e) {\n    e.preventDefault()\n\n    createConversation(selectedContactIds)\n    closeModal()\n  }\n\n  function handleCheckboxChange(contactId) {\n    setSelectedContactIds(prevSelectedContactIds => {\n      if (prevSelectedContactIds.includes(contactId)) {\n        return prevSelectedContactIds.filter(prevId => {\n          return contactId !== prevId\n        })\n      } else {\n        return [...prevSelectedContactIds, contactId]\n      }\n    })\n  }\n\n  return (\n    <>\n      <Modal.Header closeButton>Create Conversation</Modal.Header>\n      <Modal.Body>\n        <Form onSubmit={handleSubmit}>\n          {contacts.map(contact => (\n            <Form.Group controlId={contact.id} key={contact.id}>\n              <Form.Check\n                type=\"checkbox\"\n                value={selectedContactIds.includes(contact.id)}\n                label={contact.name}\n                onChange={() => handleCheckboxChange(contact.id)}\n              />\n            </Form.Group>\n          ))}\n          <Button type=\"submit\">Create</Button>\n        </Form>\n      </Modal.Body>\n    </>\n  )\n}\n"
  },
  {
    "path": "client/src/components/OpenConversation.js",
    "content": "import React, { useState, useCallback } from 'react'\nimport { Form, InputGroup, Button } from 'react-bootstrap'\nimport { useConversations } from '../contexts/ConversationsProvider';\n\nexport default function OpenConversation() {\n  const [text, setText] = useState('')\n  const setRef = useCallback(node => {\n    if (node) {\n      node.scrollIntoView({ smooth: true })\n    }\n  }, [])\n  const { sendMessage, selectedConversation } = useConversations()\n\n  function handleSubmit(e) {\n    e.preventDefault()\n\n    sendMessage(\n      selectedConversation.recipients.map(r => r.id),\n      text\n    )\n    setText('')\n  }\n\n  return (\n    <div className=\"d-flex flex-column flex-grow-1\">\n      <div className=\"flex-grow-1 overflow-auto\">\n        <div className=\"d-flex flex-column align-items-start justify-content-end px-3\">\n          {selectedConversation.messages.map((message, index) => {\n            const lastMessage = selectedConversation.messages.length - 1 === index\n            return (\n              <div\n                ref={lastMessage ? setRef : null}\n                key={index}\n                className={`my-1 d-flex flex-column ${message.fromMe ? 'align-self-end align-items-end' : 'align-items-start'}`}\n              >\n                <div\n                  className={`rounded px-2 py-1 ${message.fromMe ? 'bg-primary text-white' : 'border'}`}>\n                  {message.text}\n                </div>\n                <div className={`text-muted small ${message.fromMe ? 'text-right' : ''}`}>\n                  {message.fromMe ? 'You' : message.senderName}\n                </div>\n              </div>\n            )\n          })}\n        </div>\n      </div>\n      <Form onSubmit={handleSubmit}>\n        <Form.Group className=\"m-2\">\n          <InputGroup>\n            <Form.Control\n              as=\"textarea\"\n              required\n              value={text}\n              onChange={e => setText(e.target.value)}\n              style={{ height: '75px', resize: 'none' }}\n            />\n            <InputGroup.Append>\n              <Button type=\"submit\">Send</Button>\n            </InputGroup.Append>\n          </InputGroup>\n        </Form.Group>\n      </Form>\n    </div>\n  )\n}\n"
  },
  {
    "path": "client/src/components/Sidebar.js",
    "content": "import React, { useState } from 'react'\nimport { Tab, Nav, Button, Modal } from 'react-bootstrap'\nimport Conversations from './Conversations'\nimport Contacts from './Contacts'\nimport NewContactModal from './NewContactModal'\nimport NewConversationModal from './NewConversationModal'\n\nconst CONVERSATIONS_KEY = 'conversations'\nconst CONTACTS_KEY = 'contacts'\n\nexport default function Sidebar({ id }) {\n  const [activeKey, setActiveKey] = useState(CONVERSATIONS_KEY)\n  const [modalOpen, setModalOpen] = useState(false)\n  const conversationsOpen = activeKey === CONVERSATIONS_KEY\n  \n  function closeModal() {\n    setModalOpen(false)\n  }\n\n  return (\n    <div style={{ width: '250px' }} className=\"d-flex flex-column\">\n      <Tab.Container activeKey={activeKey} onSelect={setActiveKey}>\n        <Nav variant=\"tabs\" className=\"justify-content-center\">\n          <Nav.Item>\n            <Nav.Link eventKey={CONVERSATIONS_KEY}>Conversations</Nav.Link>\n          </Nav.Item>\n          <Nav.Item>\n            <Nav.Link eventKey={CONTACTS_KEY}>Contacts</Nav.Link>\n          </Nav.Item>\n        </Nav>\n        <Tab.Content className=\"border-right overflow-auto flex-grow-1\">\n          <Tab.Pane eventKey={CONVERSATIONS_KEY}>\n            <Conversations />\n          </Tab.Pane>\n          <Tab.Pane eventKey={CONTACTS_KEY}>\n            <Contacts />\n          </Tab.Pane>\n        </Tab.Content>\n        <div className=\"p-2 border-top border-right small\">\n          Your Id: <span className=\"text-muted\">{id}</span>\n        </div>\n        <Button onClick={() => setModalOpen(true)} className=\"rounded-0\">\n          New {conversationsOpen ? 'Conversation' : 'Contact'}\n        </Button>\n      </Tab.Container>\n\n      <Modal show={modalOpen} onHide={closeModal}>\n        {conversationsOpen ?\n          <NewConversationModal closeModal={closeModal} /> :\n          <NewContactModal closeModal={closeModal} />\n        }\n      </Modal>\n    </div>\n  )\n}\n"
  },
  {
    "path": "client/src/contexts/ContactsProvider.js",
    "content": "import React, { useContext } from 'react'\nimport useLocalStorage from '../hooks/useLocalStorage';\n\nconst ContactsContext = React.createContext()\n\nexport function useContacts() {\n  return useContext(ContactsContext)\n}\n\nexport function ContactsProvider({ children }) {\n  const [contacts, setContacts] = useLocalStorage('contacts', [])\n\n  function createContact(id, name) {\n    setContacts(prevContacts => {\n      return [...prevContacts, { id, name }]\n    })\n  }\n\n  return (\n    <ContactsContext.Provider value={{ contacts, createContact }}>\n      {children}\n    </ContactsContext.Provider>\n  )\n}\n"
  },
  {
    "path": "client/src/contexts/ConversationsProvider.js",
    "content": "import React, { useContext, useState, useEffect, useCallback } from 'react'\nimport useLocalStorage from '../hooks/useLocalStorage';\nimport { useContacts } from './ContactsProvider';\nimport { useSocket } from './SocketProvider';\n\nconst ConversationsContext = React.createContext()\n\nexport function useConversations() {\n  return useContext(ConversationsContext)\n}\n\nexport function ConversationsProvider({ id, children }) {\n  const [conversations, setConversations] = useLocalStorage('conversations', [])\n  const [selectedConversationIndex, setSelectedConversationIndex] = useState(0)\n  const { contacts } = useContacts()\n  const socket = useSocket()\n\n  function createConversation(recipients) {\n    setConversations(prevConversations => {\n      return [...prevConversations, { recipients, messages: [] }]\n    })\n  }\n\n  const addMessageToConversation = useCallback(({ recipients, text, sender }) => {\n    setConversations(prevConversations => {\n      let madeChange = false\n      const newMessage = { sender, text }\n      const newConversations = prevConversations.map(conversation => {\n        if (arrayEquality(conversation.recipients, recipients)) {\n          madeChange = true\n          return {\n            ...conversation,\n            messages: [...conversation.messages, newMessage]\n          }\n        }\n\n        return conversation\n      })\n\n      if (madeChange) {\n        return newConversations\n      } else {\n        return [\n          ...prevConversations,\n          { recipients, messages: [newMessage] }\n        ]\n      }\n    })\n  }, [setConversations])\n\n  useEffect(() => {\n    if (socket == null) return\n\n    socket.on('receive-message', addMessageToConversation)\n\n    return () => socket.off('receive-message')\n  }, [socket, addMessageToConversation])\n\n  function sendMessage(recipients, text) {\n    socket.emit('send-message', { recipients, text })\n\n    addMessageToConversation({ recipients, text, sender: id })\n  }\n\n  const formattedConversations = conversations.map((conversation, index) => {\n    const recipients = conversation.recipients.map(recipient => {\n      const contact = contacts.find(contact => {\n        return contact.id === recipient\n      })\n      const name = (contact && contact.name) || recipient\n      return { id: recipient, name }\n    })\n\n    const messages = conversation.messages.map(message => {\n      const contact = contacts.find(contact => {\n        return contact.id === message.sender\n      })\n      const name = (contact && contact.name) || message.sender\n      const fromMe = id === message.sender\n      return { ...message, senderName: name, fromMe }\n    })\n    \n    const selected = index === selectedConversationIndex\n    return { ...conversation, messages, recipients, selected }\n  })\n\n  const value = {\n    conversations: formattedConversations,\n    selectedConversation: formattedConversations[selectedConversationIndex],\n    sendMessage,\n    selectConversationIndex: setSelectedConversationIndex,\n    createConversation\n  }\n\n  return (\n    <ConversationsContext.Provider value={value}>\n      {children}\n    </ConversationsContext.Provider>\n  )\n}\n\nfunction arrayEquality(a, b) {\n  if (a.length !== b.length) return false\n\n  a.sort()\n  b.sort()\n\n  return a.every((element, index) => {\n    return element === b[index]\n  })\n}"
  },
  {
    "path": "client/src/contexts/SocketProvider.js",
    "content": "import React, { useContext, useEffect, useState } from 'react'\nimport io from 'socket.io-client'\n\nconst SocketContext = React.createContext()\n\nexport function useSocket() {\n  return useContext(SocketContext)\n}\n\nexport function SocketProvider({ id, children }) {\n  const [socket, setSocket] = useState()\n\n  useEffect(() => {\n    const newSocket = io(\n      'http://localhost:5000',\n      { query: { id } }\n    )\n    setSocket(newSocket)\n\n    return () => newSocket.close()\n  }, [id])\n\n  return (\n    <SocketContext.Provider value={socket}>\n      {children}\n    </SocketContext.Provider>\n  )\n}\n"
  },
  {
    "path": "client/src/hooks/useLocalStorage.js",
    "content": "import { useEffect, useState } from 'react'\n\nconst PREFIX = 'whatsapp-clone-'\n\nexport default function useLocalStorage(key, initialValue) {\n  const prefixedKey = PREFIX + key\n  const [value, setValue] = useState(() => {\n    const jsonValue = localStorage.getItem(prefixedKey)\n    if (jsonValue != null) return JSON.parse(jsonValue)\n    if (typeof initialValue === 'function') {\n      return initialValue()\n    } else {\n      return initialValue\n    }\n  })\n\n  useEffect(() => {\n    localStorage.setItem(prefixedKey, JSON.stringify(value))\n  }, [prefixedKey, value])\n\n  return [value, setValue]\n}\n"
  },
  {
    "path": "client/src/index.js",
    "content": "import React from 'react';\nimport ReactDOM from 'react-dom';\nimport App from './components/App';\nimport 'bootstrap/dist/css/bootstrap.min.css'\n\nReactDOM.render(\n  <React.StrictMode>\n    <App />\n  </React.StrictMode>,\n  document.getElementById('root')\n);"
  },
  {
    "path": "server/.gitignore",
    "content": "node_modules"
  },
  {
    "path": "server/package.json",
    "content": "{\n  \"name\": \"server\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"devStart\": \"nodemon server.js\"\n  },\n  \"keywords\": [],\n  \"author\": \"\",\n  \"license\": \"ISC\",\n  \"dependencies\": {\n    \"socket.io\": \"^2.3.0\"\n  },\n  \"devDependencies\": {\n    \"nodemon\": \"^2.0.4\"\n  }\n}\n"
  },
  {
    "path": "server/server.js",
    "content": "const io = require('socket.io')(5000)\n\nio.on('connection', socket => {\n  const id = socket.handshake.query.id\n  socket.join(id)\n\n  socket.on('send-message', ({ recipients, text }) => {\n    recipients.forEach(recipient => {\n      const newRecipients = recipients.filter(r => r !== recipient)\n      newRecipients.push(id)\n      socket.broadcast.to(recipient).emit('receive-message', {\n        recipients: newRecipients, sender: id, text\n      })\n    })\n  })\n})"
  }
]