-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathchat.js
More file actions
40 lines (37 loc) · 1.23 KB
/
chat.js
File metadata and controls
40 lines (37 loc) · 1.23 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
36
37
38
39
40
eventManager.on(':loaded', () => {
if (typeof socketChat !== 'undefined') {
debug('Chat detected');
eventManager.emit('ChatDetected');
const oHandler = socketChat.onmessage;
socketChat.onmessage = (event) => {
const data = JSON.parse(event.data);
const {action} = data;
debug(data, `debugging.rawchat.${action}`);
// Populate chatroom names
if (action === 'getHistory') {
chatRoomNames[data.room] = fn.translateText(data.roomName);
}
if (eventManager.emit(`preChat:${action}`, data, true).canceled) return;
oHandler(event);
eventManager.emit('ChatMessage', data);
eventManager.emit(`Chat:${action}`, data);
}
eventManager.on('Chat:getHistory', ({room, roomName: name}) => {
// Send text hook
const messages = $(`#${room} .chat-messages`);
$(`#${room} input[type="text"]`).keydown(function (e) {
if (e.which !== 13) return;
const data = {
room, name, messages,
input: this,
};
if (eventManager.emit('Chat:send', data, true).canceled) {
debug('Canceled send');
$(this).val('');
e.preventDefault();
e.stopPropagation();
}
});
});
}
});