-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocketManager.coffee
More file actions
35 lines (26 loc) · 1.31 KB
/
socketManager.coffee
File metadata and controls
35 lines (26 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
MessageRepo = require('./data/MessageRepo')
module.exports = (io) ->
io.on 'connection', (socket) ->
socket.on 'conversationConnect', (user, _conversation) ->
socket.join(_conversation)
MessageRepo.getNode _conversation, (err, rootNode) ->
return console.log err if err
socket.emit('setRootNode', rootNode)
socket.on 'getChildren', (_parent) ->
MessageRepo.getChildrenOfNode _parent, (err, nodeWithChildren) ->
socket.emit 'receivedChildren', nodeWithChildren
socket.on 'newMessage', (_user, _newMessageParent, newMessageContent) ->
MessageRepo.createNewMessage {
_owner: _user
content: newMessageContent
_children: []
}, (err, newMessage) ->
return console.log err if err
io.sockets.in(_conversation).emit 'receivedChildren', {
_id: _newMessageParent
_owner: _user
_children: [newMessage]
isLiveMessage: true
}
MessageRepo.addMessageAsChild _newMessageParent, newMessage._id, (err) ->
return console.log err if err